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