(in-package "COMMON-LISP-USER")
;;;*************************************************************************
;;;      -----  NO USER CHANGES REQUIRED IN THIS FILE ------
;;;*************************************************************************
;;; 
;;; load-kpml.lisp ()
;;;
;;;  load the core KOMET-PENMAN system
;;;  with options on multilinguality...
;;;  (modelled on compile/load-penman)
;;;
;;;  Feb95: updated for ANSI packages compatibility (John)
;;;  Jun98: references to packages USER and LISP removed (John)
;;;  Oct01: there was a parameter missing in a conditionalization
;;;         for ACL4.3, added (3.2+). Only was a problem if the
;;;         flag *acl-ipc-required?* is set, as it would be for
;;;         Allegro Lisp (John)
;;;
;;;*************************************************************************

;;; ----------------------------------------------------------------------
;;; Ascertain what KPML variations are required...
;;; ----------------------------------------------------------------------

(load (merge-pathnames "system-flag-defs.lisp" *root-of-kpml*))
(configure-kpml *questions-during-configuration*)

;;; ----------------------------------------------------------------------
;;; Set the binaries root to the KPML root unless a user has specified
;;; otherwise...
;;; ----------------------------------------------------------------------

(unless (and (boundp '*kpml-binaries-root*)
	     *kpml-binaries-root*)
  (setf *kpml-binaries-root* *root-of-kpml*))

;;; ----------------------------------------------------------------------
;;; Make sure the modified defsystem facility is available...
;;; ----------------------------------------------------------------------

(without-redefinition-warnings
 (format t "~%;;; Loading conditionalized defsystem facility...")
 (load (merge-pathnames "cond-defsystem" *root-of-kpml*)))

;;; ----------------------------------------------------------------------
;;; Following file when loaded must define the selected kpml kr definition
;;; in *kpml-kr-system-name*. This should be a mk::system name
;;; that is used for loading up below....
;;; ----------------------------------------------------------------------

(load *kpml-kr-loader*)

;;; ----------------------------------------------------------------------
;;; Get CLISP in...
;;; ----------------------------------------------------------------------

(unless (find-package "CLISP") 
  (make-package 'clisp)
  (shadow '(assq bind memq neq puthash tab) 'clisp)
  #-LCL4.2(use-package '(common-lisp) 'clisp))

(without-redefinition-warnings
 (load (merge-pathnames "clisp-defsys.lisp" *root-of-kpml*))
 (make:operate-on-system 'clisp :load
			 :compile-during-load nil
			 :load-source-instead-of-binary nil))

;;; ----------------------------------------------------------------------
;;; Load the KPML defsys and KPML package definition...
;;; ----------------------------------------------------------------------

(load (merge-pathnames "kpml-defsys.lisp" *root-of-kpml*))

;;; ----------------------------------------------------------------------
;;; Copy some values to the old PENMAN package variables just in
;;; case someone attempts to use them...
;;; ----------------------------------------------------------------------

(defvar *penman-pathname-default* *root-of-kpml*)

;;; ----------------------------------------------------------------------
;;; Load the KPML system... this is the main work... and is divided into
;;; the core system (essentially ML-Penman with very very very many additions),
;;; an optional stratification module for doing genre and stuff (not part
;;; of the standard release), the user interface, and the particular
;;; KR system and KPML-KR interface selected.
;;; ----------------------------------------------------------------------

;;;
;;; Core system...
;;;
(make:operate-on-system 'kpml :load
			   :compile-during-load nil
			   :load-source-instead-of-binary nil)

;; 3.0, 3.2+
(when *acl-ipc-required?*
  (make:operate-on-system 'kpml-acl-ipc :load
			  :compile-during-load nil
			  :load-source-instead-of-binary nil))

;;; Stratification extensions if required (these extend/alter existing
;;; functions so we don't report redefinitions...)
;;;
(when *stratification?*
  (without-redefinition-warnings
   (make:operate-on-system 'stratification  :load
			   :compile-during-load nil
			   :load-source-instead-of-binary nil)))

;;;
;;; UI...
;;;
(cond (*window-interface-required?*
       (unless (find-package "KPML-I") 
	 (make-package "KPML-I")	;  :use '(clim-lisp clim)
	 (shadow #+Lucid '(lcl::warning)
		 #-Lucid '(common-lisp:warning)
		 "KPML-I"))
       (make:operate-on-system  'kpml-clim
				:load
				:compile-during-load nil
				:load-source-instead-of-binary nil)
       (when *stratification?*
	 (make:operate-on-system 'ui-stratification
				 :load 
				 :compile-during-load nil
				 :load-source-instead-of-binary nil))
       
       #+LCL ;; don't know if anyone needs this anymore, but...
       (:version-case (":LCL")
		      ("4.1"
		       (make:operate-on-system 
			'lucid-4-1-clim-hack :load
			:compile-during-load nil
			:load-source-instead-of-binary t)))
       )
      (T
       (make:operate-on-system 'kpml-interface-stubb :load
			       :compile-during-load nil
			       :load-source-instead-of-binary nil)))

;;;
;;; Selected KR system...
;;;
(when *kpml-kr-system-name*
  (make:operate-on-system  *kpml-kr-system-name* 
			   :load 
			   :compile-during-load nil
			   :load-source-instead-of-binary nil))

;;; ----------------------------------------------------------------------
;;; KPML is now there, we can now load linguistic resources if required...
;;; default is just the upper model but this can only be done after the
;;; KR system requested is there!!!
;;;
(cond (*load-linguistic-resources?* 
       (push :semantics kpml::*loading-saving-profile*)
       (let ((kpml::*editing-protocol* nil)) ;; deactivate for configuration
	 (kpml::load-linguistic-resources *kpml-initial-resources*))
       (pop kpml::*loading-saving-profile*))
      (t
       (let ((kpml::*editing-protocol* nil)) ;; deactivate for configuration
	 (when *upper-model-required?*
	       (kpml::load-semantics 
		(pathname
		 (concatenate 'string 
			      (namestring *root-of-resources*)
			      (string *kpml-general-resources*) 
			      (string kpml::*directory-delimiter*))))
	       (kpml::kb-initializations))
	 (when *inquiry-impls-required?*
	       (kpml::load-inquiry-implementations 
		*kpml-general-resources*)))))

;;;================================================================
;;; The KPML system is now installed... Report this in the version
;;; name of the penman-features-record, in *features*, and finally
;;; load any outstanding patches. *Kpml-version* is kept
;;; up to date in systemic-networks/variables.lisp.

(in-package "KPML")

#-lispworks
(unless (common-lisp:short-site-name)
  (setf (common-lisp:short-site-name) 
	(if (getenv "HOST")
	    (getenv "HOST")
	  "unknown")))

(when (boundp '*penman-features*)
  (set-penman-feature :version *kpml-version*)
  (set-penman-feature :site (common-lisp:short-site-name))
  (set-penman-feature :language kpml::all_languages))
(push *kpml-version* *features*)

(when *stratification?*
  (kpml::set-penman-feature 
   :version (kpml::experimental-version 
	     (kpml::get-penman-feature :version)))
  (push (kpml::experimental-version kpml::*kpml-version*) *features*))

;;; ----------------------------------------------------------------------
;;; Load any patches and site specifics that are to be found...
;;; ----------------------------------------------------------------------

(kpml::load-kpml-patches)
(load (merge-pathnames "site-specifics.lisp" common-lisp-user::*root-of-kpml*)
      :if-does-not-exist nil)

;;; ----------------------------------------------------------------------
;;; And do a last reconfiguration if there is a configuration file to
;;; be found...
;;; ----------------------------------------------------------------------

(kpml::load-kpml-configuration-file)

;;; ----------------------------------------------------------------------
;;; Report what we've got so far...
;;; ----------------------------------------------------------------------

(describe-kpml t "KPML LOADED AS FOLLOWS ...")

;;;==================================================================
;;; After doing the above, we can make an image in the normal
;;; time-honored way... This can be done for Lucid and Allegro Common Lisp
;;; by calling the function (kpml::make-kpml-image "file-name").
;;;
;;; ... Enjoy ...

