675014f50c1f8734b2ef7373939c07fabbe02c56
[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$
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 (in-package #:mysql)
20
21 ;;;; Modified by Kevin Rosenberg 
22 ;;;;  - probe potential directories to find library
23 ;;;;  - Changed from CMUCL functions to UFFI to
24 ;;;;      -- prevent library from being loaded multiple times
25 ;;;;      -- support Allegro CL and Lispworks
26
27 (defparameter *clsql-mysql-library-path* 
28   (uffi:find-foreign-library
29    "mysql"
30    `(,(make-pathname :directory (pathname-directory *load-truename*))
31      "/usr/lib/clsql/"
32      "/sw/lib/clsql/"
33      "/home/kevin/debian/src/clsql/db-mysql/")
34    :drive-letters '("C")))
35
36 (defparameter *libz-library-path* 
37   (uffi:find-foreign-library
38    '("libz" "zlib")
39    `(,(make-pathname :directory (pathname-directory *load-truename*))
40       "/usr/lib/"
41       "/sw/lib/"
42       "/usr/local/lib/"
43        "/home/kevin/debian/src/clsql/db-mysql/"
44        "/mysql/lib/dll32/"
45        "/mysql/lib/opt/")
46    :drive-letters '("C")))
47   
48 (defvar *mysql-library-candidate-names*
49     '("libmysqlclient" "libmysql"))
50
51 (defparameter *mysql-library-candidate-directories*
52     `(,(pathname-directory *load-pathname*)
53       "/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/usr/local/lib/mysql/" "/usr/lib/mysql/" "/mysql/lib/opt/" "/sw/lib/mysql/"))
54
55 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
56
57 (defvar *mysql-supporting-libraries* '("c")
58   "Used only by CMU. List of library flags needed to be passed to ld to
59 load the MySQL client library succesfully.  If this differs at your site,
60 set to the right path before compiling or loading the system.")
61
62 (defvar *mysql-library-loaded* nil
63   "T if foreign library was able to be loaded successfully")
64
65 (defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :mysql)))
66   *mysql-library-loaded*)
67                                       
68 (defmethod clsql-base-sys:database-type-load-foreign ((database-type (eql :mysql)))
69   (let ((mysql-path
70          (uffi:find-foreign-library *mysql-library-candidate-names*
71                                     *mysql-library-candidate-directories*
72                                     :drive-letters
73                                     *mysql-library-candidate-drive-letters*)))
74     (unless (probe-file mysql-path)
75       (error "Can't find mysql client library to load"))
76     (uffi:load-foreign-library *libz-library-path*) 
77     (uffi:load-foreign-library mysql-path
78                                :module "mysql" 
79                                :supporting-libraries 
80                                *mysql-supporting-libraries*)
81     (uffi:load-foreign-library *clsql-mysql-library-path* 
82                                :module "clsql-mysql" 
83                                :supporting-libraries 
84                                (append *mysql-supporting-libraries*)))
85   (setq *mysql-library-loaded* t))
86
87
88 (clsql-base-sys:database-type-load-foreign :mysql)
89