;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  9/9/2002       adapted from gsl-config.lsh  by jhuangfu
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar alsa-libname "libasound")
(defvar alsa-version 0.9.0rc1)
(defvar alsa-libalsa ())
(defvar alsa-libalsa-loaded ())
(defvar alsa-cpheader-cmd ())


(when (not alsa-libalsa-loaded)

  
  ;; find  library
  (cond
   ;; alsa-libalsa was already defined, don't touch it
   (alsa-libalsa t)
   ;; look for dynamic libopenalsa.so installed
   ((progn
      (let* ((lib (find-shared-library alsa-libname 
                                       '(".so" ".so.1" ".so.2" ".so.3"))))
        (when (and lib (filep lib))
          (setq alsa-libalsa lib)))))
   ;; look for static libopenalsa.a installed
   ((progn
      (let* ((lib (find-static-library alsa-libname)))
        (when (and lib (filep lib)) 
          (setq alsa-libalsa lib)))))
   ;; couldn't find it, complain loudly.
   (t (printf "neither the libasound.so nor libasound.a could be found\n")
      (printf "You can download alsa from\n")
      (printf "http://www.alsa-project.org\n")
      (printf "compile it, and install it\n")
      (printf "in standard paths (e.g. in /usr/local/lib) so that I can find it.\n")
      (printf "If you have installed Alsa and still get this message, please do\n")
      (printf "(defparameter alsa-libalsa \"youralsalibrary\") before loading this file\n")
      (printf "(see %s for more details)\n" file-being-loaded)
      (error "cannot configure alsa")))
  
  (setq alsa-cpheader-cmd
        '(progn
           (cpheader "#include <alsa/asoundlib.h>")
           ))
  
  ;; load libraries
  ;; THIS IS COMPLETELY WRONG
  ;; THE ALSA INTERFACE SHOULD USE DHC-MAKE-WITH-LIBS INSTEAD OF THIS HACK
  (mod-load alsa-libalsa)
  (setq alsa-libalsa-loaded t)
)