r2914: rename .cl files
[clsql.git] / db-mysql / mysql-loader.lisp
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.lisp,v 1.1 2002/09/30 10:19:23 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    `("/usr/lib/clsql/"
32      "/opt/lisp/clsql/db-mysql/"
33      "/home/kevin/debian/src/clsql/db-mysql/")
34    :drive-letters '("C" "D" "E" "F" "G")))
35   
36 (defvar *mysql-library-filename*
37     (cond
38      ((probe-file "/opt/mysql/lib/mysql/libmysqlclient.so")
39       "/opt/mysql/lib/mysql/libmysqlclient.so")
40      ((probe-file "/usr/local/lib/libmysqlclient.so")
41       "/usr/local/lib/libmysqlclient.so")
42      ((probe-file "/usr/lib/libmysqlclient.so")
43       "/usr/lib/libmysqlclient.so")
44      #+(or win32 mswindows) 
45      ((probe-file "c:/mysql/lib/opt/libmysql.dll")
46       "c:/mysql/lib/opt/libmysql.dll")
47      (t
48       (warn "Can't find MySQL client library to load.")))
49   "Location where the MySQL client library is to be found.")
50
51 (defvar *mysql-library-candidate-names*
52     '("libmysqlclient" "libmysql"))
53
54 (defvar *mysql-library-candidate-directories*
55     '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/"))
56
57 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
58
59 (defvar *mysql-supporting-libraries* '("c")
60   "Used only by CMU. List of library flags needed to be passed to ld to
61 load the MySQL client library succesfully.  If this differs at your site,
62 set to the right path before compiling or loading the system.")
63
64 (defvar *mysql-library-loaded* nil
65   "T if foreign library was able to be loaded successfully")
66
67 (defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :mysql)))
68   *mysql-library-loaded*)
69                                       
70 (defmethod clsql-base-sys:database-type-load-foreign ((database-type (eql :mysql)))
71   (let ((mysql-path
72          (uffi:find-foreign-library *mysql-library-candidate-names*
73                                     *mysql-library-candidate-directories*
74                                     :drive-letters
75                                     *mysql-library-candidate-drive-letters*)))
76     ;; zlib required to load mysql on CMUCL Solaris
77     (uffi:load-foreign-library 
78      (uffi:find-foreign-library '("libz" "zlib")
79                                 '("/usr/lib/" "/usr/local/" "/lib/")))
80     (if (and
81          (uffi:load-foreign-library mysql-path
82                                     :module "mysql" 
83                                     :supporting-libraries 
84                                     *mysql-supporting-libraries*)
85          (uffi:load-foreign-library *clsql-mysql-library-filename* 
86                                     :module "clsql-mysql" 
87                                     :supporting-libraries 
88                                     (append *mysql-supporting-libraries*)))
89         (setq *mysql-library-loaded* t)
90       (warn "Unable to load MySQL client library ~A or CLSQL-MySQL library ~A"
91             mysql-path *clsql-mysql-library-filename*))))
92
93
94 (clsql-base-sys:database-type-load-foreign :mysql)
95