Source

riece / lisp / COMPILE

;;; -*- Emacs-Lisp -*-

(defvar riece-modules
  (cons 'riece-compat
	(cons (if (featurep 'xemacs)
		  'riece-xemacs
		'riece-emacs)
	      '(riece-globals
		riece-options
		riece-debug
		riece-version
		riece-coding
		riece-complete
		riece-addon-modules
		riece-addon
		riece-ruby
		riece-cache

		riece-mode
		;; riece-identity -+-> riece-channel
		;;                 +-> riece-user
		riece-identity
		riece-channel
		riece-user

		riece-misc
		riece-signal

		;; riece-layout ---> riece-display
		riece-layout
		riece-display
		riece-server

		;; riece-channel -+-> riece-naming
		;; riece-user    -+
		riece-naming
		riece-message

		;; riece-filter calls riece-{handle,000,200,300,400,500}
		riece-filter
		riece-handle
		riece-000
		riece-200
		riece-300
		riece-400
		riece-500

		riece-commands
		riece-irc
		riece))))

(defvar riece-icons
  '("riece-command-quit.xpm"
    "riece-command-join.xpm"
    "riece-command-part.xpm"
    "riece-command-previous-channel.xpm"
    "riece-command-next-channel.xpm"
    "riece-command-change-layout.xpm"
    "riece-submit-bug-report.xpm"))

(defvar riece-scripts
  '("server.rb"
    "aproxy.rb"))

(defun riece-compile-modules (modules)
  (let ((load-path (cons nil load-path))
	error-modules)
    (while modules
      (let ((source (expand-file-name
		     (concat (symbol-name (car modules)) ".el"))))
	(if (file-newer-than-file-p source (concat source "c"))
	    (condition-case error
		(byte-compile-file source)
	      (error
	       (setq error-modules (cons (car modules) error-modules))))))
      (setq modules (cdr modules)))
    (if error-modules
	(princ (concat "\n\
  WARNING: ---------------------------------------------------------
  WARNING: Couldn't compile following modules:
  WARNING: 
  WARNING:   " (mapconcat #'symbol-name error-modules ", ") "\n\
  WARNING: 
  WARNING: You should probably stop here, try \"make distclean\" to clear
  WARNING: the last build, and then reconfigure.
  WARNING: ---------------------------------------------------------\n\n")))))

(defun riece-compile-module ()
  (let ((load-path (cons nil load-path)))
    (let ((source (expand-file-name
		   (concat (car command-line-args-left) ".el"))))
      (if (file-newer-than-file-p source (concat source "c"))
	  (byte-compile-file source)))))

(defun riece-install-modules (modules dest just-print)
  (unless (or just-print (file-exists-p dest))
    (make-directory dest t))
  (while modules
    (let ((name (symbol-name (car modules))))
      (princ (format "%s.el -> %s\n" name dest))
      (unless just-print
	(copy-file (expand-file-name (concat name ".el"))
		   (expand-file-name (concat name ".el") dest)
		   t t))
      (princ (format "%s.elc -> %s\n" name dest))
      (unless just-print
	(if (file-exists-p (expand-file-name (concat name ".elc")))
	    (copy-file (expand-file-name (concat name ".elc"))
		       (expand-file-name (concat name ".elc") dest)
		       t t)
	  (princ (format "(%s was not successfully compiled, ignored)\n"
			 name)))))
    (setq modules (cdr modules))))

(defun riece-install-icons (icons dest just-print)
  (unless (or just-print (file-exists-p dest))
    (make-directory dest t))
  (while icons
    (when (file-exists-p (expand-file-name (car icons)))
      (princ (format "%s -> %s\n" (car icons) dest))
      (unless just-print
	(copy-file (expand-file-name (car icons))
		   (expand-file-name (car icons) dest)
		   t t)))
    (setq icons (cdr icons))))

(defun riece-install-scripts (scripts dest just-print)
  (unless (or just-print (file-exists-p dest))
    (make-directory dest t))
  (while scripts
    (when (file-exists-p (expand-file-name (car scripts)))
      (princ (format "%s -> %s\n" (car scripts) dest))
      (unless just-print
	(copy-file (expand-file-name (car scripts))
		   (expand-file-name (car scripts) dest)
		   t t)))
    (setq scripts (cdr scripts))))

(defun riece-install-just-print-p ()
  (let ((flag (getenv "MAKEFLAGS"))
	case-fold-search)
    (if flag
	(string-match "^\\(\\(--[^ ]+ \\)+-\\|[^ =-]\\)*n" flag))))

(defun riece-examine-modules ()
  (let ((load-path (cons nil load-path)))
    (require 'riece-addon-modules)
    (append riece-modules
	    (mapcar #'car riece-addon-modules))))

(defun riece-examine ()
  (princ (mapconcat #'symbol-name (riece-examine-modules) " ")))

(defun riece-compile ()
  (riece-compile-modules (riece-examine-modules)))

(defun riece-install ()
  (riece-install-modules
   (riece-examine-modules)
   (expand-file-name "riece" (car command-line-args-left))
   (riece-install-just-print-p))
  (riece-install-icons
   riece-icons
   (expand-file-name "riece" (car command-line-args-left))
   (riece-install-just-print-p))
  (riece-install-scripts
   riece-scripts
   (expand-file-name "riece" (car command-line-args-left))
   (riece-install-just-print-p)))

(defun riece-compile-package ()
  (setq autoload-package-name "riece")
  (add-to-list 'command-line-args-left ".")
  (batch-update-directory)
  (add-to-list 'command-line-args-left ".")
  (Custom-make-dependencies)
  (riece-compile-modules
   (append (riece-examine-modules)
	   '(auto-autoloads custom-load))))

(defun riece-install-package ()
  (riece-install-modules
   (append (riece-examine-modules)
	   '(auto-autoloads custom-load))
   (expand-file-name "lisp/riece" (car command-line-args-left))
   (riece-install-just-print-p))
  (riece-install-icons
   riece-icons
   (expand-file-name "etc/riece" (car command-line-args-left))
   (riece-install-just-print-p))
  (riece-install-scripts
   riece-scripts
   (expand-file-name "etc/riece" (car command-line-args-left))
   (riece-install-just-print-p)))

(defun riece-test ()
  (let ((load-path (cons (expand-file-name "test") (cons nil load-path)))
	(files (directory-files "test" t "^test-.*\\.el$"))
        suite)
    (require 'lunit-report)
    (setq suite (lunit-make-test-suite))
    (while files
      (when (file-regular-p (car files))
	(load-file (car files))
	(lunit-test-suite-add-test
	 suite
	 (lunit-make-test-suite-from-class
	  (intern (file-name-sans-extension
		   (file-name-nondirectory (car files)))))))
      (setq files (cdr files)))
    (lunit-report suite (car command-line-args-left))))