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 (if (featurep 'mule) '("ja" "en") '("en"))
32 "The language of info file (\"ja\" or \"en\").")
35 (defvar wl-news-lang (if (featurep 'mule) '("ja" "en") '("en"))
36 "The language of news file (\"ja\" or \"en\").")
37 (defconst wl-news-news-file '(("en" "NEWS")
39 (defconst wl-news-search-regexp
40 '(("en" "^\\* Changes in \\([0-9.]*\\) from [0-9.]+x?")
41 ("ja" "^\\* [0-9.]+x?
\e$B$+$i
\e(B \\([0-9.]*\\)
\e$B$X$NJQ99E@
\e(B")))
42 (defconst wl-news-filename "wl-news.el")
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 (condition-case () (require 'custom) (error nil))
51 (unless (and (fboundp 'defgroup)
53 ;; ignore broken module
54 (not (featurep 'tinycustom)))
55 (when (and (boundp 'emacs-major-version)
56 (= emacs-major-version 19)
57 (>= emacs-minor-version 29))
59 Warning: You don't seem to have \"new custom\" package installed.
60 See README file of APEL package for more information.
63 (defmacro defgroup (&rest args))
64 (defmacro defcustom (symbol value &optional doc &rest args)
65 (let ((doc (concat "*" (or doc ""))))
66 `(defvar ,symbol ,value ,doc))))
68 (load "bytecomp" nil t)
70 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
71 ;; Bind defcustom'ed variables.
72 (put 'custom-declare-variable 'byte-hunk-handler
73 'byte-compile-file-form-custom-declare-variable)
74 (defun byte-compile-file-form-custom-declare-variable (form)
75 (if (memq 'free-vars byte-compile-warnings)
76 (setq byte-compile-bound-variables
77 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
82 (wrong-number-of-arguments
83 ;; Optimize byte code for `char-after'.
84 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
85 (defun byte-optimize-char-after (form)
90 (setq byte-compile-warnings '(free-vars unresolved callargs redefine))
94 (setq max-lisp-eval-depth 400))
96 ;; FIXME: it is currently needed to byte-compile with Emacs 21.
97 (setq recursive-load-depth-limit nil)
99 (condition-case () (require 'easymenu) (error nil))
101 (defvar config-wl-package-done nil)
103 (defun config-wl-package-subr ()
104 (unless config-wl-package-done
105 (setq config-wl-package-done t)
106 (setq load-path (cons (expand-file-name ".") load-path))
107 (setq load-path (cons (expand-file-name WLDIR)
108 (cons (expand-file-name ELMODIR) load-path)))
109 ;; load custom file if exists. `WL-CFG.el' override for committer.
110 (load "./WL-CFG" t nil nil)
113 (setq load-path (cons (expand-file-name UTILSDIR) load-path)))
115 (load "./WL-ELS" nil nil t)
116 ;; product.el version check
118 (if (not (fboundp 'product-version-as-string))
119 (error "Please install new APEL. See INSTALL or INSTALL.ja"))
120 ;; smtp.el version check.
122 (if (not (fboundp 'smtp-send-buffer))
123 (error "Please install new FLIM. See INSTALL or INSTALL.ja"))
125 (require 'mime-setup)
126 (error (error "Cannot load `mime-setup'. Please install SEMI")))))
128 (defun config-wl-pixmap-dir (&optional packagedir)
129 "Examine pixmap directory where icon files should go."
130 (let ((pixmap-dir (car command-line-args-left)))
132 (if (string= pixmap-dir "NONE")
134 (expand-file-name "etc/wl/" packagedir)
135 (expand-file-name "wl/icons/" data-directory))
138 (princ (format "PIXMAPDIR is %s\n" PIXMAPDIR)))
139 (setq command-line-args-left (cdr command-line-args-left)))
141 (defun config-wl-package ()
142 (config-wl-package-subr)
144 (let ((elispdir (car command-line-args-left)))
145 (if (string= elispdir "NONE")
146 (defvar LISPDIR (install-detect-elisp-directory))
147 (defvar LISPDIR elispdir)))
148 (princ (format "LISPDIR is %s\n" LISPDIR))
149 (setq command-line-args-left (cdr command-line-args-left))
151 (config-wl-pixmap-dir)
154 (defun update-version ()
155 "Update version number of documents."
157 (load-file "elmo/elmo-version.el")
158 (let ((version (mapconcat
160 (product-version (product-find 'elmo-version))
162 (coding-system-for-write 'iso-latin-1-unix))
163 (princ (concat "Update version number to " version "\n"))
164 ;; generate version.tex
166 (insert "\\def\\versionnumber{" version "}\n")
167 (write-region (point-min) (point-max) (expand-file-name
168 "version.tex" "doc")))
169 ;; generate version.texi
171 (insert "@set VERSION " version "\n")
172 (write-region (point-min) (point-max) (expand-file-name
173 "version.texi" "doc")))))
176 "Run test suite for developer."
180 (let ((files (directory-files "tests" t "^test-.*\\.el$"))
181 (suite (lunit-make-test-suite)))
183 (if (file-regular-p (car files))
185 (load-file (car files))
186 (lunit-test-suite-add-test
187 suite (lunit-make-test-suite-from-class
188 (intern (file-name-sans-extension
189 (file-name-nondirectory (car files))))))))
190 (setq files (cdr files)))
194 "Check user environment. Not for developer."
198 (load "wl-news.el.in")
200 (let ((files (directory-files "tests" t "^check-.*\\.el$"))
201 (suite (lunit-make-test-suite)))
203 (if (file-regular-p (car files))
205 (load-file (car files))
206 (lunit-test-suite-add-test
207 suite (lunit-make-test-suite-from-class
208 (intern (file-name-sans-extension
209 (file-name-nondirectory (car files))))))))
210 (setq files (cdr files)))
213 (defun wl-scan-path (path scanner)
214 (let ((dirs (if (listp path)
217 (apply 'append (mapcar scanner dirs))))
219 (defun wl-scan-source (path)
224 (list y (concat y "c")))
225 (directory-files x nil "\\(.+\\)\\.el$" t))))))
227 (defun wl-scan-icons (path)
230 (let ((case-fold-search t))
231 (directory-files x nil "\\.img$\\|\\.x[bp]m$")))))
233 (defun wl-uninstall (objs path)
234 ;(message (mapconcat 'identity objs " "))
237 (let ((filename (expand-file-name x path)))
238 (if (and (file-exists-p filename)
239 (file-writable-p filename))
241 (princ (format "%s was uninstalled.\n" filename))
242 (delete-file filename)))))
246 (defun wl-examine-modules ()
247 "Examine wl modules should be byte-compile'd."
248 (config-wl-package-subr)
250 (dolist (module modules-alist)
251 (dolist (filename (cdr module))
252 (princ (format "%s/%s.elc " (car module) filename)))))
255 (defun compile-wl-package ()
260 (compile-elisp-modules (cdr x) (car x)))
263 (defun install-wl-icons ()
264 (if (not (file-directory-p PIXMAPDIR))
265 (make-directory PIXMAPDIR t))
266 (let* ((case-fold-search t)
267 (icons (directory-files ICONDIR nil
268 (cond ((featurep 'xemacs)
270 ((and (boundp 'emacs-major-version)
271 (>= emacs-major-version 21))
272 "\\.img$\\|\\.x[bp]m$")
274 "\\.img$\\|\\.xbm$")))))
275 (install-files icons ICONDIR PIXMAPDIR nil 'overwrite)))
277 (defun uninstall-wl-icons ()
278 (if (not (file-directory-p PIXMAPDIR))
280 (wl-uninstall (wl-scan-icons PIXMAPDIR)
283 (defun install-wl-package ()
285 (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
286 (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
289 (install-elisp-modules (cdr x) (car x)
290 (if (string= (car x) ELMODIR)
298 (defun uninstall-wl-package ()
300 (let ((wl-install-dir (expand-file-name WL_PREFIX
302 (elmo-install-dir (expand-file-name ELMO_PREFIX
304 (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
306 (wl-uninstall (wl-scan-source (list ELMODIR))
309 (uninstall-wl-icons)))
312 (defun config-wl-package-xmas ()
313 (if (not (featurep 'xemacs))
314 (error "This directive is only for XEmacs"))
315 (config-wl-package-subr)
319 (if (and (setq package-dir (car command-line-args-left))
320 (not (string= "NONE" package-dir)))
323 (install-get-default-package-directory)))
324 (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
325 (setq command-line-args-left (cdr command-line-args-left)))
327 (config-wl-pixmap-dir PACKAGEDIR)
331 (defun compile-wl-package-xmas ()
332 (config-wl-package-xmas)
334 (setq autoload-package-name "wl")
335 (add-to-list 'command-line-args-left WLDIR)
336 (batch-update-directory)
337 (add-to-list 'command-line-args-left WLDIR)
338 (Custom-make-dependencies)
339 ;; WL-AUTOLOAD-MODULES
340 (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
343 (compile-elisp-modules (cdr x) (car x)))
346 (defun install-wl-package-xmas ()
347 (compile-wl-package-xmas)
348 (let ((LISPDIR (expand-file-name "wl"
349 (expand-file-name "lisp"
351 (DATADIR (expand-file-name "wl"
352 (expand-file-name "etc"
354 (INFODIR (expand-file-name "info" PACKAGEDIR)))
355 (or (file-exists-p DATADIR)
356 (make-directory DATADIR t))
357 (or (file-exists-p INFODIR)
358 (make-directory INFODIR t))
363 (install-elisp-modules (cdr x) (car x) LISPDIR))
365 ;; WL-AUTOLOAD-MODULES
366 (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
369 (wl-texinfo-install)))
372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
375 (defun wl-texinfo-info-file (lang)
376 (symbol-value (intern (format "wl-%s-info" lang))))
378 (defun wl-texinfo-texi-file (lang)
379 (symbol-value (intern (format "wl-%s-texi" lang))))
381 (defun wl-texinfo-check-newer (lang)
382 (let ((info-file (expand-file-name (wl-texinfo-info-file lang) DOCDIR)))
384 (file-newer-than-file-p info-file
385 (expand-file-name "version.texi" DOCDIR))
386 (file-newer-than-file-p info-file
387 (expand-file-name (wl-texinfo-texi-file lang) DOCDIR)))))
389 (defun wl-texinfo-format-file (lang)
390 (require 'wl-vars) ;; for 'wl-cs-local
391 (or (wl-texinfo-check-newer lang)
393 ;; Support old texinfmt.el
394 (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
395 (find-file (expand-file-name (wl-texinfo-texi-file lang) DOCDIR))
396 (setq obuf (current-buffer))
397 ;; We can't know file names if splitted.
398 (texinfo-format-buffer t)
399 ;; Emacs20.2's default is 'raw-text-unix.
400 (and (fboundp 'set-buffer-file-coding-system)
401 (set-buffer-file-coding-system wl-cs-local))
403 (kill-buffer (current-buffer)) ;; info
404 (kill-buffer obuf)) ;; texi
407 (defun wl-texinfo-format ()
408 (wl-detect-info-directory)
409 (cond ((null wl-info-lang))
410 ((listp wl-info-lang)
411 (mapc 'wl-texinfo-format-file wl-info-lang))
412 ((stringp wl-info-lang)
413 (wl-texinfo-format-file wl-info-lang))))
415 (defun wl-texinfo-install-file (lang)
416 (let ((infofile (wl-texinfo-info-file lang)))
417 (install-file infofile DOCDIR INFODIR nil 'overwrite)))
419 (defun wl-texinfo-install ()
420 (cond ((null wl-info-lang))
421 ((listp wl-info-lang)
422 (mapc 'wl-texinfo-install-file wl-info-lang))
423 ((stringp wl-info-lang)
424 (wl-texinfo-install-file wl-info-lang))))
426 (defun wl-primary-info-file ()
427 "Get primary info file (for wl-detect-info-directory)."
428 (cond ((null wl-info-lang))
429 ((listp wl-info-lang)
430 (let ((wl-info-lang (car wl-info-lang)))
431 (wl-primary-info-file)))
432 ((stringp wl-info-lang)
433 (wl-texinfo-info-file wl-info-lang))))
435 (defun wl-detect-info-directory ()
436 (config-wl-package-subr)
440 (if (fboundp 'info-initialize)
443 (let ((infodir (car command-line-args-left))
444 (info (wl-primary-info-file))
447 (if (string= infodir "NONE")
449 (exec-installed-p info Info-directory-list
450 COMPRESS-SUFFIX-LIST))
451 (directory-file-name (file-name-directory previous))
452 (car Info-directory-list))
454 (setq command-line-args-left (cdr command-line-args-left))))
455 (princ (format "INFODIR is %s\n\n" INFODIR))))
457 (defun install-wl-info ()
459 (wl-texinfo-install))
462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
465 (defun wl-news-news-file (lang)
466 (cadr (assoc lang wl-news-news-file)))
468 (defun wl-news-check-newer (out-filename news-lang)
469 (let ((lang news-lang)
472 (if (file-newer-than-file-p
473 (wl-news-news-file (car lang)) out-filename)
475 (setq lang (cdr lang)))
478 (defun make-wl-news ()
480 (expand-file-name (concat wl-news-filename ".in") WLDIR))
482 (expand-file-name wl-news-filename WLDIR))
483 (wl-news-lang (if (listp wl-news-lang)
485 (list wl-news-lang))))
486 (if (or (file-newer-than-file-p in-filename out-filename)
487 (wl-news-check-newer out-filename wl-news-lang))
490 (insert-file-contents in-filename)
491 (goto-char (point-min))
492 (unless (re-search-forward "^;;; -\\*- news-list -\\*-" nil t)
493 (error "Invalid wl-news.el.in"))
497 (insert "(defconst wl-news-news-alist\n '")
499 (prin1 (wl-news-parse-news wl-news-lang) (current-buffer))
501 (narrow-to-region p (point))
503 (while (re-search-forward "^(" nil t)
504 (replace-match "\\\\(")) ; avoid font-lock confusion
507 (insert "(defconst wl-news-news-alist nil)\n\n"))
508 (let ((buffer-file-coding-system (mime-charset-to-coding-system 'x-ctext)))
509 (write-region (point-min) (point-max) out-filename)))))))
511 (defun wl-news-parse-news (lang)
514 (setq news-list (cons
515 (cons (car lang) (wl-news-parse-news-subr (car lang)))
517 (setq lang (cdr lang)))
520 (defun wl-news-parse-news-subr (lang)
521 (let ((filename (wl-news-news-file lang))
522 (reg (cadr (assoc lang wl-news-search-regexp)))
524 (if (and filename reg)
526 (insert-file-contents filename)
527 (while (re-search-forward reg nil t)
528 (let ((beg (match-beginning 0))
529 (version-tmp (split-string (match-string 1) "\\."))
530 version news-string end)
532 (setq version (append version (list (string-to-number (car version-tmp)))))
533 (setq version-tmp (cdr version-tmp)))
534 (re-search-forward "^\\(\\* \\|
\f\\)" nil t)
535 (goto-char (- (match-beginning 0) 1))
537 (setq news-string (buffer-substring beg end))
540 (list (cons version news-string))))))))
546 ;;; * MORE refine code (^_^;