- (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)))))
- (prog1
- (split (read-line (process-output process)))
- (process-close process)))))
+ (error "Unable to run ~A" *pkg-config*))
+ (let ((exit-code (process-exit-code process)))
+ (unless (or (not error) (zerop exit-code))
+ (error
+ (or
+ (read-string (process-error process) nil)
+ (format nil "~A terminated with exit code ~A"
+ *pkg-config* exit-code))))
+ (let ((output (read-lines (process-output process))))
+ (process-close process)
+ (values output exit-code)))))
+
+#+clisp
+;; I haven't figured out how to do error checking with CLISP's run-program
+(defun run-pkg-config (package error &rest options)
+ (declare (ignore error))
+ (let ((stream (ext:run-program *pkg-config* :arguments (cons package options) :output :stream)))
+ (read-lines stream)))
+
+(defun pkg-cflags (package)
+ (split-string (first (run-pkg-config package t "--cflags"))))
+
+(defun pkg-libs (package)
+ (split-string (first (run-pkg-config package t "--libs"))))
+
+
+(defun pkg-exists-p (package &key version atleast-version max-version
+ ( error t))
+ (let ((version-check
+ (cond
+ (version (format nil "= ~A" version))
+ (atleast-version (format nil ">= ~A" atleast-version))
+ (max-version (format nil "<= ~A" max-version))
+ (t ""))))
+ (if error
+ (progn
+ (run-pkg-config package t "--print-errors" "--exists" version-check)
+ t)
+ (multiple-value-bind (output exit-code)
+ (run-pkg-config package nil "--exists" version-check)
+ (declare (ignore output))
+ (zerop exit-code)))))
+
+
+(defun pkg-version (package)
+ (first (run-pkg-config package t "--modversion")))
+
+
+(defun pkg-variable (package variable)
+ (first (run-pkg-config package t "--variable" variable)))