;;; CMAIL-OPTIONS-MK				-*-Emacs-Lisp-*-

;;; Commentary:

;; DON'T EDIT THIS FILE; edit CMAIL-OPTIONS-CFG instead.
;;
;; This file is based on APEL-MK

;;; Code:

;;; Configuration variables.

;; Set these four variables in "CMAIL-OPTIONS-CFG" or in "Makefile".

;; This variable will be detected automatically.
(defvar PREFIX nil)

;; This variable will be detected automatically using PREFIX.
;; v18: (no standard site-lisp directory)
;; Emacs 19.28 and earlier: "PREFIX/lib/emacs/site-lisp"
;; Emacs 19.29 and later: "PREFIX/share/emacs/site-lisp"
(defvar LISPDIR nil)

;; This variable will be detected automatically using PREFIX.
;; Emacs 19.31 and later: "PREFIX/share/emacs/VERSION/site-lisp"
(defvar VERSION_SPECIFIC_LISPDIR nil)

;; This variable will be detected automatically.
;; XEmacs 21.0 and later: "/usr/local/lib/xemacs/xemacs-packages"
(defvar PACKAGEDIR nil)

;; Install CMAIL_OPTIONS modules to "cmail/options" subdirectory.
(defvar CMAIL_OPTIONS_PREFIX "cmail/options")

;; The directories where CMAIL_OPTIONS modules will be installed.
;; These two variables will be generated from other variables above.
(defvar CMAIL_OPTIONS_DIR nil)	     ; LISPDIR/CMAIL_OPTIONS_PREFIX

;;; Configure, Compile, and Install.

(defun config-cmail-options ()
  ;; Override everything you want.
  (load-file "CMAIL-OPTIONS-CFG")
  ;; Override PREFIX, LISPDIR, and VERSION_SPECIFIC_LISPDIR with
  ;; command-line options.
  (let (prefix lisp-dir version-specific-lisp-dir)
    (and (setq prefix
	       ;; Avoid using `pop'.
	       ;; (pop command-line-args-left)
	       (prog1
		   (car command-line-args-left)
		 (setq command-line-args-left
		       (cdr command-line-args-left))))
	 (or (string-equal "NONE" prefix)
	     (setq PREFIX prefix)))
    (and (setq lisp-dir
	       ;; Avoid using `pop'.
	       ;; (pop command-line-args-left)
	       (prog1
		   (car command-line-args-left)
		 (setq command-line-args-left
		       (cdr command-line-args-left))))
	 (or (string-equal "NONE" lisp-dir)
	     (setq LISPDIR lisp-dir)))
    (and (setq version-specific-lisp-dir
	       ;; Avoid using `pop'.
	       ;; (pop command-line-args-left)
	       (prog1
		   (car command-line-args-left)
		 (setq command-line-args-left
		       (cdr command-line-args-left))))
	 (or (string-equal "NONE" version-specific-lisp-dir)
	     (setq VERSION_SPECIFIC_LISPDIR version-specific-lisp-dir))))

  (setq load-path (cons (expand-file-name "..") load-path))
  (setq load-path (cons (expand-file-name "../apel") load-path))
  (require 'path-util)
  (require 'install)

  ;; Import `cmail-options-modules' and `cmail-options-compilable'.
  (load-file "CMAIL-OPTIONS-ELS")

  ;; Set PREFIX, LISPDIR, and VERSION_SPECIFIC_LISPDIR if not set yet.
  (or PREFIX
      (setq PREFIX install-prefix))
  (or LISPDIR
      (setq LISPDIR (install-detect-elisp-directory PREFIX)))
  (or VERSION_SPECIFIC_LISPDIR
      (setq VERSION_SPECIFIC_LISPDIR
	    (install-detect-elisp-directory PREFIX nil 'version-specific)))
  ;; The directories where CMAIL_OPTIONS will be installed.
  (or CMAIL_OPTIONS_DIR
      (setq CMAIL_OPTIONS_DIR (expand-file-name CMAIL_OPTIONS_PREFIX LISPDIR)))
  (princ (format "\nLISPDIR=%s\n" LISPDIR))
  (princ (format "VERSION_SPECIFIC_LISPDIR=%s\n" VERSION_SPECIFIC_LISPDIR)))

(defun compile-cmail-options ()
  (config-cmail-options)
  (compile-elisp-modules cmail-options-compilables "."))

(defun install-cmail-options (&optional just-print)
  (config-cmail-options)
  ;; Use cmail-use-multi-highlight.elc to check if it has been
  ;; compiled.  If not compiled yet, most likely we should not use
  ;; del-elc flag.
  (let ((del-elc (file-exists-p "cmail-use-multi-highlight.elc")))
    (install-elisp-modules cmail-options-modules "."
			   CMAIL_OPTIONS_DIR just-print del-elc)))

(defun what-where-cmail-options ()
  (config-cmail-options)
  (install-cmail-options 'just-print))

;;; CMAIL-OPTIONS-MK ends here
