chiark / gitweb /
Add a boundp-function slot, which is required by virtual slot getter.
[clg] / tools / config.lisp
CommitLineData
d3768217 1(defpackage #:pkg-config
ec75b3fc 2 (:use #:common-lisp #:clg-utils #+(or cmu clisp) #:ext #+sbcl #:sb-ext)
3 #+sbcl
4 (:import-from #:sb-int #:featurep)
a4263d6d 5 (:export #:pkg-cflags #:pkg-libs #:pkg-exists-p #:pkg-version
6 #:pkg-variable #:pkg-libdir #:tmpname)
b3c0b56a 7 (:export #:featurep #:sbcl>= #:sbcl< #:clisp>= #:clisp<))
d3768217 8
9(in-package #:pkg-config)
10
a4263d6d 11(defparameter *pkg-config* "pkg-config")
300d704e 12
4539aedf 13
a4263d6d 14(defun tmpname (suffix)
15 (format nil "~Aclg-~A-~A"
16 #-win32 "/tmp/" #+win32 "c:/temp/"
17 #+sbcl(sb-posix:getpid)
18 #+cmu(unix:unix-getpid)
19 #+clisp(os:process-id)
20 suffix))
300d704e 21
ec75b3fc 22(defun run-pkg-config (package error-p &rest options)
a4263d6d 23 (let ((outname (tmpname "pkg-config")))
ec75b3fc 24 (unwind-protect
a4263d6d 25 (let* ((asdf::*verbose-out* nil)
26 (exit-code
27 (asdf:run-shell-command
5d6e0821 28 "~A ~A ~:[~;--print-errors ~]~{~A ~} >~A 2>&1"
a4263d6d 29 *pkg-config* package error-p options outname)))
ec75b3fc 30 (cond
31 ((= exit-code 127) (error "Unable to run ~A" *pkg-config*))
32 ((and error-p (not (zerop exit-code)))
a4263d6d 33 (with-open-file (output outname)
ec75b3fc 34 (let ((errmsg (read-lines output)))
35 (error
36 (if (not errmsg)
37 (format nil "~A terminated with exit code ~A" *pkg-config* exit-code)
38 (format nil "~A: ~{~A~%~}" *pkg-config* errmsg))))))
39 (t
40 (values
a4263d6d 41 (with-open-file (output outname)
ec75b3fc 42 (read-lines output))
43 exit-code))))
a4263d6d 44 (delete-file outname))))
ec75b3fc 45
300d704e 46
47(defun pkg-cflags (package)
4539aedf 48 (split-string (first (run-pkg-config package t "--cflags"))))
49
d3768217 50(defun pkg-libs (package)
51 (split-string (first (run-pkg-config package t "--libs"))))
52
4539aedf 53
a4263d6d 54;; With
55;; (let ((version-check
56;; (cond
57;; (version (format nil "= ~A" version))
58;; (atleast-version (format nil ">= ~A" atleast-version))
59;; (max-version (format nil "<= ~A" max-version))
60;; (t ""))))
61;; ...)
62;; when running
63;; (PKG-EXISTS-P "glib-2.0" :ATLEAST-VERSION "2.4.0" :ERROR T)
64;; the EXIT-CODE in RUN-PKG-CONFIG will be 1 on ms windows and 0 on linux
65
66;; Both on ms windows and linux
67;; "pkg-config glib-2.0 --print-errors -exists >=2.4.0" is O.K. but
68;; "pkg-config glib-2.0 --print-errors -exists >= 2.4.0" prints out
69;; an error message.
70;; However,
71;; "pkg-config glib-2.0 --print-errors -exists =2.12.11" prints out
72;; an error message but
73;; "pkg-config glib-2.0 --print-errors -exists = 2.12.11" is O.K.
74;; We can get around this problem by using
75;; (let ((version-check
76;; (cond
77;; (version (format nil "--exact-version=~A" version))
78;; (atleast-version (format nil "--atleast-version=~A" atleast-version))
79;; (max-version (format nil "--max-version=~A" max-version))
80;; (t ""))))
81;; ...)
82;; - cph 17-May-2007
83
84;; Could the problem with --exists on win32 be caused by improper quoting?
85;; Since --exact-version, --atleast-version and --max-version doesn't print
86;; any error message, we stick to --exists on non Win32 platforms.
87;; - esj 2007-06-14
88
89
90;; --fix: in win32 sbcl
91;; (pkg-exists-p "glib-2.0" :version "3.12.11" :error t)
92;; will hang indefinitely. - cph 17-May-2007
93
0cd95de0 94(defun pkg-exists-p (package &key version atleast-version max-version error)
4539aedf 95 (let ((version-check
96 (cond
a4263d6d 97 (version
98 #-win32(format nil "--exists \"= ~A\"" version)
99 #+win32(format nil "--exact-version=~A" version))
100 (atleast-version
101 #-win32(format nil "--exists \">= ~A\"" atleast-version)
102 #+win32(format nil "--atleast-version=~A" atleast-version))
103 (max-version
104 #-win32(format nil "--exists \"<= ~A\"" max-version)
105 #+win32(format nil "--max-version=~A" max-version))
4539aedf 106 (t ""))))
a4263d6d 107 (zerop (nth-value 1 (run-pkg-config package error version-check)))))
4539aedf 108
109(defun pkg-version (package)
110 (first (run-pkg-config package t "--modversion")))
111
4539aedf 112(defun pkg-variable (package variable)
113 (first (run-pkg-config package t "--variable" variable)))
ec75b3fc 114
a4263d6d 115(defun pkg-libdir (package)
116 #-win32
117 (pkg-variable package "libdir")
118 #+win32
119 (let ((ldir (pkg-variable package "libdir")))
120 (format nil "~Abin" (subseq ldir 0 (search "lib" ldir :from-end t)))))
121
ec75b3fc 122
123(defun |#?-reader| (stream subchar arg)
124 (declare (ignore subchar arg))
a8ed38f3 125 (let* ((not-p (when (char= (peek-char nil stream) #\-)
126 (read-char stream)))
127 (conditional (read stream t nil t)))
ec75b3fc 128 (cond
129 (*read-suppress* (read stream t nil t))
130 ((not *read-eval*)
131 (error 'reader-error
132 :format-control "Attempt to read #? while *READ-EVAL* is bound to NIL."
133 :format-arguments nil :stream stream))
134 ((if not-p
135 (eval conditional)
136 (not (eval conditional)))
137 (let ((*read-suppress* t))
138 (read stream t nil t)))))
139 (values))
140
141(set-dispatch-macro-character #\# #\? #'|#?-reader|)
142
143
144#+sbcl
145(progn
146 (defun sbcl-version ()
2cf62811 147 (values-list
148 (loop
149 repeat 4
19b56e93 150 ;; We use . and - as delimiters because some Linux
151 ;; distributions tend to patch SBCL and add a distro-specific
152 ;; version tag (like 1.0.19-gentoo).
5fe4b66c 153 for part in (split-string (lisp-implementation-version) :delimiter '(#\. #\-))
2cf62811 154 while (every #'digit-char-p part)
155 collect (parse-integer part))))
156 (defun sbcl>= (major minor micro &optional patch)
157 (multiple-value-bind (%major %minor %micro %patch) (sbcl-version)
ec75b3fc 158 (or
2cf62811 159 (> %major major)
160 (and (= %major major) (> %minor minor))
f2b5b118 161 (and (= %major major) (= %minor minor) (> %micro micro))
2cf62811 162 (and
163 (= %major major) (= %minor minor) (= %micro micro)
164 (>= (or %patch 0) (or patch 0))))))
165 (defun sbcl< (major minor micro &optional patch)
166 (not (sbcl>= major minor micro patch))))
ec75b3fc 167
168#-sbcl
a4263d6d 169(progn
2cf62811 170 (defun sbcl>= (major minor micro &optional patch)
171 (declare (ignore major minor micro patch))
a4263d6d 172 nil)
2cf62811 173 (defun sbcl< (major minor micro &optional patch)
174 (declare (ignore major minor micro patch))
a4263d6d 175 nil))
ca70819a 176
177#+clisp
178(progn
179 (defun clisp-version ()
180 (let* ((dot (position #\. (lisp-implementation-version))))
181 (values
182 (parse-integer (lisp-implementation-version) :end dot)
183 (parse-integer (lisp-implementation-version) :start (1+ dot) :junk-allowed t))))
184 (defun clisp>= (req-major req-minor)
185 (multiple-value-bind (major minor) (clisp-version)
186 (or
187 (> major req-major)
b3c0b56a 188 (and (= major req-major) (> minor req-minor)))))
189 (defun clisp< (req-major req-minor)
190 (not (clisp>= req-major req-minor))))
ca70819a 191
192#-clisp
b3c0b56a 193(progn
194 (defun clisp>= (req-major req-minor)
195 (declare (ignore req-major req-minor))
196 nil)
197 (defun clisp< (req-major req-minor)
198 (declare (ignore req-major req-minor))
199 nil))