;;; lisp file for xyzzy ver0.2.2.233 or ver0.2.2.234
;;; compile-directory.l ver0.0.0.2 // crayonzen [2006-06-08]00:03:12(+0900)

(provide "compile-directory")

(in-package "editor")

(export '(byte-compile-directory-ask
	  byte-compile-directory
	  byte-compile-directory-all
	  ))

;;ask all
(defun byte-compile-directory-ask (dirname)
  (interactive "DByte compile directory: \np")
  (byte-compile-directory-1 dirname 1 #'compile-file))

;;new src only
(defun byte-compile-directory (dirname)
  (interactive "DByte compile directory: \np")
  (byte-compile-directory-1 dirname 2 #'compile-file))

;;all
(defun byte-compile-directory-all (dirname)
  (interactive "DByte compile directory: \np")
  (byte-compile-directory-1 dirname 3 #'compile-file))

(defun byte-compile-directory-1 (dirname arg compile-fn)
  (long-operation
    (let ((count 0))
      (dolist (src (directory (merge-pathnames "*.l" dirname) :absolute t))
	(let ((dst (compile-file-pathname src)))
	  (setq newdst (and (file-exist-p dst)
			    (file-newer-than-file-p dst src)))

	  (when (case arg
		  (1
		   (if (and (file-exist-p dst)
			    (null (file-newer-than-file-p src dst)))
		       (yes-no-or-cancel-p "再び~Aをコンパイルし直しますか?" src)
		     (yes-no-or-cancel-p "~Aをコンパイルしますか?" src)))
		  (2
		   (if (file-exist-p dst)
		       (if (file-newer-than-file-p src dst)
			   t
			 ;nil
			 )
		     t))
		  (3
		   t)
		  (t
		   nil)
		  )

	    (funcall compile-fn src)
	    (setq count (1+ count))
	    )

	  ))
      (format t "Total ~[No~:;~:*~d~] file~:*~p compiled~%" count)
      count))
  )
