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.18 2002/05/27 17:19:30 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 (uffi:find-foreign-library
31 `(,(directory-namestring
32 (translate-logical-pathname
33 "CL-LIBRARY:clsql;interfaces;mysql;"))
34 "/usr/share/common-lisp/source/clsql/interfaces/mysql/")
35 :drive-letters '("C" "D" "E" "F" "G")))
37 (defvar *mysql-library-filename*
39 ((probe-file "/opt/mysql/lib/mysql/libmysqlclient.so")
40 "/opt/mysql/lib/mysql/libmysqlclient.so")
41 ((probe-file "/usr/local/lib/libmysqlclient.so")
42 "/usr/local/lib/libmysqlclient.so")
43 ((probe-file "/usr/lib/libmysqlclient.so")
44 "/usr/lib/libmysqlclient.so")
45 #+(or win32 mswindows)
46 ((probe-file "c:/mysql/lib/opt/libmysql.dll")
47 "c:/mysql/lib/opt/libmysql.dll")
49 (warn "Can't find MySQL client library to load.")))
50 "Location where the MySQL client library is to be found.")
52 (defvar *mysql-library-candidate-names*
53 '("libmysqlclient" "libmysql"))
55 (defvar *mysql-library-candidate-directories*
56 '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/"))
58 (defvar *mysql-library-candidate-drive-letters* '("C" "D" "E"))
60 (defvar *mysql-supporting-libraries* '("c")
61 "Used only by CMU. List of library flags needed to be passed to ld to
62 load the MySQL client library succesfully. If this differs at your site,
63 set to the right path before compiling or loading the system.")
65 (defvar *mysql-library-loaded* nil
66 "T if foreign library was able to be loaded successfully")
68 (defmethod clsql-base-sys:database-type-library-loaded ((database-type (eql :mysql)))
69 *mysql-library-loaded*)
71 (defmethod clsql-base-sys:database-type-load-foreign ((database-type (eql :mysql)))
73 (uffi:find-foreign-library *mysql-library-candidate-names*
74 *mysql-library-candidate-directories*
76 *mysql-library-candidate-drive-letters*)))
77 ;; zlib required to load mysql on CMUCL Solaris
78 (uffi:load-foreign-library
79 (uffi:find-foreign-library '("libz" "zlib")
80 '("/usr/lib/" "/usr/local/" "/lib/")))
82 (uffi:load-foreign-library mysql-path
85 *mysql-supporting-libraries*)
86 (uffi:load-foreign-library *clsql-mysql-library-filename*
89 (append *mysql-supporting-libraries*)))
90 (setq *mysql-library-loaded* t)
91 (warn "Unable to load MySQL client library ~A or CLSQL-MySQL library ~A"
92 mysql-path *clsql-mysql-library-filename*))))
95 (clsql-base-sys:database-type-load-foreign :mysql)