Fixed output-file location and changed GCC-XML call
Tue Sep 5 23:09:55 PDT 2006 Daniel Dickison (danieldickison@gmail.com)
* Fixed output-file location and changed GCC-XML call
The output file, if not specified, is "<xml-dir>/../<ffi-name>/".
Also, we now call gccxml directly, specifying options programatically instead of through an options file. I hadn't realize until now that gccxml will forward all non-gccxml-specific options to gcc.
diff -rN -u old-c2ffi/FFI-Generator.lisp new-c2ffi/FFI-Generator.lisp
--- old-c2ffi/FFI-Generator.lisp 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/FFI-Generator.lisp 2014-07-28 13:32:12.000000000 -0700
@@ -3,9 +3,9 @@
(in-package :c2ffi)
(export '(ffi-generator
+ ffi-name
ffi-xml-file
ffi-output-file
- ffi-parse-tree
ffi-bindings
generate-bindings
write-bindings))
@@ -13,7 +13,11 @@
(defclass ffi-generator ()
- ((xml-file :initarg :xml-file
+ ((name :initarg :name
+ :initform "FFI"
+ :accessor ffi-name
+ :documentation "The type of FFI, used for creating the output path.")
+ (xml-file :initarg :xml-file
:initform nil
:accessor ffi-xml-file)
(output-file :initarg :output-file
@@ -33,13 +37,19 @@
(defmethod ffi-output-file ((ffi ffi-generator))
"Override the accessor getter for output-file to return a value computed from xml-file if this slot is not explicitly set."
(or (slot-value ffi 'output-file)
- (and (ffi-xml-file ffi)
- (make-pathname :type "lisp"
- :defaults (ffi-xml-file ffi)))
+ (aand (probe-file (ffi-xml-file ffi))
+ (make-pathname :name (pathname-name it)
+ :type "lisp"
+ :directory (append (pathname-directory it)
+ (list :up (ffi-name ffi)))
+ :defaults (ffi-xml-file ffi)))
(error "Output file cannot be determined. Please set either xml-file or output-file.")))
(defgeneric generate-bindings (ffi-gen)
(:documentation "Generates bindings from the XML-File, if the slot is set, or from the parse-tree. If neither XML-File or parse-tree is set, an error is signalled.")
+ (:method :before ((ffi-gen ffi-generator))
+ (format *terminal-io* "~&Generating ~A bindings.~%"
+ (ffi-name ffi-gen)))
(:method ((ffi-gen ffi-generator))
(with-slots (xml-file parse-tree) ffi-gen
(assert (or xml-file parse-tree) (xml-file parse-tree)
@@ -54,6 +64,9 @@
(defgeneric write-bindings (ffi-gen
&key in-package if-exists if-does-not-exist)
(:documentation "Writes the generated bindings out to output-file.")
+ (:method :before ((ffi-gen ffi-generator) &key &allow-other-keys)
+ (format *terminal-io* "~&Writing bindings to ~S.~%"
+ (ffi-output-file ffi-gen)))
(:method ((ffi ffi-generator)
&key
(in-package nil)
diff -rN -u old-c2ffi/GCC-XML.lisp new-c2ffi/GCC-XML.lisp
--- old-c2ffi/GCC-XML.lisp 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/GCC-XML.lisp 2014-07-28 13:32:12.000000000 -0700
@@ -2,19 +2,20 @@
(export '(generate-xml))
-(defun generate-xml (h-file xml-file &optional gcc-opts-file)
- (format *terminal-io* "~&~%Running: ~S~%Options: ~S~%Input: ~S~%Output: ~S~%"
- *gccxml-command-path* (truename gcc-opts-file)
+(defvar *gccxml-command* "gccxml")
+
+(defun generate-xml (h-file xml-file &optional options)
+ (format *terminal-io* "~&~%Running ~A~%Options: ~A~%Input: ~S~%Output: ~S~%"
+ *gccxml-command* options
(namestring (truename h-file))
(namestring xml-file))
#+:openmcl
- (ccl:run-program (namestring *gccxml-command-path*)
- (list* (namestring (truename h-file))
- (namestring xml-file)
- (when gcc-opts-file
- (list (namestring (truename gcc-opts-file)))))
+ (ccl:run-program *gccxml-command*
+ (append options
+ (list (namestring (truename h-file))
+ (str+ "-fxml=" (namestring xml-file))))
:output *terminal-io*
:error *error-output*)
#-:openmcl
- (error "Generate-XML is currently only implemented for OpenMCL."))
+ (error "Generate-XML is currently only implemented for OpenMCL. Please run gccxml from the command line on other platforms."))
diff -rN -u old-c2ffi/Pathnames.lisp new-c2ffi/Pathnames.lisp
--- old-c2ffi/Pathnames.lisp 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/Pathnames.lisp 1969-12-31 16:00:00.000000000 -0800
@@ -1,10 +0,0 @@
-(in-package :c2ffi)
-
-(eval-when (:compile-toplevel)
- (defconstant +c-to-ffi-dir+
- (make-pathname :directory (pathname-directory *compile-file-truename*))))
-
-(defvar *gccxml-command-path*
- (merge-pathnames "gccxml-command.sh" +c-to-ffi-dir+))
-
-;(translate-logical-pathname "USER:Library;Lisp;MyCode;c-to-ffi;gccxml-command.sh")))
\ No newline at end of file
diff -rN -u old-c2ffi/Test.lisp new-c2ffi/Test.lisp
--- old-c2ffi/Test.lisp 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/Test.lisp 1969-12-31 16:00:00.000000000 -0800
@@ -1,5 +0,0 @@
-(require 'asdf)
-(asdf:operate 'asdf:load-op "c2ffi")
-
-(let ((*default-pathname-defaults* (make-pathname :directory (pathname-directory *load-truename*))))
- (c2ffi:make-uffi-for-files "Test/*.h" "Test/xplane-gccopts.txt"))
diff -rN -u old-c2ffi/c2ffi.asd new-c2ffi/c2ffi.asd
--- old-c2ffi/c2ffi.asd 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/c2ffi.asd 2014-07-28 13:32:12.000000000 -0700
@@ -3,14 +3,12 @@
:version "0.1"
:depends-on ("xmls" "cl-utilities" "iterate" "anaphora")
:components ((:file "Package")
- (:file "Pathnames"
- :depends-on ("Package"))
(:file "String-Utilities"
:depends-on ("Package"))
(:file "XML-Utilities"
:depends-on ("Package" "String-Utilities"))
(:file "GCC-XML"
- :depends-on ("Package" "Pathnames"))
+ :depends-on ("Package" "String-Utilities"))
(:file "FFI-Generator"
:depends-on ("Package" "String-Utilities" "XML-Utilities"))
(:file "c2ffi"
@@ -23,15 +21,3 @@
#+:uffi
(:file "UFFI-Generator"
:depends-on ("Package" "C-to-FFI"))))
-
-(defsystem "c2ffi-cffi"
- :author "Daniel Dickison (danieldickison@gmail.com)"
- :version "0.1"
- :depends-on ("c2ffi" "xmls" "cl-utilities" "anaphora" "cffi")
- :components ((:file "CFFI-Generator")))
-
-(defsystem "c2ffi-uffi"
- :author "Daniel Dickison (danieldickison@gmail.com)"
- :version "0.1"
- :depends-on ("c2ffi" "xmls" "cl-utilities" "anaphora" "cffi")
- :components ((:file "UFFI-Generator")))
diff -rN -u old-c2ffi/c2ffi.lisp new-c2ffi/c2ffi.lisp
--- old-c2ffi/c2ffi.lisp 2014-07-28 13:32:12.000000000 -0700
+++ new-c2ffi/c2ffi.lisp 2014-07-28 13:32:12.000000000 -0700
@@ -2,15 +2,41 @@
(in-package :c2ffi)
-(export '(generate-ffi-for-files
- eval-bindings))
+(export '(generate-ffi-for-files))
+#| Test Call -- must first cd into c2ffi source directory.
+ (c2ffi:generate-ffi-for-files "Test/*.h"
+ :gcc-options '("-DAPL=1" "-DIBM=0" "-DLIN=0")
+ :in-package :x-plane)
+|#
-(defun generate-ffi-for-files (dir
+(defun generate-ffi-for-files (h-files
&key (generator-class 'cffi-generator)
- gcc-options-file
+ gcc-options
in-package)
- (dolist (infile (directory dir))
+ "Generates FFI files for each input file designated by `h-files`. Each input file is first parsed by the GCC-XML program, whose XML output is then parsed by an instance of `generator-class`.
+
+* `h-files` -- a list of pathnames or a pathname designator. If it is a single
+ pathname designator, it may include wildcards which will be expanded
+ as by `directory` to produce the list of input files.
+* `generator-class` -- a symbol specifying a subclass of `ffi-generator`.
+ Default: `'cffi-generator`.
+* `gcc-options` -- a list of strings to be passed to GCC-XML.
+* `in-package` -- a package designator. If a string designator is used, the
+ package need not be currently defined, but must be defined when the FFI
+ bindings are loaded.
+
+#### Example ####
+
+The following example parses all .h files in the current directory and outputs CFFI bindings to files in a subdirectory named \"CFFI\". The compiler option -DMY_DEF=1 is passed to GCC-XML.
+
+ (generate-ffi-for-files \"*.h\"
+ :gcc-options '(\"-DMY_DEF=1\")
+ :in-package :cl-user)"
+
+ (dolist (infile (if (listp h-files)
+ h-files
+ (directory h-files)))
(let* ((xmlfile (make-pathname
:type "xml"
:directory (append (pathname-directory infile) '("XML"))
@@ -20,9 +46,10 @@
(ensure-directories-exist xmlfile)
;; Run GCC-XML.
- (generate-xml infile xmlfile gcc-options-file)
+ (generate-xml infile xmlfile gcc-options)
;; Run the FFI generator.
+ (generate-bindings generator)
(write-bindings generator :in-package in-package))))
(defun eval-bindings (defs)