init.lisp 4.18 KB
Newer Older
1 2
;; Load GSL
;; Liam Healy Sat Mar  4 2006 - 18:53
3
;; Time-stamp: <2016-11-20 14:46:05CST init.lisp>
4
;;
5
;; Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015, 2016 Liam M. Healy
6 7 8 9 10 11 12 13 14 15 16 17 18 19
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
20

Liam M. Healy's avatar
Liam M. Healy committed
21 22
(in-package :cl-user)

23
(defpackage gsll
24
    (:nicknames :gsl)
25
  (:use :common-lisp :cffi)
26
  (:import-from :grid #:dim0 #:dim1 #:^ #:copy)
Liam M. Healy's avatar
Liam M. Healy committed
27
  (:export #:dim0 #:dim1 #:copy))
28

29 30 31 32 33 34 35 36 37 38
(setf
 antik::*antik-user-shadow-symbols*
 (append antik::*antik-user-shadow-symbols*
	 ;; Where there is a symbol conflict between GSLL and other packages,
	 '(
	   ;; take from the other package
	   grid:row			; GSLL alternate is equivalent
	   grid:column			; GSLL alternate is equivalent
	   iterate:sum ; GSLL histogram function, both pretty obscure
	   iterate:multiply		; GSLL function duplicates '*
Liam M. Healy's avatar
Liam M. Healy committed
39 40 41
	   ;;antik:polar-to-rectangular	; GSLL's doesn't use vectors
	   ;;antik:rectangular-to-polar	; GSLL's doesn't use vectors
	   ;;antik:acceleration
42
	   ;; taken from GSLL
Liam M. Healy's avatar
Liam M. Healy committed
43 44 45 46 47 48
  ;; No actual conflict due to different usage of symbols:
  ;; antik:psi means "pounds per square inch" vs. function #'gsl:psi
  ;; antik:knots means "nautical miles per hour" vs. function #'gsl:knots
  ;; antik:acceleration refers to the time derivative of velocity vs. object 'gsl:acceleration.
  ;; si units symbol-macro vs. GSLL's sine integral.
  ;;(:shadowing-import-from :antik #:psi #:knots #:si)
49 50 51 52
	   gsll::iterate ; conflict with iterate:iterate, but iterate:iter is a synonym
	   ))
 antik::*antik-user-use-packages*
 (cons '#:gsll antik::*antik-user-use-packages*))
53

54
(antik:make-user-package :antik-user)	; Add the new use package and shadow symbols to :antik-user
55

56 57
(in-package :gsl)

58
#+darwin
59 60 61 62 63 64 65
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun gsl-config (arg)
    "A wrapper for tool `gsl-config'."
    (with-input-from-string
        (s (with-output-to-string (asdf::*verbose-out*)
             (asdf:run-shell-command "gsl-config ~s" arg)))
      (read-line s)
66
      (read-line s)))
Liam M. Healy's avatar
Liam M. Healy committed
67 68 69 70 71 72 73 74
  (defparameter *gsl-libpath*
    (let ((gsl-config-libs (gsl-config "--libs")))
      (when (eql 2 (mismatch gsl-config-libs "-L" :test #'string=))
	(uiop:ensure-directory-pathname
	 (uiop:ensure-absolute-pathname
	  (pathname
	   (subseq gsl-config-libs 2 (position #\space gsl-config-libs)))))))
    "The path to the GSL libraries; gsl-config must return -L result first.")
75
  (defun gsl-config-pathname (pn)
Liam M. Healy's avatar
Liam M. Healy committed
76 77 78
    (namestring (uiop:merge-pathnames* pn *gsl-libpath*))))

#-darwin 				; unneeded other than macosx
79 80
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defun gsl-config-pathname (pn) pn))
81

82
(cffi:define-foreign-library libgslcblas
83
  (:darwin #+ccl #.(ccl:native-translated-namestring
84 85
		    (gsl-config-pathname "libgslcblas.dylib"))
           #-ccl #.(gsl-config-pathname "libgslcblas.dylib"))
86
  (:windows (:or "libgslcblas-0.dll" "cyggslcblas-0.dll"))
87
  (:unix (:or "libgslcblas.so.0" "libgslcblas.so"))
88 89 90 91
  (t (:default "libgslcblas")))
   
(cffi:use-foreign-library libgslcblas)

92 93 94 95 96 97
;; When calling libgsl from emacs built for windows and slime, and
;; using clisp built for cygwin, we have to load lapack/cygblas.dll
;; before loading cyggsl-0.dll
#+(and clisp cygwin)
(cffi:load-foreign-library "/lib/lapack/cygblas.dll")

98
(cffi:define-foreign-library libgsl
99
  (:darwin #+ccl #.(ccl:native-translated-namestring
100 101
                     (gsl-config-pathname "libgsl.dylib"))
           #-ccl #.(gsl-config-pathname "libgsl.dylib"))
102
  (:windows (:or "libgsl-0.dll" "cyggsl-0.dll"))
103
  (:unix (:or "libgsl.so.19" "libgsl.so.0" "libgsl.so"))
104 105 106
  (t (:default "libgsl")))
   
(cffi:use-foreign-library libgsl)