r10575: 09 Jun 2005 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / uffi / clsql-uffi-loader.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:     clsql-uffi-loader.sql
6 ;;;; Purpose:  Library loader using CLSQL UFFI helper library
7 ;;;; Author:   Kevin M. Rosenberg
8 ;;;; Created:  Mar 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL 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 (in-package #:clsql-uffi)
20
21 (defun find-and-load-foreign-library (filenames &key module supporting-libraries (errorp t))
22   (setq filenames (if (listp filenames) filenames (list filenames)))
23   (or (loop for type in (uffi:foreign-library-types)
24             for suffix = (make-pathname :type type)
25             thereis (loop for filename in filenames
26                           thereis (handler-case
27                                     (uffi:load-foreign-library (merge-pathnames filename suffix)
28                                                                :module module
29                                                                :supporting-libraries supporting-libraries)
30                                     (error (c)
31                                       (warn "~A" c)
32                                       nil))))
33       (when errorp
34         (error "Couldn't load foreign librar~@P ~{~S~^, ~}."
35                (length filenames) filenames))))
36
37 (defvar *clsql-uffi-library-filenames*
38     (list #+(or 64bit x86-64) (make-pathname :name "uffi64"
39                                              :directory clsql-uffi-system::*library-file-dir*)
40           #+(or 64bit x86-64) "uffi64"
41           (make-pathname :name "uffi"
42                          :directory clsql-uffi-system::*library-file-dir*)
43           "uffi"))
44
45 (defvar *clsql-uffi-supporting-libraries* '("c")
46   "Used only by CMU. List of library flags needed to be passed to ld to
47 load the MySQL client library succesfully.  If this differs at your site,
48 set to the right path before compiling or loading the system.")
49
50 (defvar *uffi-library-loaded* nil
51   "T if foreign library was able to be loaded successfully")
52
53 (defun load-uffi-foreign-library ()
54   (find-and-load-foreign-library *clsql-uffi-library-filenames*
55                                  :module "clsql-uffi" 
56                                  :supporting-libraries 
57                                  *clsql-uffi-supporting-libraries*)
58   (setq *uffi-library-loaded* t))
59
60 (load-uffi-foreign-library)
61