3 (export '*dso-extension*)
5 (defvar *dso-extension* #-darwin"so" #+darwin"dylib")
8 (defun concatenate-strings (strings &optional delimiter)
9 (if (not (rest strings))
14 (if delimiter (string delimiter) "")
15 (concatenate-strings (rest strings) delimiter))))
17 ;;; The following code is more or less copied frm sb-bsd-sockets.asd,
18 ;;; but extended to allow flags to be set in a general way
20 (defclass unix-dso (module) ())
21 (defun unix-name (pathname)
24 (logical-pathname (translate-logical-pathname pathname))
27 (defmethod input-files ((operation compile-op) (dso unix-dso))
28 (mapcar #'component-pathname (module-components dso)))
30 (defmethod output-files ((operation compile-op) (dso unix-dso))
31 (let ((dir (component-pathname dso)))
33 (make-pathname :type *dso-extension*
34 :name (car (last (pathname-directory dir)))
35 :directory (butlast (pathname-directory dir))
39 (defmethod perform :after ((operation compile-op) (dso unix-dso))
40 (let ((dso-name (unix-name (car (output-files operation dso)))))
43 "gcc ~A -o ~S ~{~S ~}"
45 ;; (sb-ext:posix-getenv "EXTRA_LDFLAGS")
47 #+sunos "-shared -lresolv -lsocket -lnsl"
49 #-(or darwin sunos) "-shared")
53 (output-files operation c))
54 (module-components dso)))))
55 (error 'operation-error :operation operation :component dso))))
58 (defvar *loaded-libraries* ())
60 (defun load-dso (filename)
61 #+sbcl(sb-alien:load-shared-object filename)
62 #+cmu(ext:load-foreign filename)
64 (unless (find filename *loaded-libraries* :test #'equal)
65 (ffi::foreign-library (namestring filename))
66 (push filename *loaded-libraries*)))
69 (defmethod perform ((o load-op) (c unix-dso))
70 (let ((co (make-instance 'compile-op)))
71 (let ((filename (car (output-files co c))))
72 (load-dso filename))))
76 (defclass c-source-file (source-file)
77 ((cflags :initform nil :initarg :cflags)
78 (optimization :initform 2 :initarg :optimization)
79 (definitions :initform nil :initarg :definitions)
80 (include-paths :initform nil :initarg :include-paths)))
83 (defmethod output-files ((op compile-op) (c c-source-file))
84 (list (make-pathname :type "o" :defaults (component-pathname c))))
87 (defmethod perform ((op compile-op) (c c-source-file))
89 (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
93 (when (slot-value c 'optimization)
94 (list (format nil "-O~A" (slot-value c 'optimization))))
96 for symbol in (slot-value c 'definitions)
97 collect (format nil "-D~A" symbol))
99 for path in (slot-value c 'include-paths)
100 collect (format nil "-I~A" path))
101 (slot-value c 'cflags))
103 (unix-name (car (output-files op c)))
104 (unix-name (component-pathname c))))
105 (error 'operation-error :operation op :component c)))
108 (defmethod perform ((operation load-op) (c c-source-file))
114 (defclass library (component)
115 ((libdir :initarg :libdir)))
118 (defun split-path (path)
119 (labels ((split (path)
120 (unless (zerop (length path))
121 (let ((slash (position #\/ path)))
123 (cons (subseq path 0 slash) (split (subseq path (1+ slash))))
125 (if (and (not (zerop (length path))) (char= (char path 0) #\/))
126 (cons :absolute (split (subseq path 1)))
127 (cons :relative (split path)))))
130 (defmethod component-pathname ((lib library))
131 (make-pathname :type *dso-extension*
132 :name (component-name lib)
133 :directory (split-path (slot-value lib 'libdir))))
135 (defmethod perform ((o load-op) (c library))
136 (load-dso (component-pathname c)))
138 (defmethod perform ((operation operation) (c library))
141 (defmethod operation-done-p ((o load-op) (c library))
142 #+sbcl(find (sb-ext::unix-namestring (component-pathname c)) sb-alien::*shared-objects* :key #'sb-alien::shared-object-file :test #'equal)
143 #+cmu(rassoc (unix::unix-namestring (component-pathname c))
144 system::*global-table*
145 :key #'(lambda (pathname)
146 (when pathname (unix::unix-namestring pathname)))
148 #+clisp(find (component-pathname c) *loaded-libraries* :test #'equal))
150 (defmethod operation-done-p ((o operation) (c library))