1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: libraries.cl
6 ;;;; Purpose: UFFI source to load foreign libraries
7 ;;;; Programmers: Kevin M. Rosenberg and John DeSoi
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: libraries.cl,v 1.1 2002/08/02 14:39:12 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
15 ;;;; UFFI users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
17 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
18 ;;;; *************************************************************************
20 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
23 (defvar *loaded-libraries* nil
24 "List of foreign libraries loaded. Used to prevent reloading a library")
26 ;in MCL calling this more than once for the same library does not do anything
27 (defmacro load-foreign-library (filename &key module supporting-libraries)
28 (declare (ignore module supporting-libraries))
29 `(eval-when (:compile-toplevel :load-toplevel :execute)
30 (when (ccl:add-to-shared-library-search-path ,filename t)
31 (pushnew ,filename *loaded-libraries*))))
33 ;; Copied directly from main source without MCL specializations
34 (defun find-foreign-library (names directories &key types drive-letters)
35 "Looks for a foreign library. directories can be a single
36 string or a list of strings of candidate directories. Use default
37 library type if type is not specified."
39 (setq types (default-foreign-library-type)))
41 (setq types (list types)))
43 (setq names (list names)))
44 (unless (listp directories)
45 (setq directories (list directories)))
46 #+(or win32 mswindows)
47 (unless (listp drive-letters)
48 (setq drive-letters (list drive-letters)))
49 #-(or win32 mswindows)
50 (setq drive-letters '(nil))
51 (dolist (drive-letter drive-letters)
53 (dolist (dir directories)
55 (let ((path (make-pathname
57 #+lispworks (when drive-letter drive-letter)
59 #-lispworks (when drive-letter drive-letter)
65 (pathname-directory dir))
70 (parse-namestring dir)))))))
71 (when (probe-file path)
72 (return-from find-foreign-library path)))))))
76 ;; Copied directly from main source without MCL specializations
77 (defun default-foreign-library-type ()
78 "Returns string naming default library type for platform"
79 #+(or win32 mswindows) "dll"
80 #-(or win32 mswindows) "so")