-(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"))