;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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
;;;
;;;  HTK 3.1 usually merely generates a HTKLib.linux.a under $HTK/HTKLib
;;;
;;;  under architectures other than Linux, the lib file will be different,
;;;  e.g. HTKLib.sun4_solaris.a, or HTKLib.sgi.a. in these cases, the user
;;;  needs to change the htk-libname defined below accordingly.
;;;
;;;  if the user doesn't copy the lib file to standard paths (e.g. 
;;;  /usr/local/lib), the user has to tell me where this file is.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar htk-libname "HTKLib")
(defvar htk-version 3.1)
(defvar htk-lib ())
(defvar htk-cpheader-cmd ())


(when (not htk-libhtk-loaded)

  ;; find  library
  (cond
   ;; htk-lib was already defined, don't touch it
   (htk-libhtk t)
   ;; look for dynamic libhtk.so installed
   ((progn
      (let* ((lib (find-shared-library  "libhtk")))
	(when (and lib (filep lib)) (setq htk-libhtk lib)))))
   ;; look for static libhtk.a installed
   ((progn
      (let* ((lib (find-static-library  "libhtk")))
	(when (and lib (filep lib)) (setq htk-libhtk lib)))))
   ;; look for HTKLib.XXX.a for manually installed 
   ((progn 
      (let* ((lib (find-static-library htk-libname 
                                       '(".linux.a" ".sgi.a" "sun4_solaris.a"))))
	(when (and lib (filep lib)) (setq htk-libhtk lib)))))
   ;; couldn't find it, complain loudly.
   (t (printf "neither the HTKLib.XXXX.so nor HTKLib.XXXX.a could be found\n")
      (printf "You can download htk from\n")
      (printf "http://htk.eng.cam.ac.uk/, compile it, and install the HTKLib.XXXX.a\n")
      (printf "file in standard paths (e.g. in /usr/local/lib) so that I can find it.\n")
      (printf "If you would rather leave the file where it is, do\n")
      (printf "(defparameter htk-libhtk \"yourhtklibrary\") before loading this file\n")      
      (printf "(see %s for more details)\n" file-being-loaded)
      (error "cannot configure htk")))


  ;; load libraries
  ;; THIS IS COMPLETELY WRONG
  ;; THE INTERFACE SHOULD USE DHC-MAKE-WITH-LIBS INSTEAD OF THIS HACK

  (mod-load  htk-libhtk)
  (setq htk-libhtk-loaded t)

  (setq htk-cpheader-cmd
    '(progn
       (cpheader "#include <htk/HShell.h>")
       (cpheader "#include <htk/HMem.h>")
       (cpheader "#include <htk/HMath.h>")
       (cpheader "#include <htk/HSigP.h>")
       (cpheader "#include <htk/HAudio.h>")
       (cpheader "#include <htk/HWave.h>")
       (cpheader "#include <htk/HVQ.h>")
       (cpheader "#include <htk/HParm.h>")
       (cpheader "#include <htk/HLabel.h>")
       (cpheader "#include <htk/HModel.h>")
       (cpheader "#include <htk/HTrain.h>")
       (cpheader "#include <htk/HUtil.h>") 
       (cpheader "#include <htk/esignal.h>")
       (cpheader "#include <htk/HDict.h>")
       (cpheader "#include <htk/HAdapt.h>")
       (cpheader "#include <htk/HFB.h>")
       (cpheader "#include <htk/HLM.h>")
       (cpheader "#include <htk/HNet.h>")
       (cpheader "#include <htk/HRec.h>")
       (cpheader "#include <htk/HGraf.h>") 
       (cpheader "#include <htk/strarr.h>") ) )
)