r1709: *** 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.6 2002/03/31 23:45:34 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 default-foreign-library-type ()
26   "Returns string naming default library type for platform"
27   #+(or win32 mswindows) "dll"
28   #+freebsd "a"
29   #+linux "so")
30
31   
32 (defun load-foreign-library (filename &key module supporting-libraries
33                                            force-load)
34   #+allegro (declare (ignore module supporting-libraries))
35   #+lispworks  (declare (ignore supporting-libraries))
36   #+cmu (declare (ignore module))
37   
38   (when (and filename (probe-file filename))
39     (if (pathnamep filename)    ;; ensure filename is a string to check if
40         (setq filename (namestring filename)))  ; already loaded
41
42     (if (and (not force-load)
43              (find filename *loaded-libraries* :test #'string-equal))
44         t ;; return T, but don't reload library
45       (progn
46         #+cmu (alien:load-foreign filename 
47                                   :libraries
48                                   (convert-supporting-libraries-to-string
49                                    supporting-libraries))
50         #+lispworks (fli:register-module module 
51                                          :connection-style :automatic 
52                                          :real-name filename)
53         #+allegro (load filename)
54         
55         (push filename *loaded-libraries*)
56         t)))
57   )
58
59 (defun convert-supporting-libraries-to-string (libs)
60   (let (lib-load-list)
61     (dolist (lib libs)
62       (push (format nil "-l~A" lib) lib-load-list))
63     (nreverse lib-load-list)))