;; The following lines added by ql:add-to-init-file:
#-quicklisp
#+asdf (require :asdf)

(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

(push (pathname "~/source/_cl") ql:*local-project-directories*)

(ql:quickload :cffi :silent t)
(pushnew (merge-pathnames ".nix-profile/lib/" (user-homedir-pathname))
         cffi:*foreign-library-directories*)
(pushnew (merge-pathnames ".nix-profile/lib64/" (user-homedir-pathname))
         cffi:*foreign-library-directories*)
(pushnew (merge-pathnames "/run/current-system/sw/share/nix-ld/lib/" (user-homedir-pathname))
         cffi:*foreign-library-directories*)


(defun pkg-config-add-lib (libname)
 (let ((process (sb-ext:run-program "/usr/bin/env"
                                    (list "pkg-config" libname "--libs-only-L")
                                    :input t :output :stream :wait t)))
  (let ((stream (sb-ext:process-output process)))
       (loop for line = (read-line stream nil nil)
        while line do
              ;; Drop "-L" part, and add '/' to the end. '/' IS necessary!
              (pushnew (pathname (concatenate 'string (subseq line 2) "/"))
                       cffi:*foreign-library-directories*))
       (sb-ext:process-close process))))
;; load specific libs
(pkg-config-add-lib "libffi")
