r8153: initial changes to make installable with asdf-install
[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 (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 (defparameter *clsql-mysql-library-path* 
29   (uffi:find-foreign-library
30    "mysql"
31    `(,(make-pathname :directory (pathname-directory *load-truename*))
32      "/usr/lib/clsql/"
33      "/sw/lib/clsql/"
34      "/home/kevin/debian/src/clsql/db-mysql/")
35    :drive-letters '("C")))
36
37 (defparameter *libz-library-path* 
38   (uffi:find-foreign-library
39    '("libz" "zlib")
40    `(,(make-pathname :directory (pathname-directory *load-truename*))
41       "/usr/lib/"
42       "/sw/lib/"
43       "/usr/local/lib/"
44       "/home/kevin/debian/src/clsql/db-mysql/"
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