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 (defun load-dso (filename)
56 #+sbcl(sb-alien:load-shared-object filename)
57 #+cmu(ext:load-foreign filename))
60 (defmethod perform ((o load-op) (c unix-dso))
61 (let ((co (make-instance 'compile-op)))
62 (let ((filename (car (output-files co c))))
63 (load-dso filename))))
67 (defclass c-source-file (source-file)
68 ((cflags :initform nil :initarg :cflags)
69 (optimization :initform 2 :initarg :optimization)
70 (definitions :initform nil :initarg :definitions)
71 (include-paths :initform nil :initarg :include-paths)))
74 (defmethod output-files ((op compile-op) (c c-source-file))
75 (list (make-pathname :type "o" :defaults (component-pathname c))))
78 (defmethod perform ((op compile-op) (c c-source-file))
80 (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
84 (when (slot-value c 'optimization)
85 (list (format nil "-O~A" (slot-value c 'optimization))))
87 for symbol in (slot-value c 'definitions)
88 collect (format nil "-D~A" symbol))
90 for path in (slot-value c 'include-paths)
91 collect (format nil "-I~A" path))
92 (slot-value c 'cflags))
94 (unix-name (car (output-files op c)))
95 (unix-name (component-pathname c))))
96 (error 'operation-error :operation op :component c)))
99 (defmethod perform ((operation load-op) (c c-source-file))
105 (defclass library (component)
106 ((libdir :initarg :libdir)))
109 (defun relative-pathname (path)
112 (string (if (char= #\/ (char path 0))
116 (defmethod component-pathname ((lib library))
117 (make-pathname :type "so"
118 :name (component-name lib)
119 :directory (relative-pathname (slot-value lib 'libdir))))
121 (defmethod perform ((o load-op) (c library))
122 (load-dso (component-pathname c)))
124 (defmethod perform ((operation operation) (c library))
127 (defmethod operation-done-p ((o load-op) (c library))
128 #+sbcl(find (sb-ext::unix-namestring (component-pathname c)) sb-alien::*shared-objects* :key #'sb-alien::shared-object-file :test #'equal)
129 #+cmu(rassoc (unix::unix-namestring (component-pathname c))
130 system::*global-table*
131 :key #'(lambda (pathname)
132 (when pathname (unix::unix-namestring pathname)))
135 (defmethod operation-done-p ((o operation) (c library))