;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; 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 2 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, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: lapack-config.lsh,v 1.3 2005/05/09 01:21:57 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "dh-compile")
(libload "libc/fortran")

;; set FORTRAN libraries
(defvar lapack-libfortran fortran-libs)    
(defvar lapack-liblapack ())
(defvar lapack-cflags ())

;; find lapack library
(cond
 ;; lapack-lib was already defined
 (lapack-liblapack t)
 ;; look for lapack_XXX.a for manually installed LAPACK
 ;; look for dynamic libblas.so installed through packages
 ;; but only if the fortran libs are non static
 ((when (not fortran-libs-static-p)
    (let* ((lib (find-shared-library "liblapack")))
      (when (and lib (filep lib)) (setq lapack-liblapack (list lib))))))
 ;; look for static liblapack.a installed through packages
 ((progn
    (let* ((lib (find-static-library "liblapack")))
      (when (and lib (filep lib)) (setq lapack-liblapack (list lib))))))
 ;; look for lapack_XXX.a for manually installed LAPACK
 ((progn
    (let* ((lib (find-static-library 
		 "lapack" '(".a" "_LINUX.a" "_IRIX64.a" "_SUN4SOL2.a"))))
      (when (and lib (filep lib)) (setq lapack-liblapack (list lib))))))
 (t (printf "Neither the liblapack shared library nor the\n")
    (printf "lapack_XXXX.a static libraries could be found.\n")
    (printf "You should install the liblapack and liblapack-devel\n")
    (printf "packages from your operating system distribution.\n")
    (printf "Alternatively, you can download, compile, and install LAPACK by hand.\n")
    (printf "If you have installed LAPACK and still get this message, please do\n")
    (printf "(defparameter lapack-liblapack \"yourlapacklibrary\") before loading this file\n")      
    (printf "(see %s for more details)\n" file-being-loaded)
    (error "cannot configure LAPACK")))


(cond
 ((stringp lapack-cflags) t)
 ((progn (when (= "yes" (getconf "GCC")) (setq lapack-cflags " -w "))))
 (t (printf "WARNING: your C compiler is not GCC, you will see\n")
    (printf "  lots of warnings while compiling the LAPACK/Lush interface\n")
    (printf "  To suppress those warnings, do (defparameter lapack-cflags \" -w \")\n")
    (printf "  [or whatever your compiler's no-warning option is], before\n")
    (printf "  loading this file (see %s for more details).\n" file-being-loaded)))
    
