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

(libload "dh-compile")

(defvar cblas-useintel ())
(defvar cblas-libcblas ())

(cond
 ;; cblas-lib was already defined
 (cblas-libcblas t)
 ;; look for Intel cblas libraries
 ((progn 
    (let* ((lib1 (find-shared-library "libmkl"))
	   (lib2 (find-shared-library "libguide.so")))
      (when (and lib1 lib2 (filep lib1) (filep lib2)) 
	(setq cblas-useintel t)
	(setq cblas-libcblas (list lib1 lib2))))))
 ;; look for libgslcblas installed through packages
 ((progn 
    (let* ((lib (find-shared-library "libgslcblas")))
      (when (and lib (filep lib)) 
	(setq cblas-useintel ())
	(setq cblas-libcblas (list lib))))))
 ;; look for libcblas installed through packages
 ((progn 
    (let* ((lib (find-shared-library "libcblas")))
      (setq cblas-useintel ())
      (when (and lib (filep lib)) (setq cblas-libcblas (list lib))))))
 ;; couldn't find it, complain loudly.
 (t (printf "I could not find libgslcblas, nor libcblas.\n")
    (printf "I could not find the Intel cblas libraries either.\n")
    (printf "(libmkl.so and libguide.so)\n")
    (printf "You should install the GSL package [Gnu Scientific Library]\n")
    (printf "(found in the gsl package on Red Hat Linux and libgsl0,\n")
    (printf "libgsl0-devel, and gsl on Mandrake).\n")
    (printf "For maximum performance on Intel CPU, you may want\n")
    (printf "to install the (commercial) Math Kernel Library from Intel\n")
    (printf "[http://www.intel.com/support/performancetools/libraries/mkl/linuxindex.htm]\n")
    (printf "If you have installed CBLAS and still get this message, please do\n")
    (printf "(defparameter cblas-libcblas (list \"yourcblaslibrary\")) before loading this file\n")      
    (printf "(see %s for more details)\n" file-being-loaded)
    (error "cannot configure CBLAS")))


