1 (defparameter *pkg-config* "pkg-config")
3 (defun split-string (string &key (start 0) (end (length string)))
4 (let ((position (position #\sp string :start start :end end)))
6 ((zerop (- end start)) nil)
7 ((not position) (list (subseq string start end)))
8 ((= position start) (split-string string :start (1+ start) :end end))
10 (subseq string start position)
11 (split-string string :start (1+ position) :end end))))))
14 (defun read-lines (&optional (stream *standard-input*))
15 (let ((line (read-line stream nil)))
17 (cons line (read-lines stream)))))
20 (defun read-string (&optional (stream *standard-input*)
21 (delimiter #\newline) (eof-error-p t) eof-value)
22 (let ((string (make-array 0 :element-type 'character
23 :fill-pointer t :adjustable t)))
24 ;; I really need to learn how to use the loop facility
25 (labels ((read-chars ()
26 (let ((char (read-char stream (and eof-error-p delimiter))))
28 (vector-push-extend char string)
29 (unless (eq char delimiter)
33 ((not (zerop (length string))) string)
34 ((not eof-error-p) eof-value)
35 ((error 'end-of-file :stream stream)))))
38 (defun run-pkg-config (package error &rest options)
41 *pkg-config* (cons package options) :wait t :output :stream)))
43 (error "Unable to run ~A" *pkg-config*))
44 (let ((exit-code (process-exit-code process)))
45 (unless (or (not error) (zerop exit-code))
48 (read-string (process-error process) nil)
49 (format nil "~A terminated with exit code ~A"
50 *pkg-config* exit-code))))
51 (let ((output (read-lines (process-output process))))
52 (process-close process)
53 (values output exit-code)))))
56 (defun pkg-cflags (package)
57 (split-string (first (run-pkg-config package t "--cflags"))))
60 (defun pkg-exists-p (package &key version atleast-version max-version
64 (version (format nil "= ~A" version))
65 (atleast-version (format nil ">= ~A" atleast-version))
66 (max-version (format nil "<= ~A" max-version))
70 (run-pkg-config package t "--print-errors" "--exists" version-check)
72 (multiple-value-bind (output exit-code)
73 (run-pkg-config package nil "--exists" version-check)
74 (declare (ignore output))
78 (defun pkg-version (package)
79 (first (run-pkg-config package t "--modversion")))
82 (defun pkg-variable (package variable)
83 (first (run-pkg-config package t "--variable" variable)))