;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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: libnum-config.lsh,v 1.2 2005/11/06 21:48:08 profshadoko Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(when (not libnum-config-loaded)

  (defparameter libnum-libgsl ())
  (defparameter libnum-libgslcblas ())

  ;; find gsl library
  (cond
   ;; gsl-lib was already defined, don't touch it
   (libnum-libgsl t)
   ;; look for dynamic libgsl.so installed through packages
   ((progn
      (let* ((lib (find-shared-library "libgsl")))
        (when (and lib (filep lib)) (setq libnum-libgsl lib)))))
   ;; look for static libgsl.a installed through packages
   ((progn
      (let* ((lib (find-static-library "libgsl")))
        (when (and lib (filep lib)) (setq libnum-libgsl lib)))))
   ;; couldn't find it, complain loudly.
   (t (printf "Neither the libgsl.so not libgsl.a could be found\n")
      (printf "You should install the libgsl and libgsl-devel\n")
      (printf "packages from your operating system distribution.\n")
      (printf "Alternatively, you can download GSL from\n")
      (printf "http://sources.redhat.com/gsl, compile it,\n")
      (printf "and install it by hand (e.g. in /usr/local/lib).\n")
      (printf "If you have installed GSL and still get this message, type:\n")
      (printf "    (defparameter libnum-libgsl \"yourgsllibrary\")\n")
      (printf "before loading this file.\n")      
      (printf "(see %s for more details)\n" file-being-loaded)
      (error "cannot configure GSL")))

  
  ;; find the gslcblas library
  (cond
   ;; libnum-libgslcblas was already defined, don't touch it
   (libnum-libgslcblas t)
   ;; look for dynamic libgslcblas.so installed through packages
   ((progn
      (let* ((lib (find-shared-library "libgslcblas")))
        (when (and lib (filep lib)) (setq libnum-libgslcblas lib)))))
   ;; look for static libgslcblas.a installed through packages
   ((progn
      (let* ((lib (find-static-library "libgslcblas")))
        (when (and lib (filep lib)) (setq libnum-libgslcblas lib)))))
   ;; couldn't find it, complain loudly.
   (t (printf "neither the libgslcblas.so not libgslcblas.a could be found\n")
      (printf "You should install the libgsl and libgsl-devel")
      (printf "packages from your operating system distribution.\n")
      (printf "Alternatively, you can download GSL from\n")
      (printf "http://sources.redhat.com/gsl, compile it,\n")
      (printf "and install it by hand (e.g. in /usr/local/lib).\n")
      (printf "If you have installed GSL and still get this message, type:\n")
`      (printf "    (defparameter libnum-libgslcblas \"yourgslcblaslibrary\")\n")
      (printf "before loading this file.\n")      
      (printf "(see %s for more details)\n" file-being-loaded)
      (error "cannot configure GSLCBLAS") ) ) 
  
  
  ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (libload "libc/shell")
  
  (let ((dlist c-include-path)
        (hlist ()))
    (while (and dlist (not hlist))
      (setq hlist (glob ".*\\.h" (ls (concat-fname (car dlist) "gsl"))))
      (setq dlist (cdr dlist)))
    (if (not hlist)
        (progn
          (printf "Could not find GSL include files\n") ;
          (printf "please make sure you have installed the\n")
          (printf "GSL development packages\n")
          (error "cannot find GSL header files"))
      (setq libnum-gsl-headers
            (cons 'progn
                  (append
                   '((cpheader "#include <gsl/gsl_math.h>"))
                   '((cpheader "#include <gsl/gsl_math.h>"))
                   (all ((x hlist))
                     (when (not (regex-match "gsl_wavelet.*" x)) ;; incompatible with fft
                       (list 'cpheader (sprintf "#include <gsl/%s>" x)) ) ) ) ) ) ) ) 

  (defparameter libnum-cmacros 
    '(progn
       (cpheader "#define IDX2GSL_VECTOR(_idxv_,_gslv_,_type_) _gslv_.data = IDX_PTR(_idxv_,_type_); _gslv_.size = _idxv_->dim[0]; _gslv_.stride = _idxv_->mod[0]; _gslv_.block = NULL; _gslv_.owner=0")
       (cpheader "#define IDX2GSL_VECTOR_COMPLEX(_idxv_,_gslv_,_type_) _gslv_.data = IDX_PTR(_idxv_,_type_); _gslv_.size = _idxv_->dim[0]; _gslv_.stride = _idxv_->mod[0]/2; _gslv_.block = NULL; _gslv_.owner=0")
       (cpheader "#define IDX2GSL_MATRIX(_idxv_,_gslv_,_type_) _gslv_.data = IDX_PTR(_idxv_,_type_); _gslv_.size1 = _idxv_->dim[0]; _gslv_.size2 = _idxv_->dim[1]; _gslv_.tda = _idxv_->mod[0]; _gslv_.block = NULL; _gslv_.owner=0")
       (cpheader "#define IDX2GSL_MATRIX_COMPLEX(_idxv_,_gslv_,_type_) _gslv_.data = IDX_PTR(_idxv_,_type_); _gslv_.size1 = _idxv_->dim[0]; _gslv_.size2 = _idxv_->dim[1]; _gslv_.tda = _idxv_->mod[0]/2; _gslv_.block = NULL; _gslv_.owner=0")
       (cpheader "#define IDX2GSL_PERMUTATION(_idxv_,_gslv_) _gslv_.data = (size_t *)IDX_PTR(_idxv_,int); _gslv_.size = _idxv_->dim[0]")
      ()))

  (defparameter libnum-config-loaded 1)
  )

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