;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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 python-libname "libpython2.2")
(defvar python-version 2.2)
(defvar python-libpython ())
(defvar python-libpython-loaded ())
(defvar python-cpheader-cmd ())
(defvar Py_UNICODE -int-)


(when (not python-libpython-loaded)
  
  ;; find  library
  (cond
   ;; python-libpython was already defined, don't touch it
   (python-libpython t)
   ;; look for dynamic libopenpython.so installed
   ((progn
      (let* ((lib (find-shared-library python-libname '(".so" ".so.1" ".so.2" ".so.3") )))
	(when (and lib (filep lib)) (setq python-libpython lib)))))
   ;; look for static libopenpython.a installed
   ((progn
      (let* ((lib (find-static-library python-libname )))
	(when (and lib (filep lib)) (setq python-libpython lib)))))
   ;; couldn't find it, complain loudly.
   (t (printf "neither the libpython.so nor libpython.a could be found\n")
      (printf "You can download python from\n")
      (printf "http://www.python.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 python and still get this message, please do\n")
      (printf "(defparameter python-libpython \"yourpythonlibrary\")\n")
      (printf "before loading this file\n")      
      (printf "(see %s for more details)\n" file-being-loaded)
      (error "cannot configure python")))

  (setq python-cpheader-cmd
        '(progn
           (cpheader "#include <python2.2/Python.h>") ))
  
  ;; load libraries
  ;; THIS IS COMPLETELY WRONG **AGAIN**
  ;; THE INTERFACE SHOULD USE DHC-MAKE-WITH-LIBS INSTEAD OF THIS HACK
  ;; AND IN FACT IT DOES NOT WORK WITH A STATIC LIBRARY!!!!!
  (mod-load python-libpython)
  (setq python-libpython-loaded t) )
