;; Example image creation script for KPML under Harlequin
;; Lispworks for Windows.
;; 
;; File: make-kpml-lw-image.lisp
;; John:Stirling:April-May 1998.

;; This file should be used as the init parameter for a direct call
;; to Harlequin Lispworks of the form:
;;
;;    <path to>\LispWorks\lispworks.exe -init <path to>\<this file> 
;;
;; started from a DOS prompt. There are several variables that should
;; be changed for any particular local installation. These are marked
;; below. It is sometime difficult for the poor system to find the
;; both this file and the Lispwork image simultaneously, so one way
;; is to call Lispworks from the directory where this file is.
;;
;; ----------------------------------------------------------------------
;; INSTRUCTIONS FOR USE...
;;
;; The startup dialog must be answered as usual
;; but in a DOS-style interaction popup window. It appears that
;; nothing appears in this DOS-style window until at least a 
;; carriage return has been entered. So, to get going, TYPE
;; A CARRIAGE RETURN CHARACTER... 
;;
;; The first place where user interaction is required is to answer
;; the question: Compile KPML? 
;; KPML should already have been compiled in order to check that
;; it is working, so we should not recompile it here (answer `n' 
;; followed by a carriage return.  Then the next question
;; should appear: Load KPML? which should be answered `y' followed by
;; a carriage return. Loading then proceeds as normal... The safest
;; answers to the configuration questions are as always: 
;;       y to load clim interface,
;;       n to load linguistic resources,
;;       y to load upper model,
;;       n to load general inquiry implementations.
;; If things are in this file have been localized appropriately, it
;; should run through until an image is saved without further interaction.
;; The final image for an empty KPML image occupies around 32Mbyte.
;;
;; ----------------------------------------------------------------------
;;;
(in-package "COMMON-LISP-USER")

;; *** CHANGE THE FOLLOWING TWO PATHNAMES FOR THE LOCAL SITE... ***
(defparameter *root-of-kpml* (pathname "C:\\kpml21b\\kpml-2.1b\\"))
(defparameter *root-of-resources* (pathname "C:\\Eigene Dateien\\Resources\\"))

;; *** THE FOLLOWING MUST ONLY BE SET IF THE KPML BINARIES ARE BEING ***
;; *** KEPT IN A DIFFERENT PLACE TO THE SOURCE FILES. THIS IS NOT    ***
;; *** THE CASE UNLESS YOU HAVE EXPLICITLY ORGANIZED THIS TO BE DONE ***
;; *** LOCALLY.
(defparameter *kpml-binaries-root* 
          (pathname "C:\\KPML-BINARIES\\LISPWORKS40\\"))

;; A Lisp listener is only brought up at this stage if user input is required.
;; Unfortunately, any output before this is sent to /etc/blackhole (joke).
;; So, here we force Lispworks to bring up a lisp listener so that we
;; can read the instructions that follow...
(read-char *query-io*)

(format *terminal-io* 
        "~2% *** KPML IMAGE CONSTRUCTION SCRIPT FOR PC-LISPWORKS. *** ~2%")

(format *terminal-io* 
        "~2% *** PROCEEDING TO UPDATE LISPWORKS and LOAD CLIM... *** ~2%")

;; First load everything that is necessary (e.g., Lisp patches,
;; CLIM, KPML, etc....
;; *** CHANGE THE FOLLOWING IF LISPWORKS LIVES SOMEWHERE DIFFERENT... ***
(load "c:\\Programme\\Harlequin\\LispWorks\\pcwin32-ext-pen.fsl")
(require "CLIM")

(format *terminal-io* 
        "~2% *** LISPWORKS UPDATED... PROCEEDING TO LOAD KPML.... *** ~2%")

;; Following does the work of loading KPML and the KR system that KPML
;; is setup to use...
(load (merge-pathnames "KPML-INSTALLATION.lisp" *root-of-kpml*))

;; ----------------------------------------------------------------------
;; Load any patches that need to be loaded into this KPML image by
;; hand...
;;
;; *** CHANGE THE FOLLOWING PATHNAME TO POINT TO WHERE CURRENT PATCHES ***
;; *** ARE KEPT...                                                     ***
(defvar *kpml-temp-patch-dir* nil)

;; *** CHANGE THE FOLLOWING TO NAME THE CURRENT ADDITIONAL PATCHES ***
(defvar *kpml-temp-patch-list* nil)

(loop for patch-file in *kpml-temp-patch-list*
      do (load (merge-pathnames *kpml-temp-patch-dir* patch-file)))

;; All done. If there is anything else that is required here, add it in.
;; For example, loading linguistic resources, etc... (see hardcopy 
;; KPML documentation for how to load resources etc. from Lisp:
;; e.g., (kpml::load-linguistic-resources :english)

;; *** KPML is now loaded, add further actions as required here. ***

;; Then make the image... perhaps with a different name and in a 
;; different place, as desired.
(format *terminal-io* 
        "~2% *** KPML NOW LOADED. PROCEEDING TO SAVE IMAGE... *** ~2%")
(hcl:save-image "C:\\tmp\\kpml-image-lw40")

;; (Note, any desired changing of package has to be done in the
;;; restart function not here...)

;; In order to set a restart function for the image (i.e., a function that
;; is called automatically on firing up the image) an additional parameter
;; to save-image such as
;;
;;      :restart-function #'kpml::kpml-restart-function)
;;
;; needs to be given. This standard KPML function brings up the window
;; interface (unless the image is called with -nowindow flag), loads installed
;; patches, etc. However, IT DOES NOT YET WORK FOR HARLEQUIN LISPWORKS since
;; Lispworks appears to want to call the function
;; BEFORE CLIM-compatible streams, etc. have been created,  causing
;; it to crash during initialization. I need first to work out
;; how to insist that basic window support already exists when
;; the KPML restart function runs. For now,  the function
;; call can be issued by hand when the Lisp Listener comes up
;; (kpml::kpml-restart-function) if required.

;; Done.
(lispworks:quit)



