
;; $Id: jl-config.cl,v 1.2 2001/04/02 20:41:19 moltmans Exp $

(in-package :user)

;; SAMPLE FILE with DUMMY values to be customized for each site

(setf jl-here (read-from-string
               (concatenate 
		'string ":" (string-downcase (short-site-name)))))

;; ??? marks places that MUST be customized

;; the following variables have default values that may be changed
;; to suit special situations (such as heavy debugging)
;;(setf javatools.jlinker:*jlinker-verbose* t)
;;(setf javatools.jlinker:*jlinker-debug* t)
;;(setf javatools.jlinker:*jlinker-retry-number* 3)
;;(setf javatools.jlinker:*jlinker-retry-delay*  5)

;; In general, this is a good idea because it avoids user
;; shell profiles when we call Java (after setting up path
;; and CLASSPATH).
(setf javatools.jlinker:*jlinker-unix-vector-p* t)


;; The value of the two variable below is significant ONLY if Lisp 
;; will start Java with (jlinker-init :start-java ...)


;; Expected value of this symbol:
;;  symbol -> The name of a function of at least five (5) optional arguments.
;;            The default value shown below is a function included
;;            with jLinker.  This value can also be replaced with
;;            the name of a suitable user-written function.
;;  other  -> Error
(setf javatools.jlinker:*jlinker-run-java* 'javatools.jlinker::run-java)


;; Expected value of this symbol:
;; string -> Path namestring of Java home directory
;;           jLinker will construct a suitable value for PATH
;;           and for CLASSPATH
;;
;; nil    -> jLinker makes no modifications to PATH or CLASSPATH
;;           User must make sure that the file jlinker.jar is 
;;           visible to Java.
(setf javatools.jlinker:*jlinker-java-home*
  (case jl-here
    (:gray-duck  "c:\\java\\jdk1.3")
    (otherwise   "")
    )
  )


;; The code for javatools.jlinker::run-java is included below as a
;; sample that can be renamed and  modified to satisfy the 
;; requirements of a particular installation.
#|
(defun run-java (&optional debug lport lhost jport jhost &rest more)
  (let* ((op-val #+unix      "java"
                 #+mswindows 
                 (if debug "cmd /c start /wait /b java.exe" "javaw.exe")
                 )
         (class javatools.jlinker::*java-link-base-class*)
         (cmdl (append (list op-val class)
                       (when lport (list "-lport" (format nil "~A" lport)))
                       (when lhost (list "-lhost" lhost))
                       (when jport (list "-jport" (format nil "~A" jport)))
                       (when jhost (list "-jhost" jhost))
                       (when debug (list "-debug"))
                       (mapcar #'(lambda (m) (format nil "~A" m)) more)
                       ))
	 (command 
	  #+mswindows (format nil "~{~A ~}" cmdl)
	  #+unix
	  (if *jlinker-unix-vector-p*
	      (make-array (1+ (length cmdl)) 
			  :initial-contents (cons (car cmdl) cmdl))
	    (format nil "~{~A ~}" cmdl))
	  )
	 (log 
	  #+mswindows (and debug (jlinker-slot :java-out)
			   (concatenate 
			    'string (jlinker-slot :java-out) ".log"))
	  #+unix nil
	  )
	 (elog (when log 
		 (concatenate 'string (jlinker-slot :java-out) "e.log")))
	 (show (if (and debug (null log)) :showna :hide))
	 )
    (set-java-paths)
    (when log (jlinker-slot :java-out :wrap))
    (jcollect-pid
	 command
	 :output log
	 :if-output-exists :supersede
	 :error-output elog
	 :if-error-output-exists :supersede
	 :show-window show
	 :wait nil)))

(defun jcollect-pid (&rest args)
  (multiple-value-bind (rc x pid)
      (apply #'run-shell-command args)
      (declare (ignore x))
      (if pid
	  (jlinker-slot :pid pid)
	rc)))

(defun set-java-paths ()
  (let* ((delim #+mswindows "\\" #+unix "/")
	 (break #+mswindows ";" #+unix ":")
	 (jhome *jlinker-java-home*)
	 class oldcp
	 path)
    (when (and jhome (file-directory-p jhome))
      (when (equal jhome "") (setf jhome "."))
      (setf (sys:getenv "JAVA_HOME") jhome)
      (setf class (sys:getenv "CLASSPATH"))
      (if (or (null class) (equal class ""))
	  (setf class "")
	(setf class (concatenate 'string class break)))
      (or (and (setf oldcp (sys:getenv "CLASSPATH"))
	       (search "jlinker.jar" oldcp))
	  (setf (sys:getenv "CLASSPATH")
		(apply #'concatenate 'string
		       class "." delim break
		       "jlinker.jar" break
		       jhome delim "lib"
		       (when oldcp (list break oldcp))
		       )))
      (or (and (setf path (sys:getenv "PATH"))
	       (search jhome path))
	  (setf (sys:getenv "PATH")
		(concatenate 'string jhome delim "bin" break path))))))
|#




