1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: mysql-loader.sql
6 ;;;; Purpose: MySQL library loader using UFFI
7 ;;;; Programmers: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: mysql-loader.cl,v 1.7 2002/05/13 21:50:52 kevin Exp $
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
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
28 (defvar *clsql-mysql-library-filename*
29 (translate-logical-pathname
30 #+(or linux unix) "CL-LIBRARY:clsql;interfaces;mysql;clsql-mysql.so"
31 #+(or mswindows win32) "CL-LIBRARY:clsql;interfaces;mysql;clsql-mysql.dll"
34 (defvar *mysql-library-filename*
36 ((probe-file "/opt/mysql/lib/mysql/libmysqlclient.so")
37 "/opt/mysql/lib/mysql/libmysqlclient.so")
38 ((probe-file "/usr/local/lib/libmysqlclient.so")
39 "/usr/local/lib/libmysqlclient.so")
40 ((probe-file "/usr/lib/libmysqlclient.so")
41 "/usr/lib/libmysqlclient.so")
42 #+(or win32 mswindows)
43 ((probe-file "c:/mysql/lib/opt/libmysql.dll")
44 "c:/mysql/lib/opt/libmysql.dll")
46 (warn "Can't find MySQL client library to load.")))
47 "Location where the MySQL client library is to be found.")
49 (defvar *mysql-library-candidate-names*
50 '("libmysqlclient" "libmysql"))
52 (defvar *mysql-library-candidate-directories*
53 '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/"))
55 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
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.")
62 (defvar *mysql-library-loaded* nil
63 "T if foreign library was able to be loaded successfully")
65 (defmethod clsql-sys:database-type-library-loaded ((database-type (eql :mysql)))
66 *mysql-library-loaded*)
68 (defmethod clsql-sys:database-type-load-foreign ((database-type (eql :mysql)))
70 (uffi:find-foreign-library *mysql-library-candidate-names*
71 *mysql-library-candidate-directories*
73 *mysql-library-candidate-drive-letters*)))
74 ;; zlib required to load mysql on CMUCL Solaris
75 (uffi:load-foreign-library
76 (uffi:find-foreign-library '("libz" "zlib")
77 '("/usr/lib/" "/usr/local/" "/lib/")))
80 (uffi:load-foreign-library mysql-path
83 *mysql-supporting-libraries*)
84 (uffi:load-foreign-library *clsql-mysql-library-filename*
87 (append *mysql-supporting-libraries*)))
88 (setq *mysql-library-loaded* t))))
91 (clsql-sys:database-type-load-foreign :mysql)