;;; NICOLA-DDSKK-MK --- installer for NICOLA-DDSKK  -*-emacs-lisp-*-

;;; Code:

(require 'cl)
(require 'advice)

(defun config-nicola-ddskk ()
  (let (prefix lisp-dir version-specific-lisp-dir)
    (and (setq prefix (car command-line-args-left))
	 (or (string-equal "NONE" prefix)
	     (defvar PREFIX prefix)))
    (setq command-line-args-left (cdr command-line-args-left))
    (and (setq lisp-dir (car command-line-args-left))
	 (or (string-equal "NONE" lisp-dir)
	     (defvar LISPDIR lisp-dir)))
    (setq command-line-args-left (cdr command-line-args-left))
    (and (setq version-specific-lisp-dir (car command-line-args-left))
	 (or (string-equal "NONE" version-specific-lisp-dir)
	     (progn
	       (defvar VERSION_SPECIFIC_LISPDIR version-specific-lisp-dir)
	       (princ (format "VERSION_SPECIFIC_LISPDIR=%s\n"
			      VERSION_SPECIFIC_LISPDIR)))))
    (setq command-line-args-left (cdr command-line-args-left))
    (load-file "NICOLA-DDSKK-CFG")
    (load-file "NICOLA-DDSKK-ELS")
    (autoload 'browse-url "browse-url" nil t)
    (autoload 'browse-url-netscape "browse-url" nil t)
    (autoload 'update-buffer-local-frame-params "ccc")
    (autoload 'set-buffer-local-cursor-color "ccc")
    (autoload 'skk-cursor-current-color "skk-cursor")
    (princ (format "PREFIX=%s
VERSION_SPECIFIC_LISPDIR=%s\n" PREFIX VERSION_SPECIFIC_LISPDIR))))

(defun compile-nicola-ddskk ()
  (condition-case nil (load "bytecomp-runtime.el") (error))
  (config-nicola-ddskk)
  (require 'skk-isearch)
  (require 'skk-macs)
  (require 'skk-autoloads)
  (require 'skk)
  (nicola-ddskk-generate-autoloads)
  (compile-elisp-modules nicola-ddskk-modules "."))

(defun install-nicola-ddskk ()
  (config-nicola-ddskk)
  (install-elisp-modules nicola-ddskk-modules "./" NICOLA-DDSKK_DIR)
  (delete-file "./nicola-ddskk-autoloads.el"))

(defun config-nicola-ddskk-package ()
  (require 'cus-load)
  (let (package-dir)
    (and (setq package-dir (car command-line-args-left))
	 (or (string= "NONE" package-dir)
	     (defvar PACKAGEDIR package-dir)))
    (setq command-line-args-left (cdr command-line-args-left))
    (load-file "NICOLA-DDSKK-CFG")
    (load-file "NICOLA-DDSKK-ELS")
    (setq nicola-ddskk-modules (append nicola-ddskk-modules
			       '(auto-autoloads custom-load)))
    (princ (format "PACKAGEDIR=%s\n" PACKAGEDIR))))

(defun compile-nicola-ddskk-package ()
  (config-nicola-ddskk-package)

  (install-update-package-files "nicola-ddskk" ".")

  (require 'nicola-ddskk-autoloads "./auto-autoloads.el")
  (require 'skk-isearch)
  (require 'skk-macs)
  (require 'skk-autoloads)
  (require 'skk)
  (compile-elisp-modules nicola-ddskk-modules "."))

(defun install-nicola-ddskk-package ()
  (config-nicola-ddskk-package)
  (install-elisp-modules nicola-ddskk-modules
			 "./"
			 (expand-file-name NICOLA-DDSKK_PREFIX
					   (expand-file-name "lisp"
							     PACKAGEDIR)))
  (delete-file "./auto-autoloads.el")
  (delete-file "./custom-load.el"))

(defun nicola-ddskk-generate-autoloads ()
  "Generate nicola-ddskk-autoload.el."
  (require 'autoload)
  (let ((buf (get-buffer-create " *nicola-ddskk-generate-autoloads*"))
       sort-min standard-output)
    (save-excursion
      (set-buffer buf)
      (setq buffer-file-name "nicola-ddskk-autoloads.el")
      (erase-buffer)
      (insert ";; -*- coding: iso-2022-7bit -*-\n")
      (message "%s" nicola-ddskk-modules)
	(dolist (module nicola-ddskk-modules)
	  (let ((file (expand-file-name (format "%s.el" module)
					default-directory)))
	    (and (file-exists-p file)
		 (message "%s" file)
		 (generate-file-autoloads file))))
	(goto-char (point-max))
	(insert "
\(provide 'nicola-ddskk-autoloads)
")
	(let ((coding-system-for-write 'iso-2022-7bit))
	  (write-region (point-min) (point-max)
			"nicola-ddskk-autoloads.el" nil nil))
	(kill-buffer buf))))

;;; NICOLA-DDSKK-MK ends here
