r1555: *** empty log message ***
[uffi.git] / src / libraries.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          libraries.cl
6 ;;;; Purpose:       UFFI source to load foreign libraries
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: libraries.cl,v 1.3 2002/03/14 21:03:12 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
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 ;;;; *************************************************************************
18
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :uffi)
21
22 (defvar *loaded-libraries* nil
23   "List of foreign libraries loaded. Used to prevent reloading a library")
24
25 (defun load-foreign-library (filename &key module supporting-libraries)
26   #+allegro (declare (ignore module supporting-libraries))
27   #+lispworks  (declare (ignore supporting-libraries))
28   #+cmu (declare (ignore module))
29   
30   (when (and filename (probe-file filename))
31     (if (find filename *loaded-libraries* :test #'string-equal)
32         t ;; return T, but don't reload library
33       (progn
34         #+cmu (alien:load-foreign filename 
35                                   :libraries
36                                   (convert-supporting-libraries-to-string
37                                    supporting-libraries))
38         #+lispworks (fli:register-module module 
39                                          :connection-style :automatic 
40                                          :real-name filename)
41         #+allegro (load filename)
42         
43         (push filename *loaded-libraries*))))
44   )
45
46 (defun convert-supporting-libraries-to-string (libs)
47   (let (lib-load-list)
48     (dolist (lib libs)
49       (push (format nil "-l~A" lib) lib-load-list))
50     (nreverse lib-load-list)))