2 ;;; WL-MK for byte-compile, install, uninstall
4 ;;; Original by OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
5 ;;; Modified by Yuuichi Teranishi <teranisi@gohome.org>
7 ;;;;;;;;;;;;;;;;;;;;; DO NOT EDIT THIS FILE ;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;; INTERNAL USE ONLY ;;;;;;;;;;;;;;;;;;;;;
13 (defvar ELMODIR "./elmo")
14 (defvar DOCDIR "./doc")
15 (defvar ICONDIR "./etc/icons")
16 (defvar UTILSDIR "./utils")
17 (defvar WL_PREFIX "wl")
18 (defvar ELMO_PREFIX "wl")
20 (defvar COMPRESS-SUFFIX-LIST '("" ".gz" ".Z" ".bz2"))
22 (defvar wl-install-utils nil
23 "If Non-nil, install `wl-utils-modules'.")
26 (defconst wl-ja-info "wl-ja.info")
27 (defconst wl-ja-texi "wl-ja.texi")
28 (defconst wl-en-info "wl.info")
29 (defconst wl-en-texi "wl.texi")
31 (defvar wl-info-lang '("ja" "en")
32 "The language of info file (\"ja\" or \"en\").")
35 (defconst wl-news-news-file "NEWS")
36 (defconst wl-news-news-file-ja "NEWS.ja")
37 (defconst wl-news-filename "wl-news.el")
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 (condition-case () (require 'custom) (error nil))
46 (unless (and (fboundp 'defgroup)
48 ;; ignore broken module
49 (not (featurep 'tinycustom)))
50 (when (and (boundp 'emacs-major-version)
51 (= emacs-major-version 19)
52 (>= emacs-minor-version 29))
54 Warning: You don't seem to have \"new custom\" package installed.
55 See README file of APEL package for more information.
58 (defmacro defgroup (&rest args))
59 (defmacro defcustom (symbol value &optional doc &rest args)
60 (let ((doc (concat "*" (or doc ""))))
61 (` (defvar (, symbol) (, value) (, doc))))))
63 (load "bytecomp" nil t)
65 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
66 ;; Bind defcustom'ed variables.
67 (put 'custom-declare-variable 'byte-hunk-handler
68 'byte-compile-file-form-custom-declare-variable)
69 (defun byte-compile-file-form-custom-declare-variable (form)
70 (if (memq 'free-vars byte-compile-warnings)
71 (setq byte-compile-bound-variables
72 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
77 (wrong-number-of-arguments
78 ;; Optimize byte code for `char-after'.
79 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
80 (defun byte-optimize-char-after (form)
85 (setq byte-compile-warnings '(free-vars unresolved callargs redefine))
89 (setq max-lisp-eval-depth 400))
91 ;; FIXME: it is currently needed to byte-compile with Emacs 21.
92 (setq recursive-load-depth-limit nil)
94 (condition-case () (require 'easymenu) (error nil))
96 (defvar config-wl-package-done nil)
98 (defun config-wl-package-subr ()
99 (unless config-wl-package-done
100 (setq config-wl-package-done t)
101 (setq load-path (cons (expand-file-name ".") load-path))
102 (setq load-path (cons (expand-file-name WLDIR)
103 (cons (expand-file-name ELMODIR) load-path)))
104 ;; load custom file if exists. `WL-CFG.el' override for committer.
105 (load "./WL-CFG" t nil nil)
108 (setq load-path (cons (expand-file-name UTILSDIR) load-path)))
110 (load "./WL-ELS" nil nil t)
111 ;; product.el version check
113 (if (not (fboundp 'product-version-as-string))
114 (error "Please install new APEL. See INSTALL or INSTALL.ja"))
115 ;; smtp.el version check.
117 (if (not (fboundp 'smtp-send-buffer))
118 (error "Please install new FLIM. See INSTALL or INSTALL.ja"))
120 (require 'mime-setup)
121 (error (error "Cannot load `mime-setup'. Please install SEMI")))))
123 (defun config-wl-pixmap-dir (&optional packagedir)
124 "Examine pixmap directory where icon files should go."
125 (let ((pixmap-dir (car command-line-args-left)))
127 (if (string= pixmap-dir "NONE")
129 (expand-file-name "etc/wl/" packagedir)
130 (expand-file-name "wl/icons/" data-directory))
133 (princ (format "PIXMAPDIR is %s\n" PIXMAPDIR)))
134 (setq command-line-args-left (cdr command-line-args-left)))
136 (defun config-wl-package ()
137 (config-wl-package-subr)
139 (let ((elispdir (car command-line-args-left)))
140 (if (string= elispdir "NONE")
141 (defvar LISPDIR (install-detect-elisp-directory))
142 (defvar LISPDIR elispdir)))
143 (princ (format "LISPDIR is %s\n" LISPDIR))
144 (setq command-line-args-left (cdr command-line-args-left))
146 (config-wl-pixmap-dir)
149 (defun update-version ()
150 "Update version number of documents."
152 (load-file "elmo/elmo-version.el")
153 (let ((version (mapconcat
155 (product-version (product-find 'elmo-version))
157 (princ (concat "Update version number to " version "\n"))
158 ;; generate version.tex
160 (insert "\\def\\versionnumber{" version "}\n")
161 (write-region (point-min) (point-max) (expand-file-name
162 "version.tex" "doc")))
163 ;; generate version.texi
165 (insert "@set VERSION " version "\n")
166 (write-region (point-min) (point-max) (expand-file-name
167 "version.texi" "doc")))))
170 "Run test suite for developer."
173 (let ((files (directory-files "tests" t "^test-.*\\.el$"))
174 (suite (lunit-make-test-suite)))
176 (if (file-regular-p (car files))
178 (load-file (car files))
179 (lunit-test-suite-add-test
180 suite (lunit-make-test-suite-from-class
181 (intern (file-name-sans-extension
182 (file-name-nondirectory (car files))))))))
183 (setq files (cdr files)))
187 "Check user environment. Not for developer."
190 (let ((files (directory-files "tests" t "^check-.*\\.el$"))
191 (suite (lunit-make-test-suite)))
193 (if (file-regular-p (car files))
195 (load-file (car files))
196 (lunit-test-suite-add-test
197 suite (lunit-make-test-suite-from-class
198 (intern (file-name-sans-extension
199 (file-name-nondirectory (car files))))))))
200 (setq files (cdr files)))
203 (defun wl-scan-source (path)
208 (setq ret (append (list y (concat y "c")) ret)))
209 (directory-files x nil "\\(.+\\)\\.el$" t)))
214 (defun wl-uninstall (objs path)
215 ;(message (mapconcat 'identity objs " "))
218 (let ((filename (expand-file-name x path)))
219 (if (and (file-exists-p filename)
220 (file-writable-p filename))
222 (princ (format "%s was uninstalled.\n" filename))
223 (delete-file filename)))))
227 (defun compile-wl-package ()
232 (compile-elisp-modules (cdr x) (car x)))
235 (defun install-wl-icons ()
236 (if (not (file-directory-p PIXMAPDIR))
237 (make-directory PIXMAPDIR t))
238 (let* ((case-fold-search t)
239 (icons (directory-files ICONDIR t
240 (cond ((featurep 'xemacs)
242 ((and (boundp 'emacs-major-version)
243 (>= emacs-major-version 21))
244 "\\.img$\\|\\.x[bp]m$")
246 "\\.img$\\|\\.xbm$"))))
249 (setq icon (car icons)
251 dest (expand-file-name (file-name-nondirectory icon) PIXMAPDIR))
252 (princ (format "%s -> %s\n"
253 (file-name-nondirectory icon)
254 (substring (file-name-directory dest) 0 -1)))
255 (copy-file icon dest t))))
257 (defun install-wl-package ()
259 (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
260 (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
263 (install-elisp-modules (cdr x) (car x)
264 (if (string= (car x) ELMODIR)
272 (defun uninstall-wl-package ()
274 (let ((wl-install-dir (expand-file-name WL_PREFIX
276 (elmo-install-dir (expand-file-name ELMO_PREFIX
278 (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
280 (wl-uninstall (wl-scan-source (list ELMODIR))
283 (let* ((case-fold-search t)
284 (icons (directory-files PIXMAPDIR t "\\.x[bp]m$"))
287 (setq icon (car icons)
289 (if (and (file-exists-p icon)
290 (file-writable-p icon))
292 (princ (format "%s was uninstalled.\n" icon))
293 (delete-file icon)))))))
296 (defun config-wl-package-xmas ()
297 (if (not (featurep 'xemacs))
298 (error "This directive is only for XEmacs"))
299 (config-wl-package-subr)
302 (and (setq package-dir (car command-line-args-left))
303 (if (string= "NONE" package-dir)
305 (if (boundp 'early-packages)
306 (let ((dirs (append (if early-package-load-path
308 (if late-package-load-path
310 (if last-package-load-path
313 (while (not (file-exists-p
314 (setq dir (car dirs))))
315 (setq dirs (cdr dirs)))
317 (defvar PACKAGEDIR package-dir)))
318 (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
319 (setq command-line-args-left (cdr command-line-args-left)))
321 (config-wl-pixmap-dir PACKAGEDIR)
325 (defun compile-wl-package-xmas ()
326 (config-wl-package-xmas)
327 (setq autoload-package-name "wl")
328 (add-to-list 'command-line-args-left WLDIR)
329 (batch-update-directory)
330 (add-to-list 'command-line-args-left WLDIR)
331 (Custom-make-dependencies)
332 ;; WL-AUTOLOAD-MODULES
333 (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
336 (compile-elisp-modules (cdr x) (car x)))
339 (defun install-wl-package-xmas ()
340 (compile-wl-package-xmas)
341 (let ((LISPDIR (expand-file-name "wl"
342 (expand-file-name "lisp"
344 (DATADIR (expand-file-name "wl"
345 (expand-file-name "etc"
347 (INFODIR (expand-file-name "info" PACKAGEDIR)))
348 (or (file-exists-p DATADIR)
349 (make-directory DATADIR t))
350 (or (file-exists-p INFODIR)
351 (make-directory INFODIR t))
356 (install-elisp-modules (cdr x) (car x) LISPDIR))
358 ;; WL-AUTOLOAD-MODULES
359 (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
362 (wl-texinfo-install)))
365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
368 (defun wl-texinfo-format-file (lang)
369 (let ((infofile (symbol-value (intern (format "wl-%s-info" lang))))
370 (texifile (symbol-value (intern (format "wl-%s-texi" lang)))))
371 (require 'wl-vars) ;; for 'wl-cs-local
372 (or (file-newer-than-file-p (expand-file-name infofile DOCDIR)
373 (expand-file-name texifile DOCDIR))
375 ;; Support old texinfmt.el
376 (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
377 (find-file (expand-file-name texifile DOCDIR))
378 (setq obuf (current-buffer))
379 ;; We can't know file names if splitted.
380 (texinfo-format-buffer t)
381 ;; Emacs20.2's default is 'raw-text-unix.
382 (and (fboundp 'set-buffer-file-coding-system)
383 (set-buffer-file-coding-system wl-cs-local))
385 (kill-buffer (current-buffer)) ;; info
386 (kill-buffer obuf)) ;; texi
389 (defun wl-texinfo-format ()
390 (wl-detect-info-directory)
391 (cond ((listp wl-info-lang)
392 (mapcar 'wl-texinfo-format-file wl-info-lang))
393 ((stringp wl-info-lang)
394 (wl-texinfo-format-file wl-info-lang))))
396 (defun wl-texinfo-install-file (lang)
397 (let ((infofile (symbol-value (intern (format "wl-%s-info" lang)))))
398 (install-file infofile DOCDIR INFODIR nil 'overwrite)))
400 (defun wl-texinfo-install ()
401 (cond ((listp wl-info-lang)
402 (mapcar 'wl-texinfo-install-file wl-info-lang))
403 ((stringp wl-info-lang)
404 (wl-texinfo-install-file wl-info-lang))))
406 (defun wl-primary-info-file ()
407 "Get primary info file (for wl-detect-info-directory)."
409 ((listp wl-info-lang)
410 (let ((wl-info-lang (car wl-info-lang)))
411 (wl-primary-info-file)))
412 ((stringp wl-info-lang)
413 (symbol-value (intern (format "wl-%s-info" wl-info-lang))))))
415 (defun wl-detect-info-directory ()
416 (config-wl-package-subr)
419 (if (fboundp 'info-initialize)
422 (let ((infodir (car command-line-args-left))
423 (info (wl-primary-info-file))
426 (if (string= infodir "NONE")
428 (exec-installed-p info Info-directory-list
429 COMPRESS-SUFFIX-LIST))
431 ;;(condition-case nil (delete-file previous))
432 (directory-file-name (file-name-directory previous));)
433 (car Info-directory-list))
435 (setq command-line-args-left (cdr command-line-args-left))))
436 (princ (format "INFODIR is %s\n\n" INFODIR)))
438 (defun install-wl-info ()
440 (wl-texinfo-install))
443 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
446 (defun make-wl-news ()
448 (expand-file-name (concat wl-news-filename ".in") WLDIR))
450 (expand-file-name wl-news-filename WLDIR)))
451 (if (or (file-newer-than-file-p in-filename out-filename)
452 (file-newer-than-file-p wl-news-news-file out-filename)
453 (file-newer-than-file-p wl-news-news-file-ja out-filename))
456 (insert-file-contents in-filename)
457 (goto-char (point-min))
458 (unless (re-search-forward "^;;; -\\*- news-list -\\*-" nil t)
459 (error "Invalid wl-news.el.in"))
461 (insert "(defconst wl-news-news-alist\n '")
462 (prin1 (wl-news-parse-news) (current-buffer))
464 (insert "(defconst wl-news-news-ja-alist\n '")
465 (prin1 (wl-news-parse-news-ja) (current-buffer))
467 (write-region (point-min) (point-max) out-filename))))))
469 (defun wl-news-parse-news ()
472 (insert-file-contents wl-news-news-file)
473 (while (re-search-forward "^\\* Changes in \\([0-9.]*\\) from" nil t)
474 (let ((beg (match-beginning 0))
475 (version-tmp (split-string (match-string 1) "\\."))
476 version news-string end)
478 (setq version (append version (list (string-to-int (car version-tmp)))))
479 (setq version-tmp (cdr version-tmp)))
480 (re-search-forward "^\\(\\* \\|
\f\\)" nil t)
481 (goto-char (- (match-beginning 0) 1))
483 (setq news-string (buffer-substring beg end))
486 (list (cons version news-string)))))))
489 (defun wl-news-parse-news-ja ()
492 (insert-file-contents wl-news-news-file-ja)
493 (while (re-search-forward "^\\* [0-9.]*
\e$B$+$i
\e(B \\([0-9.]*\\)
\e$B$X$NJQ99E@
\e(B" nil t)
494 (let ((beg (match-beginning 0))
495 (version-tmp (split-string (match-string 1) "\\."))
496 version news-string end)
498 (setq version (append version (list (string-to-int (car version-tmp)))))
499 (setq version-tmp (cdr version-tmp)))
500 (re-search-forward "^\\(\\* \\|
\f\\)" nil t)
501 (goto-char (- (match-beginning 0) 1))
503 (setq news-string (buffer-substring beg end))
506 (list (cons version news-string)))))))
513 ;;; * MORE refine code (^_^;