r2860: *** empty log message ***
[clsql.git] / db-mysql / mysql-loader.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          mysql-loader.sql
6 ;;;; Purpose:       MySQL library loader using UFFI
7 ;;;; Programmers:   Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: mysql-loader.cl,v 1.2 2002/09/26 18:18:38 kevin Exp $
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 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 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :mysql)
21
22 ;;;; Modified by Kevin Rosenberg 
23 ;;;;  - probe potential directories to find library
24 ;;;;  - Changed from CMUCL functions to UFFI to
25 ;;;;      -- prevent library from being loaded multiple times
26 ;;;;      -- support Allegro CL and Lispworks
27
28 (defvar *clsql-mysql-library-filename* 
29   (uffi:find-foreign-library
30    "clsql-mysql"
31    `(,(directory-namestring
32        (translate-logical-pathname 
33         "cl-library:clsql;interfaces;mysql;"))
34      "/usr/lib/clsql/"
35      "/opt/lisp/clsql/db-mysql/"
36      "/home/kevin/debian/src/clsql/db-mysql/")
37    :drive-letters '("C" "D" "E" "F" "G")))
38   
39 (defvar *mysql-library-filename*
40     (cond
41      ((probe-file "/opt/mysql/lib/mysql/libmysqlclient.so")
42       "/opt/mysql/lib/mysql/libmysqlclient.so")
43      ((probe-file "/usr/local/lib/libmysqlclient.so")
44       "/usr/local/lib/libmysqlclient.so")
45      ((probe-file "/usr/lib/libmysqlclient.so")
46       "/usr/lib/libmysqlclient.so")
47      #+(or win32 mswindows) 
48      ((probe-file "c:/mysql/lib/opt/libmysql.dll")
49       "c:/mysql/lib/opt/libmysql.dll")
50      (t
51       (warn "Can't find MySQL client library to load.")))
52   "Location where the MySQL client library is to be found.")
53
54 (defvar *mysql-library-candidate-names*
55     '("libmysqlclient" "libmysql"))
56
57 (defvar *mysql-library-candidate-directories*
58     '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/"))
59
60 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
61
62 (defvar *mysql-supporting-libraries* '("c")
63   "Used only by CMU. List of library flags needed to be passed to ld to
64 load the MySQL client library succesfully.  If this differs at your site,
65 set to the right path before compiling or loading the system.")
66
67 (defvar *mysql-library-loaded* nil
68   "T if foreign library was able to be loaded successfully")
69
70 (defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :mysql)))
71   *mysql-library-loaded*)
72                                       
73 (defmethod clsql-base-sys:database-type-load-foreign ((database-type (eql :mysql)))
74   (let ((mysql-path
75          (uffi:find-foreign-library *mysql-library-candidate-names*
76                                     *mysql-library-candidate-directories*
77                                     :drive-letters
78                                     *mysql-library-candidate-drive-letters*)))
79     ;; zlib required to load mysql on CMUCL Solaris
80     (uffi:load-foreign-library 
81      (uffi:find-foreign-library '("libz" "zlib")
82                                 '("/usr/lib/" "/usr/local/" "/lib/")))
83     (if (and
84          (uffi:load-foreign-library mysql-path
85                                     :module "mysql" 
86                                     :supporting-libraries 
87                                     *mysql-supporting-libraries*)
88          (uffi:load-foreign-library *clsql-mysql-library-filename* 
89                                     :module "clsql-mysql" 
90                                     :supporting-libraries 
91                                     (append *mysql-supporting-libraries*)))
92         (setq *mysql-library-loaded* t)
93       (warn "Unable to load MySQL client library ~A or CLSQL-MySQL library ~A"
94             mysql-path *clsql-mysql-library-filename*))))
95
96
97 (clsql-base-sys:database-type-load-foreign :mysql)
98