;;; CMAIL-CFG					-*-Emacs-Lisp-*-

(if (boundp 'LISPDIR)
    (let ((dir (expand-file-name LISPDIR)))
      (if (and (file-directory-p dir)
	       (not (member dir load-path)))
	  (setq load-path (cons dir load-path)))))

;; load path-util for add-path and module-installed-p, but don't add
;; apel to the load path yet for apel installation check.
(let ((load-path (cons (expand-file-name "apel") load-path)))
  (load "path-util"))

;; delete the current directory if it is in the load path so that the apel
;; attached the cmail distribution will not affect the pcustom search.
(setq load-path (delete (expand-file-name ".")
			(mapcar 'expand-file-name load-path)))

;; add emu directory to the load path to find pcustom.
(add-path "emu" 'append)

;; if pcustom module is found, assume a compatible version of apel has
;; been installed. What we need is to add the installed apel path to
;; the load-path. Otherwise, we will use the attached version of apel
;; for cmail byte compile. We also install the attached apel to the
;; system.
(if (module-installed-p 'pcustom)
    (add-path "apel" 'append)
  (setq load-path (cons (expand-file-name "apel") load-path))
  (setq install-apel t))

;; Finally add the current directory to the load path.
(setq load-path (cons "." load-path))

(require 'emu)

;; now load install.el. add the attached apel directory at the
;; front of load path, and then load install.el. This must be done
;; after pcustom check is completed, because install.el will load
;; pcustom library from the apel package.
(let ((load-path (cons (expand-file-name "apel") load-path)))
  (load "install"))

;; Only when the emacs version is SEMI compatible, add semi directory
;; to load-path to find mime-setup.el.
(if (not (or running-emacs-18 running-emacs-19))
    (add-path "semi" 'append)
  (add-path "mel" 'append))

;;; @ Please specify prefix of install directory.
;;;

;; Please specify install path prefix.
;; If it is omitted, shared directory (maybe /usr/local is used).
(defvar PREFIX install-prefix)
;;(setq PREFIX "~/")

;; Please specify install path prefix for binaries.
(defvar EXEC_PREFIX
  (if (or running-emacs-18 running-xemacs)
      (expand-file-name "../../.." exec-directory)
    (expand-file-name "../../../.." exec-directory)
    ))

;; Please specify cmail prefix [optional]
;;
;; Set CMAIL_PREFIX to a directory name where cmail modules will be
;; installed, which is relative to the LISPDIR directory.  With the
;; following lines of code, it will be set to "cmail" when cmail is
;; NOT already installed in the LISPDIR directory, and the version of
;; emacs supports subdirectory search by default.
;; (e.g. subdirs.el/normal-top-level-add-subdirs-to-load-path).  An
;; empty string is used otherwise. (That means cmail will be installed
;; in LISPDIR, instead of a sub-directory.)

(defvar LISPDIR (install-detect-elisp-directory PREFIX))
(setq CMAIL_PREFIX
      (if (and (null (module-installed-p 'cmail (list LISPDIR)))
	       (or (featurep 'xemacs)
		   (and (fboundp 'set-buffer-multibyte)
			(subrp (symbol-function 'set-buffer-multibyte)))))
	  "cmail"
	""))

;;; @ optional settings
;;;

(setq CMAIL_DIR (expand-file-name CMAIL_PREFIX LISPDIR))

(defvar INFODIR (expand-file-name "info" PREFIX))
(defvar CMAIL_ICON_DIR (expand-file-name "icon" CMAIL_DIR))

;;; CMAIL-CFG ends here
