Windows issues parsing these characters. Bug fix for entering edit mode without setti...
[cowl.git] / asdf-cpplib.lisp
blob597faa4ef3dd2650a98d25dc51f1f438db6a2a1c
1 (defpackage #:asdf-cpplib
2 (:use #:asdf #:cl)
3 (:export #:system-split #:cpp-library))
5 (in-package #:asdf-cpplib)
8 ;;; PARAMETERS
9 (defvar *c++-compiler* "c++")
10 (defvar *c++-flags* '("-fPIC" "-O2" "-W" "-Wall" "-shared"))
11 (defvar *libs* '())
13 ;;;; UTILITY
14 (defun system (program args &key (echo nil))
15 (flet ((quotify (a)
16 (if (find-if #'(lambda (c)
17 (find c '(#\Space #\Newline #\Return #\Linefeed #\Tab)))
19 (format nil "~s" a)
20 a)))
21 (when echo (format t "~a ~{~a~^ ~}~%"
22 (quotify program)
23 (mapcar #'quotify args))))
24 #+sbcl
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)
32 while j))
35 ;;;; ASDF EXTENSIONS
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))))
43 `(progn
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
47 (etypecase val
48 (null (setf ,extra nil))
49 (cons (setf ,extra val))
50 (symbol (setf (,extra-of cpp-library)
51 (symbol-value val)))
52 (string (setf (,extra-of cpp-library)
53 (remove-if #'(lambda (s)
54 (zerop (length 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))
74 #+sbcl
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*
85 (append *c++-flags*
86 (extra-cflags-of c)
87 (list "-o" (namestring (first (output-files o c))))
88 (mapcar #'namestring (input-files o c))
89 (extra-libs-of c))
90 :echo t))
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))
96 (list
97 (make-pathname :type
98 #+unix "so"
99 #+windows "dll"
100 #+darwin "dylib"
101 :defaults (component-pathname c))))