1 (defpackage #:asdf-cpplib
3 (:export
#:system-split
#:cpp-library
))
5 (in-package #:asdf-cpplib
)
9 (defvar *c
++-compiler
* "c++")
10 (defvar *c
++-flags
* '("-fPIC" "-O2" "-W" "-Wall" "-shared"))
14 (defun system (program args
&key
(echo nil
))
16 (if (find-if #'(lambda (c)
17 (find c
'(#\Space
#\Newline
#\Return
#\Linefeed
#\Tab
)))
21 (when echo
(format t
"~a ~{~a~^ ~}~%"
23 (mapcar #'quotify args
))))
25 (with-output-to-string (out)
26 (sb-ext:run-program program args
:wait t
:search t
:output out
:error t
:input nil
)))
28 (defun string-split (string &optional
(test #'(lambda (c) (find c
'(#\Newline
#\Space
#\Page
#\Tab
#\Return
#\Linefeed
)))))
29 (loop for i
= 0 then
(1+ j
)
30 as j
= (position-if test string
:start i
)
31 collect
(subseq string i j
)
36 (defclass cpp-library
(asdf:source-file
)
37 ((extra-cflags :initarg
:extra-cflags
:initform nil
:reader extra-cflags-of
)
38 (extra-libs :initarg
:extra-libs
:initform nil
:reader extra-libs-of
)))
40 (defmacro define-extra-param
(name)
41 (let ((extra-of (intern (format nil
"EXTRA-~a-OF" name
)))
42 (extra (intern (format nil
"EXTRA-~a" name
))))
44 (defmethod (setf ,extra-of
) (val (cpp-library cpp-library
))
45 ;; (format t "Setting extra ~a to ~s~%" ',name val)
46 (with-slots (,extra
) cpp-library
48 (null (setf ,extra nil
))
49 (cons (setf ,extra val
))
50 (symbol (setf (,extra-of cpp-library
)
52 (string (setf (,extra-of cpp-library
)
53 (remove-if #'(lambda (s)
55 (string-split val
))))))))))
57 (define-extra-param cflags
)
58 (define-extra-param libs
)
60 (defmethod initialize-instance :after
((cpp-library cpp-library
)
61 &key
(extra-cflags nil
) (extra-libs nil
) &allow-other-keys
)
62 (setf (extra-cflags-of cpp-library
) extra-cflags
63 (extra-libs-of cpp-library
) extra-libs
))
65 (defmethod reinitialize-instance :after
((cpp-library cpp-library
)
66 &key
(extra-cflags nil
) (extra-libs nil
) &allow-other-keys
)
67 (setf (extra-cflags-of cpp-library
) extra-cflags
68 (extra-libs-of cpp-library
) extra-libs
))
71 (defmethod source-file-type ((c cpp-library
) (s module
)) "cpp")
73 (defmethod perform ((o load-op
) (c cpp-library
))
75 (sb-alien:load-shared-object
(namestring (first (input-files o c
))))
77 #|
(funcall (find-symbol "LOAD-FOREIGN-LIBRARY" (find-package '#:cffi
))
78 (list* :or
(mapcar #'(lambda (p)
79 (make-pathname :type nil
:defaults p
))
80 (input-files o c
))))|
#
83 (defmethod perform ((o compile-op
) (c cpp-library
))
84 (system *c
++-compiler
*
87 (list "-o" (namestring (first (output-files o c
))))
88 (mapcar #'namestring
(input-files o c
))
92 (defmethod input-files ((o compile-op
) (c cpp-library
))
93 (list (component-pathname c
)))
95 (defmethod output-files ((o compile-op
) (c cpp-library
))
101 :defaults
(component-pathname c
))))