+(eval-when (:compile-toplevel :load-toplevel :execute)
+ #+common-lisp-controller (require 'uffi)
+ #-common-lisp-controller (asdf:operate 'asdf:load-op 'uffi))
+
+(defvar *library-file-dir* (append (pathname-directory *load-truename*)
+ (list "db-mysql")))
+
+(defclass clsql-mysql-source-file (c-source-file)
+ ())
+
+(defmethod output-files ((o compile-op) (c clsql-mysql-source-file))
+ (let* ((library-file-type
+ (funcall (intern (symbol-name'#:default-foreign-library-type)
+ (symbol-name '#:uffi))))
+ (found (some #'(lambda (dir)
+ (probe-file (make-pathname :directory dir
+ :name (component-name c)
+ :type library-file-type)))
+ '((:absolute "usr" "lib" "clsql")))))
+ (list (if found
+ found
+ (make-pathname :name (component-name c)
+ :type library-file-type
+ :directory *library-file-dir*)))))
+
+(defmethod perform ((o load-op) (c clsql-mysql-source-file))
+ nil) ;;; library will be loaded by a loader file
+
+(defmethod operation-done-p ((o load-op) (c clsql-mysql-source-file))
+ nil)
+
+(defmethod perform ((o compile-op) (c clsql-mysql-source-file))
+ (unless (zerop (run-shell-command
+ "cd ~A; make"
+ (namestring (make-pathname :name nil
+ :type nil
+ :directory *library-file-dir*))))
+ (error 'operation-error :component c :operation o)))
+
+(defmethod operation-done-p ((o compile-op) (c clsql-mysql-source-file))
+ (let ((lib (make-pathname :defaults (component-pathname c)
+ :type (uffi:default-foreign-library-type))))
+ (and (probe-file lib)
+ (> (file-write-date lib) (file-write-date (component-pathname c))))))
+