1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: libraries.cl
6 ;;;; Purpose: UFFI source to load foreign libraries
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: libraries.cl,v 1.7 2002/04/01 00:52:07 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
22 (defvar *loaded-libraries* nil
23 "List of foreign libraries loaded. Used to prevent reloading a library")
25 (defun default-foreign-library-type ()
26 "Returns string naming default library type for platform"
27 #+(or win32 mswindows) "dll"
31 (defun find-foreign-library (name &key directories type)
32 "Looks for a foreign library. directories can be a single
33 string or a list of strings of candidate directories. Use default
34 library type if type is not specified."
36 (setq type (default-foreign-library-type)))
37 (unless (listp directories)
38 (setq directories (list directories)))
39 (dolist (dir directories)
40 (let ((path (make-pathname :name :type type :directory directory)))
41 (when (probe-file path)
46 (defun load-foreign-library (filename &key module supporting-libraries
48 #+allegro (declare (ignore module supporting-libraries))
49 #+lispworks (declare (ignore supporting-libraries))
50 #+cmu (declare (ignore module))
52 (when (and filename (probe-file filename))
53 (if (pathnamep filename) ;; ensure filename is a string to check if
54 (setq filename (namestring filename))) ; already loaded
56 (if (and (not force-load)
57 (find filename *loaded-libraries* :test #'string-equal))
58 t ;; return T, but don't reload library
60 #+cmu (alien:load-foreign filename
62 (convert-supporting-libraries-to-string
63 supporting-libraries))
64 #+lispworks (fli:register-module module
65 :connection-style :automatic
67 #+allegro (load filename)
69 (push filename *loaded-libraries*)
73 (defun convert-supporting-libraries-to-string (libs)
76 (push (format nil "-l~A" lib) lib-load-list))
77 (nreverse lib-load-list)))