;; File: make-kpml4-lw41-image.lisp
;; John:Bremen:November 1999.
;; KPML4 update: June 2002
;;
;; Example image creation script for KPML under Harlequin
;; Lispworks 4.1 for Windows. 
;;
;; ======================================================================
;; ALL PLACES FOR SETTING PATHS ARE GROUPED TOGETHER IMMEDIATELY
;; FOLLOWING THESE COMMENTS
;; ======================================================================

;; ----------------------------------------------------------------------
;; Using this image maker can replace
;; all individual file and path settings typically required in
;; KPML-INSTALLATION.lisp. It also allows setting of the paths
;; required for a default Loom installation. Loom 2.0, 2.1, 3.0
;; must have been installed and compiled first. The paths are
;; otherwise set and used in the file kpml top directory
;; file 'selected-kpml-kr.lisp'.
;; ----------------------------------------------------------------------

;; This file should be used as the init parameter for a direct call
;; to Harlequin Lispworks of the form:
;;
;;    <path to>\LispWorks41\lispworks-4100 -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. 
;;
;; The first place where user interaction is required is to answer
;; the question: 
;; (1) Compile KPML? 
;;    If this is a fresh installation and an image is being made, and
;;    if it can be assumed that KPML is going to compile without difficulties
;;    (which any freshly downloaded release files should do), then one
;;    can also simply compile KPML at this stage too: 
;;    In this case and only this case answer: 'y' followed by carriage return.
;;
;;    Otherwise 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.  
;;
;; (2) Then the next question
;;     should appear: Load KPML? 
;;     which should always be answered `y' followed by
;;     a carriage return. Loading then proceeds as normal... 
;;
;; (3) 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 "E:\\systems\\kpml\\kpml4\\"))
(defparameter *ROOT-OF-RESOURCES* (pathname "E:\\systems\\kpml\\Resources\\"))

;; *** CHANGE THE FOLLOWING IF LOOM IS BEING USED AS KR ...          ***
(defvar *loom-pathname-default*
  (pathname "E:/systems/Loom/loom4.0/"))

;; *** 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 "E:\\systems\\kpml\\binaries\\lww41-winXP-l4\\"))

;; *** SET THIS TO WHERE THE CLIM FONT PATCHES FOR LWW4.1 ARE TO BE  ***
;; *** FOUND (IF AT ALL)                                             ***

(defvar *LWW41-PRIVATE-PATCHES* 
    ;; ignore if you do not know what this is for...
    ;; if you are using an uptodate Lispworks, probably not necessary...
    nil
  ;; "C:\\Programme\\Harlequin\\Lispworks41\\clim-fonts-lww41\\"
  )

;; *** CHANGE THE FOLLOWING FOR WHERE THE IMAGE WILL BE PUT...       ***
(defvar *IMAGE-DESTINATION* 
  "E:\\systems\\kpml\\Images\\kpml4-image-lw41")

;; *********************************************************************
;; NO MORE CHANGES REQUIRED FOR REGULAR USE...

;;; ----------------------------------------------------------------------

(format *terminal-io* 
        "~2% *** KPML IMAGE CONSTRUCTION SCRIPT FOR PC-LISPWORKS 4.1. *** ~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....
;; ----------------------------------------------------------------------

(load-all-patches)
(require "clim")

;; *** ESSENTIAL FONT SUPPORT PATCHES ***
;; newly provided by Harlequin at Sept 1999 for LW4.1.17.

(defvar *clim-lww4-1-17-font-support*
  '(("clim-standalone-fat-strings.fsl" . :clim-standalone)
    ("clim-standalone-device-fonts.fsl" . :clim-standalone)
    ("clim-win32-fat-strings.fsl" . :clim-win32)
    ("clim-win32-device-fonts.fsl" . :clim-win32)))

(when *lww41-private-patches*
  (loop for (patch-file . patch-label) in *clim-lww4-1-17-font-support*
      do 
	(scm:require-private-patch 
	 (merge-pathnames  
	  *lww41-private-patches* patch-file)
	 patch-label)))

;;; ----------------------------------------------------------------------

(push :dump-kpml *features*)
(load (merge-pathnames "KPML-INSTALLATION.lisp" *root-of-kpml*))

;; ----------------------------------------------------------------------
;; Load any patches that need to be loaded into this KPML image by
;; hand... This is only for development and when you know what and
;; why you are doing it!!
;;
;; *** 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%")

(setf kpml::*kpml-creation-timestamp* (kpml::time-stamp))
(kpml::set-penman-feature :language kpml::all_languages)
(kpml::set-penman-feature :site (common-lisp:short-site-name))

;;; ...

(hcl:save-image *image-destination*
		:gc t 
                :environment t
		
		;; In theory, the following could also be given as a restart
		;; function, but Lispworks then gets in a tangle because it 
		;; has not started multiprocessing in time... So, you have to
		;; start up KPML by hand in the normal fashion 
		;; (i.e., (kpml-i::startup) or, indeed,
		;; (kpml::kpml-restart-function). The problem is that
		;; some of these do not return, so that you have to
		;; set up the right function calls to run when the
		;; stack frames are started, or something like that...
#||
		:restart-function
                  #'(lambda ()
		      (progn
			(lispworks-tools::start-lispworks)
			(mp::initialize-multiprocessing)
			(kpml::kpml-restart-function)))

||#
                )


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

;;; ----------------------------------------------------------------------
;;; Done...

(quit)



