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