5 (defun concatenate-strings (strings &optional delimiter)
6 (if (not (rest strings))
11 (if delimiter (string delimiter) "")
12 (concatenate-strings (rest strings) delimiter))))
14 ;;; The following code is more or less copied frm sb-bsd-sockets.asd,
15 ;;; but extended to allow flags to be set in a general way
17 (defclass unix-dso (module) ())
18 (defun unix-name (pathname)
21 (logical-pathname (translate-logical-pathname pathname))
24 (defmethod input-files ((operation compile-op) (dso unix-dso))
25 (mapcar #'component-pathname (module-components dso)))
27 (defmethod output-files ((operation compile-op) (dso unix-dso))
28 (let ((dir (component-pathname dso)))
30 (make-pathname :type "so"
31 :name (car (last (pathname-directory dir)))
32 :directory (butlast (pathname-directory dir))
36 (defmethod perform :after ((operation compile-op) (dso unix-dso))
37 (let ((dso-name (unix-name (car (output-files operation dso)))))
40 "gcc ~A -o ~S ~{~S ~}"
42 ;; (sb-ext:posix-getenv "EXTRA_LDFLAGS")
44 #+sunos "-shared -lresolv -lsocket -lnsl"
46 #-(or darwin sunos) "-shared")
50 (output-files operation c))
51 (module-components dso)))))
52 (error 'operation-error :operation operation :component dso))))
55 (defvar *loaded-libraries* ())
57 (defun load-dso (filename)
58 #+sbcl(sb-alien:load-shared-object filename)
59 #+cmu(ext:load-foreign filename)
61 (unless (find filename *loaded-libraries* :test #'equal)
62 (ffi::foreign-library (namestring filename))
63 (push filename *loaded-libraries*)))
66 (defmethod perform ((o load-op) (c unix-dso))
67 (let ((co (make-instance 'compile-op)))
68 (let ((filename (car (output-files co c))))
69 (load-dso filename))))
73 (defclass c-source-file (source-file)
74 ((cflags :initform nil :initarg :cflags)
75 (optimization :initform 2 :initarg :optimization)
76 (definitions :initform nil :initarg :definitions)
77 (include-paths :initform nil :initarg :include-paths)))
80 (defmethod output-files ((op compile-op) (c c-source-file))
81 (list (make-pathname :type "o" :defaults (component-pathname c))))
84 (defmethod perform ((op compile-op) (c c-source-file))
86 (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
90 (when (slot-value c 'optimization)
91 (list (format nil "-O~A" (slot-value c 'optimization))))
93 for symbol in (slot-value c 'definitions)
94 collect (format nil "-D~A" symbol))
96 for path in (slot-value c 'include-paths)
97 collect (format nil "-I~A" path))
98 (slot-value c 'cflags))
100 (unix-name (car (output-files op c)))
101 (unix-name (component-pathname c))))
102 (error 'operation-error :operation op :component c)))
105 (defmethod perform ((operation load-op) (c c-source-file))
111 (defclass library (component)
112 ((libdir :initarg :libdir)))
115 (defun split-path (path)
116 (labels ((split (path)
117 (unless (zerop (length path))
118 (let ((slash (position #\/ path)))
120 (cons (subseq path 0 slash) (split (subseq path (1+ slash))))
122 (if (and (not (zerop (length path))) (char= (char path 0) #\/))
123 (cons :absolute (split (subseq path 1)))
124 (cons :relative (split path)))))
127 (defmethod component-pathname ((lib library))
128 (make-pathname :type "so"
129 :name (component-name lib)
130 :directory (split-path (slot-value lib 'libdir))))
132 (defmethod perform ((o load-op) (c library))
133 (load-dso (component-pathname c)))
135 (defmethod perform ((operation operation) (c library))
138 (defmethod operation-done-p ((o load-op) (c library))
139 #+sbcl(find (sb-ext::unix-namestring (component-pathname c)) sb-alien::*shared-objects* :key #'sb-alien::shared-object-file :test #'equal)
140 #+cmu(rassoc (unix::unix-namestring (component-pathname c))
141 system::*global-table*
142 :key #'(lambda (pathname)
143 (when pathname (unix::unix-namestring pathname)))
145 #+clisp(find (component-pathname c) *loaded-libraries* :test #'equal))
147 (defmethod operation-done-p ((o operation) (c library))