(in-package "COMMON-LISP-USER")
;;;*************************************************************************
;;;      -----  NO USER CHANGES REQUIRED IN THIS FILE ------
;;;*************************************************************************
;;; 
;;; compile-kpml.lisp ()
;;;
;;;  compile the core KOMET-PENMAN system
;;;  with NO options on multilinguality...
;;;  (modelled on compile/load-penman)
;;;  Feb95: updated for ANSI packages compatibility (John)
;;;  Mar97: minor updates for KPML 1.1 restructuring (John)
;;;  Jun98: references to packages USER and LISP removed (John)
;;;  Sep02: the increasing number of startup files pushed to a subdir (John)
;;;  Dec04: KR loading made an option during compilation/installation,
;;;         when not loaded, the KR API-stubbs are loaded instead so
;;;         that we have no undefined functions (John)
;;;*************************************************************************

;;; ----------------------------------------------------------
;;; Find out what variety of KPML is to be compiled...
;;; ----------------------------------------------------------

(load 
 (merge-pathnames 
  "system-flag-defs.lisp" 
  (merge-pathnames "Processes/startup/" *root-of-kpml*)))

(configure-kpml-compilation *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*))

;;; ----------------------------------------------------------
;;; We also use the portable defsystem facility, so make sure
;;; this is around too... 
;;; 2.1 
;;;
;;; Note, since this has been hacked slightly
;;; for ease of use with new Lisp minor versions that might
;;; be released, we now *always* load the revised version
;;; distributed with KPML at this point...
;;; ----------------------------------------------------------

(without-redefinition-warnings
 (format t "~%;;; Loading conditionalized defsystem facility...")
 (load 
  (merge-pathnames 
   "cond-defsystem"
   (merge-pathnames "Processes/startup/" *root-of-kpml*))))

;;; ----------------------------------------------------------
;;; We've still got code that is relying on CLISP (the portable
;;; Loop facility made redundent by Common Lisp), so make sure
;;; it is there...
;;; ----------------------------------------------------------

(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 
 (format t "~%;;; Loading CLISP module (still)...")
 (load 
  (merge-pathnames 
   "clisp-defsys.lisp"
   (merge-pathnames "clisp/" *root-of-kpml*)))
 (make:operate-on-system 'clisp :compile)
 (make:operate-on-system 'clisp :load))

;; Following must be defined within the selected kpml kr definition...
;; (defvar *kpml-kr-system-name* nil). This should be a mk::system name
;; for loading up below.
(when *load-kr-system?*
  (load *kpml-kr-loader*))

;;; ----------------------------------------------------------
;;; Load the KPML defsys...
;;; ----------------------------------------------------------

(load 
 (merge-pathnames 
  "kpml-defsys.lisp"
  (merge-pathnames "Processes/startup/" *root-of-kpml*)))

(defparameter *penman-pathname-default* *root-of-kpml*)

;;; ----------------------------------------------------------
;;; Compile the KPML system...
;;; ----------------------------------------------------------

(make:operate-on-system 'kpml
			:compile :force *non-incremental-compile?*)

;; 3.0
(when *acl-ipc-required?*
  (make:operate-on-system 'kpml-acl-ipc
			  :compile :force *non-incremental-compile?*))

;; 4.0
(when *cl-xml-required?*
  (make:operate-on-system 'kpml-xml
			  :compile :force *non-incremental-compile?*))


(when *stratification?* 
      (make:operate-on-system 'stratification  :compile 
			  :force *non-incremental-compile?*)
      )

(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 'cross-platform-compatibility :load
			       :compile-during-load nil
			       :load-source-instead-of-binary t)
       (cond (*new-style-interface?*
	      (make:operate-on-system 'kpml-clim
				      :compile 
				      :force *non-incremental-compile?*)
	      (when *stratification?*
		(make:operate-on-system 'ui-stratification
					:compile 
					:force *non-incremental-compile?*)))
	     (T
	      ;; 3.0 if you land here, you are in trouble!
	      (make:operate-on-system 'old-kpml-interface
				      :compile 
				      :force *non-incremental-compile?*))))
      (t
       (make:operate-on-system 'kpml-interface-stubb :compile 
			       :force *non-incremental-compile?*)))

;;; ----------------------------------------------------------------------
;;; compile the relevant KPML-KR interface functions as defined within
;;; the selected kpml-kr file.
;;; 4.0 make this depend on the selected configuration option...
;;; ----------------------------------------------------------------------

(if *load-kr-system?*
    (case *kpml-kr-system-name*
	  (kpml-loom
	   (check-package-present "LOOM")
	   (make:operate-on-system  'kpml-loom
				    :compile :force *non-incremental-compile?*)
	   (make:operate-on-system 'kpml-loom-speedup
				   :compile :force *non-incremental-compile?*))
	  (t
	   (make:operate-on-system  *kpml-kr-system-name* 
				    :compile :force *non-incremental-compile?*)))
  (make:operate-on-system 'kpml-null-kr
			  :compile :force *non-incremental-compile?*))

;;; ======================================================================
;;; KPML system is now compiled... Needs to be loaded before being
;;; used however... Report on how things look...

(when (and (find-package "KPML")
	   (find-symbol "DESCRIBE-KPML" "KPML"))
  (funcall (find-symbol "DESCRIBE-KPML" "KPML")
	   t  "KPML INITIAL COMPILATION STATE AS FOLLOWS ..."))



