chiark / gitweb /
Added support for pkg-config
[clg] / tools / config.lisp
index fa335fa9e7b9a5923c11ded340ecad42f498dbfb..0b776e0b7f966a7df01824647df099cb17d24bd0 100644 (file)
@@ -1,16 +1,25 @@
-(defun configure-cflags (config-program)
+(defparameter *pkg-config* "/usr/bin/pkg-config")
+
+(defun split-string (string &key (start 0) end)
+  (let ((position (position #\sp string :start start :end end)))
+    (if position
+       (cons
+        (subseq string start position)
+        (split-string string :start (1+ position) :end end))
+      (list (subseq string start end)))))
+
+(defun run-pkg-config (package &rest options)
   (let ((process
         (run-program
-         config-program '("--cflags") :wait t :output :stream)))
+         *pkg-config* (cons package options) :wait t :output :stream)))
     (unless process
-      (error "Unable to run %A" config-program))
-    (labels ((split (string)
-              (let ((position (position #\sp string)))
-                (if position
-                    (cons
-                     (subseq string 0 position)
-                     (split (subseq string (1+ position))))
-                  (list string)))))
+      (error "Unable to run ~A" *pkg-config*))
+    (unless (zerop (process-exit-code process))
+      (error "~A: ~A" *pkg-config* (read-line (process-output process))))
     (prog1
-       (split (read-line (process-output process)))
-      (process-close process)))))
+       (delete-if #'(lambda (str) (string= str "")) (split-string (read-line (process-output process))))
+      (process-close process))))
+
+
+(defun pkg-cflags (package)
+  (run-pkg-config package "--cflags"))