chiark / gitweb /
Fix to load shared libraries from default locations in CMUCL and CLISP
[clg] / tools / asdf-extensions.lisp
index 94da8c7b3afaed5228ec04322ed9a4d33809f1c2..30dd410b3ea83caf62e09fee74e878b0ff5f5e36 100644 (file)
@@ -1,10 +1,12 @@
 (in-package :asdf)
 
-(export '(*dso-extension* *operation* *system* *component*))
+(export '(*absolute-paths-as-default* *dso-extension*
+         *operation* *system* *component* library shared-object))
 
 (defparameter *dso-extension* 
  #-(or darwin win32)"so" #+darwin"dylib" #+win32"dll")
 
+(defparameter *absolute-paths-as-default* nil)
 
 ;;; The following code is more or less copied from sb-bsd-sockets.asd,
 ;;; but extended to allow flags to be set in a general way. The class
@@ -13,7 +15,8 @@ (defparameter *dso-extension*
 
 (defclass shared-object (module)
   ((ldflags :initform nil :initarg :ldflags)
-   (absolute :initform nil :initarg :absolute :reader absolute-p)))
+   (absolute :initform *absolute-paths-as-default* 
+            :initarg :absolute :reader absolute-p)))
 
 (defun ensure-namestring (pathname)
   (namestring 
@@ -78,7 +81,10 @@ (defun load-shared-object (pathname &optional (absolute-p t))
          (setf (cdr shared-object) name+type))))
     #+clisp 
     (progn
+      #?-(pkg-config:clisp>= 2 45)
       (ffi::foreign-library namestring)
+      #?(pkg-config:clisp>= 2 45)
+      (ffi:open-foreign-library namestring)
       (pushnew 
        (if absolute-p namestring name+type)
        *loaded-libraries* :test #'string=))))
@@ -104,7 +110,7 @@ (defmethod output-files ((op compile-op) (c c-source-file))
 
 (defmethod perform ((op compile-op) (c c-source-file))
   (unless
-      (= 0 (run-shell-command "gcc ~A~{ ~A~} -o ~S -c ~S"
+      (= 0 (run-shell-command "gcc -Wall ~A~{ ~A~} -o ~S -c ~S"
            #-win32 "-fPIC"
            #+win32 "-DBUILD_DLL"
            (nconc
@@ -131,25 +137,34 @@ (defmethod perform ((operation load-op) (c c-source-file))
 (defclass library (component) 
   ((libdir :initarg :libdir :initform nil)
    (libname :initarg :libname :initform nil)
-   (absolute :initform nil :initarg :absolute :reader absolute-p)))
+   (absolute :initform *absolute-paths-as-default*
+            :initarg :absolute :reader absolute-p)))
 
 
 (defun split-path (path)
-  (labels ((split (path)
-            (unless (zerop (length path))
-              (let ((slash (position #\/ path)))
-                (if slash
-                    (cons (subseq path 0 slash) (split (subseq path (1+ slash))))
-                  (list path))))))
-    (if (and (not (zerop (length path))) (char= (char path 0) #\/))
-       (cons :absolute (split (subseq path 1)))
-      (cons :relative (split path)))))
-
+  (when path
+    (labels ((split (path)
+              (unless (zerop (length path))
+                (let ((slash (position #\/ path)))
+                  (if slash
+                      (cons (subseq path 0 slash) (split (subseq path (1+ slash))))
+                      (list path))))))
+      (if (and (not (zerop (length path))) (char= (char path 0) #\/))
+         (cons :absolute (split (subseq path 1)))
+       (cons :relative (split path))))))
+  
 
 (defmethod component-pathname ((lib library))
-  (make-pathname :type *dso-extension*
-                :name (or (slot-value lib 'libname) (component-name lib))
-                :directory (split-path (slot-value lib 'libdir))))
+  (or
+   (when (slot-value lib 'libname)
+     (let ((filename (format nil "~A~A" (namestring (make-pathname :directory (split-path (slot-value lib 'libdir)))) (slot-value lib 'libname))))
+       (when (probe-file filename)
+        (pathname filename))))
+   
+   (make-pathname
+    :type *dso-extension*
+    :name (or (slot-value lib 'libname) (component-name lib))
+    :directory (split-path (slot-value lib 'libdir)))))
 
 (defmethod perform ((o load-op) (lib library))
   (load-shared-object (component-pathname lib) (absolute-p lib)))