Automated commit for debian release 6.7.2-1
[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 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
16
17 (in-package #:clsql-uffi)
18
19 (defun find-and-load-foreign-library (filenames &key module supporting-libraries (errorp t))
20   "Attempt to load a foreign library. This will search for any of the filenames, as
21 well as any of the filenames in any of the clsql:*foreign-library-search-paths*"
22   (setq filenames (if (listp filenames) filenames (list filenames)))
23
24   (flet ((try-load (testpath)
25            (handler-case
26                (uffi:load-foreign-library testpath
27                                           :module module
28                                           :supporting-libraries supporting-libraries)
29              (error nil)))) ;(c) (warn "~A" c) nil))))
30     (or
31      (loop for type in (uffi:foreign-library-types)
32            thereis
33            (loop for name in filenames
34                  for pn = (make-pathname :name name :type type)
35                  thereis (or
36                           (try-load pn)
37                           (loop for search-path in clsql:*foreign-library-search-paths*
38                                 thereis (try-load (merge-pathnames pn search-path))))))
39      (when errorp
40        (error "Couldn't load foreign librar~@P ~{~S~^, ~}. (searched ~S: ~S)"
41               (length filenames) filenames
42               'clsql:*foreign-library-search-paths* clsql:*foreign-library-search-paths*)))))
43
44 ;; searches clsql_uffi64 to accomodate both 32-bit and 64-bit libraries on same system
45 (defvar *clsql-uffi-library-filenames*
46   `(,@(when (> most-positive-fixnum (expt 2 32)) (list "clsql_uffi64"))
47     "clsql_uffi"))
48
49 (defvar *clsql-uffi-supporting-libraries* '("c")
50   "Used only by CMU. List of library flags needed to be passed to ld to
51 load the MySQL client library succesfully.  If this differs at your site,
52 set to the right path before compiling or loading the system.")