anchor.diff:  (defpackage #:pkg-config
  -  (:use #:common-lisp #+cmu #:ext #+sbcl #:sb-ext)
  -  (:export #:pkg-cflags #:pkg-libs #:pkg-exists-p #:pkg-version 
  -	   #:pkg-variable))
  +  (:use #:common-lisp #:clg-utils #+(or cmu clisp) #:ext #+sbcl #:sb-ext)
  +  #+sbcl
  +  (:import-from #:sb-int #:featurep)
  +  (:export #:pkg-cflags #:pkg-libs #:pkg-exists-p #:pkg-version #:pkg-variable)
  +  (:export #:featurep #:sbcl>=))
   
   (in-package #:pkg-config)
   
   (defparameter *pkg-config* "/usr/bin/pkg-config")
   
  -(defun split-string (string &key (start 0) (end (length string)))
  -  (let ((position (position #\sp string :start start :end end)))
  -    (cond
  -     ((zerop (- end start)) nil)
  -     ((not position) (list (subseq string start end)))
  -     ((= position start) (split-string string :start (1+ start) :end end))
  -     (t	(cons
  -	 (subseq string start position)
  -	 (split-string string :start (1+ position) :end end))))))
  -
  -
  -(defun read-lines (&optional (stream *standard-input*))
  -  (let ((line (read-line stream nil)))
  -    (when line
  -      (cons line (read-lines stream)))))
  -
  -
  -(defun read-string (&optional (stream *standard-input*)
  -		    (delimiter #\newline) (eof-error-p t) eof-value)
  -  (let ((string (make-array 0 :element-type 'character
  -			    :fill-pointer t :adjustable t)))
  -    ;; I really need to learn how to use the loop facility
  -    (labels ((read-chars ()
  -               (let ((char (read-char stream (and eof-error-p delimiter))))
  -		 (when char
  -		   (vector-push-extend char string)
  -		   (unless (eq char delimiter)
  -		     (read-chars))))))
  -      (read-chars))
  -    (cond
  -     ((not (zerop (length string))) string)
  -     ((not eof-error-p) eof-value)
  -     ((error 'end-of-file :stream stream)))))
  -
   
   #+(or sbcl cmu)
  -(defun run-pkg-config (package error &rest options)
  +(defun run-pkg-config (package error-p &rest options)
     (let ((process
   	 (run-program
   	  *pkg-config* (cons package options) :wait t :output :stream)))
       (unless process
         (error "Unable to run ~A" *pkg-config*))
       (let ((exit-code (process-exit-code process)))
  -      (unless (or (not error) (zerop exit-code))
  +      (unless (or (not error-p) (zerop exit-code))
   	(error
   	 (or
  -	  (read-string (process-error process) nil)
  +	  (format nil "~A: ~{~A~%~}" *pkg-config* (read-lines (process-error process)))
   	  (format nil "~A terminated with exit code ~A"
   		  *pkg-config* exit-code))))
         (let ((output (read-lines (process-output process))))	  
  
positive.code: 
  (defun pkg-variable (package variable)
    (first (run-pkg-config package t "--variable" variable)))
  
negative.code: 	(values output exit-code)))))
  
  #+clisp
  (defun run-pkg-config (package error-p &rest options)
    (let ((outfile (format nil "/tmp/clg-pkg-config-~A-output" (os:process-id)))
  	(errfile (format nil "/tmp/clg-pkg-config-~A-error" (os:process-id))))
      (unwind-protect
  	(let ((exit-code 
  	       (run-shell-command 
  		(format nil "~A ~A ~{~A ~}2>~A" 
  		 *pkg-config* package 
  		 (mapcar #'(lambda (option) 
  			     (format nil "'~A'" option))
  			 options)
  		 errfile)
  		:output outfile :if-output-exists :overwrite)))
  	  (cond
  	   ((= exit-code 127) (error "Unable to run ~A" *pkg-config*))
  	   ((and error-p (not (zerop exit-code)))
  	    (with-open-file (output errfile)
  	      (let ((errmsg (read-lines output)))
  		(error
  		 (if (not errmsg)
  		     (format nil "~A terminated with exit code ~A" *pkg-config* exit-code)
  		   (format nil "~A: ~{~A~%~}" *pkg-config* errmsg))))))
  	   (t
  	    (values 
  	     (with-open-file (output outfile)
  	       (read-lines output))
  	     exit-code))))
        (progn
  	(delete-file outfile)
  	(delete-file errfile)))))
  
  
  (defun pkg-cflags (package)
    (split-string (first (run-pkg-config package t "--cflags"))))
  