(in-package :asdf-ecs) (defclass c-library (component) ((library-definition :initarg :definition :accessor library-definition)) (:documentation "Base class for c libraries.")) (defmethod input-files ((o compile-op) (c c-library)) nil) (defmethod input-files ((o load-op) (c c-library)) (error "Either you're trying to use c-library directly, or the author of your subclass has forgotten to define an input-files method.")) (defmethod operation-done-p ((o compile-op) (c c-library)) nil) (defmethod operation-done-p ((o load-op) (c c-library)) nil) (defclass c-source-file (asdf:c-source-file) ((compile-options :initarg :compile-options :initform nil :accessor compile-options :documentation "alist of (compiler . compiler-options). If you want to ensure a specific ordering, write a compiler-options method instead."))) (defgeneric compiler-options (compiler c-source-file &key input-file output-file) (:documentation "Returns a list of options to pass to .") (:method ((c (eql (get-compiler :gcc))) (f c-source-file) &key input-file output-file) ;; Do the arguments passed to gcc depend on a specific ordering? Should ;; compile-options be between -shared and -o, in that case? (append (cdr (assoc :gcc (compile-options f))) (list #-darwin "-shared" #+darwin "-dynamiclib" "-o" output-file input-file)))) (defmethod perform ((o compile-op) (c c-source-file)) (compiler-perform (get-compiler *compiler*) o c)) (defgeneric compiler-perform (compiler compile-op c-source-file) (:documentation "asdf:perform, but with a compiler.") (:method ((compiler (eql (get-compiler :gcc))) (o compile-op) (c c-source-file)) (unless (zerop (run-shell-command "~A ~{~A ~}" (compiler-path compiler) (compiler-options compiler c :input-file (namestring (component-pathname c)) :output-file (namestring (first (output-files o c)))))) (error 'operation-error :component c :operation o))))