;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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: blas-config.lsh,v 1.3 2005/05/09 01:21:56 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

;; set FORTRAN libraries
(defvar blas-libfortran fortran-libs)    
(defvar blas-libblas ())
(defvar blas-cflags ())

;; find blas library
(cond
 ;; blas-lib was already defined, don't touch it
 (blas-libblas t)
 ;; 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 "libblas")))
      (when (and lib (filep lib)) (setq blas-libblas lib)))))
 ;; look for static libblas.a installed through packages
 ((progn
    (let* ((lib (find-static-library "libblas")))
      (when (and lib (filep lib)) (setq blas-libblas lib)))))
 ;; look for blas_XXX.a for manually installed BLAS
 ((progn
    (let* ((lib (find-static-library 
		 "blas" '(".a" "_LINUX.a" "_IRIX64.a" "_SUN4SOL2.a"))))
      (when (and lib (filep lib)) (setq blas-libblas lib)))))
 ;; couldn't find it, complain loudly.
 (t (printf "neither the libblas shared library nor the\n")
    (printf "blas_XXXX.a static library 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 BLAS from\n")
    (printf "http://www.netlib.org/blas, compile it, and install it\n")
    (printf "by hand (e.g. in /usr/local/lib).\n")
    (printf "If you have installed BLAS and still get this message, please do\n")
    (printf "(defparameter blas-libblas \"yourblaslibrary\")\n")
    (printf "before loading this file\n")
    (printf "(see %s for more details)\n" file-being-loaded)
    (error "cannot configure BLAS"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; find the option that suppresses warnings
(cond
 ((stringp blas-cflags) t)
 ((progn (when (= "yes" (getconf "GCC")) (setq blas-cflags " -w "))))
 (t (printf "WARNING: your C compiler is not GCC, you will see\n")
    (printf "  lots of warnings while compiling the BLAS/Lush interface\n")
    (printf "  Suppress these warnings with (defparameter blas-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)))




