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-source (path)
218 (setq ret (append (list y (concat y "c")) ret)))
219 (directory-files x nil "\\(.+\\)\\.el$" t)))
224 (defun wl-uninstall (objs path)
225 ;(message (mapconcat 'identity objs " "))
228 (let ((filename (expand-file-name x path)))
229 (if (and (file-exists-p filename)
230 (file-writable-p filename))
232 (princ (format "%s was uninstalled.\n" filename))
233 (delete-file filename)))))
237 (defun wl-examine-modules ()
238 "Examine wl modules should be byte-compile'd."
239 (config-wl-package-subr)
241 (dolist (module modules-alist)
242 (dolist (filename (cdr module))
243 (princ (format "%s/%s.elc " (car module) filename)))))
246 (defun compile-wl-package ()
251 (compile-elisp-modules (cdr x) (car x)))
254 (defun install-wl-icons ()
255 (if (not (file-directory-p PIXMAPDIR))
256 (make-directory PIXMAPDIR t))
257 (let* ((case-fold-search t)
258 (icons (directory-files ICONDIR nil
259 (cond ((featurep 'xemacs)
261 ((and (boundp 'emacs-major-version)
262 (>= emacs-major-version 21))
263 "\\.img$\\|\\.x[bp]m$")
265 "\\.img$\\|\\.xbm$")))))
266 (install-files icons ICONDIR PIXMAPDIR nil 'overwrite)))
268 (defun uninstall-wl-icons ()
269 (let* ((case-fold-search t)
270 (icons (directory-files PIXMAPDIR t "\\.img$\\|\\.x[bp]m$"))
273 (setq icon (car icons)
275 (if (and (file-exists-p icon)
276 (file-writable-p icon))
278 (princ (format "%s was uninstalled.\n" icon))
279 (delete-file icon))))))
281 (defun install-wl-package ()
283 (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
284 (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
287 (install-elisp-modules (cdr x) (car x)
288 (if (string= (car x) ELMODIR)
296 (defun uninstall-wl-package ()
298 (let ((wl-install-dir (expand-file-name WL_PREFIX
300 (elmo-install-dir (expand-file-name ELMO_PREFIX
302 (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
304 (wl-uninstall (wl-scan-source (list ELMODIR))
307 (uninstall-wl-icons)))
310 (defun config-wl-package-xmas ()
311 (if (not (featurep 'xemacs))
312 (error "This directive is only for XEmacs"))
313 (config-wl-package-subr)
317 (if (and (setq package-dir (car command-line-args-left))
318 (not (string= "NONE" package-dir)))
321 (install-get-default-package-directory)))
322 (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
323 (setq command-line-args-left (cdr command-line-args-left)))
325 (config-wl-pixmap-dir PACKAGEDIR)
329 (defun compile-wl-package-xmas ()
330 (config-wl-package-xmas)
332 (setq autoload-package-name "wl")
333 (add-to-list 'command-line-args-left WLDIR)
334 (batch-update-directory)
335 (add-to-list 'command-line-args-left WLDIR)
336 (Custom-make-dependencies)
337 ;; WL-AUTOLOAD-MODULES
338 (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
341 (compile-elisp-modules (cdr x) (car x)))
344 (defun install-wl-package-xmas ()
345 (compile-wl-package-xmas)
346 (let ((LISPDIR (expand-file-name "wl"
347 (expand-file-name "lisp"
349 (DATADIR (expand-file-name "wl"
350 (expand-file-name "etc"
352 (INFODIR (expand-file-name "info" PACKAGEDIR)))
353 (or (file-exists-p DATADIR)
354 (make-directory DATADIR t))
355 (or (file-exists-p INFODIR)
356 (make-directory INFODIR t))
361 (install-elisp-modules (cdr x) (car x) LISPDIR))
363 ;; WL-AUTOLOAD-MODULES
364 (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
367 (wl-texinfo-install)))
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
373 (defun wl-texinfo-info-file (lang)
374 (symbol-value (intern (format "wl-%s-info" lang))))
376 (defun wl-texinfo-texi-file (lang)
377 (symbol-value (intern (format "wl-%s-texi" lang))))
379 (defun wl-texinfo-check-newer (lang)
380 (let ((info-file (expand-file-name (wl-texinfo-info-file lang) DOCDIR)))
382 (file-newer-than-file-p info-file
383 (expand-file-name "version.texi" DOCDIR))
384 (file-newer-than-file-p info-file
385 (expand-file-name (wl-texinfo-texi-file lang) DOCDIR)))))
387 (defun wl-texinfo-format-file (lang)
388 (require 'wl-vars) ;; for 'wl-cs-local
389 (or (wl-texinfo-check-newer lang)
391 ;; Support old texinfmt.el
392 (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
393 (find-file (expand-file-name (wl-texinfo-texi-file lang) DOCDIR))
394 (setq obuf (current-buffer))
395 ;; We can't know file names if splitted.
396 (texinfo-format-buffer t)
397 ;; Emacs20.2's default is 'raw-text-unix.
398 (and (fboundp 'set-buffer-file-coding-system)
399 (set-buffer-file-coding-system wl-cs-local))
401 (kill-buffer (current-buffer)) ;; info
402 (kill-buffer obuf)) ;; texi
405 (defun wl-texinfo-format ()
406 (wl-detect-info-directory)
407 (cond ((null wl-info-lang))
408 ((listp wl-info-lang)
409 (mapc 'wl-texinfo-format-file wl-info-lang))
410 ((stringp wl-info-lang)
411 (wl-texinfo-format-file wl-info-lang))))
413 (defun wl-texinfo-install-file (lang)
414 (let ((infofile (wl-texinfo-info-file lang)))
415 (install-file infofile DOCDIR INFODIR nil 'overwrite)))
417 (defun wl-texinfo-install ()
418 (cond ((null wl-info-lang))
419 ((listp wl-info-lang)
420 (mapc 'wl-texinfo-install-file wl-info-lang))
421 ((stringp wl-info-lang)
422 (wl-texinfo-install-file wl-info-lang))))
424 (defun wl-primary-info-file ()
425 "Get primary info file (for wl-detect-info-directory)."
426 (cond ((null wl-info-lang))
427 ((listp wl-info-lang)
428 (let ((wl-info-lang (car wl-info-lang)))
429 (wl-primary-info-file)))
430 ((stringp wl-info-lang)
431 (wl-texinfo-info-file wl-info-lang))))
433 (defun wl-detect-info-directory ()
434 (config-wl-package-subr)
438 (if (fboundp 'info-initialize)
441 (let ((infodir (car command-line-args-left))
442 (info (wl-primary-info-file))
445 (if (string= infodir "NONE")
447 (exec-installed-p info Info-directory-list
448 COMPRESS-SUFFIX-LIST))
449 (directory-file-name (file-name-directory previous))
450 (car Info-directory-list))
452 (setq command-line-args-left (cdr command-line-args-left))))
453 (princ (format "INFODIR is %s\n\n" INFODIR))))
455 (defun install-wl-info ()
457 (wl-texinfo-install))
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
463 (defun wl-news-news-file (lang)
464 (cadr (assoc lang wl-news-news-file)))
466 (defun wl-news-check-newer (out-filename news-lang)
467 (let ((lang news-lang)
470 (if (file-newer-than-file-p
471 (wl-news-news-file (car lang)) out-filename)
473 (setq lang (cdr lang)))
476 (defun make-wl-news ()
478 (expand-file-name (concat wl-news-filename ".in") WLDIR))
480 (expand-file-name wl-news-filename WLDIR))
481 (wl-news-lang (if (listp wl-news-lang)
483 (list wl-news-lang))))
484 (if (or (file-newer-than-file-p in-filename out-filename)
485 (wl-news-check-newer out-filename wl-news-lang))
488 (insert-file-contents in-filename)
489 (goto-char (point-min))
490 (unless (re-search-forward "^;;; -\\*- news-list -\\*-" nil t)
491 (error "Invalid wl-news.el.in"))
495 (insert "(defconst wl-news-news-alist\n '")
497 (prin1 (wl-news-parse-news wl-news-lang) (current-buffer))
499 (narrow-to-region p (point))
501 (while (re-search-forward "^(" nil t)
502 (replace-match "\\\\(")) ; avoid font-lock confusion
505 (insert "(defconst wl-news-news-alist nil)\n\n"))
506 (let ((buffer-file-coding-system (mime-charset-to-coding-system 'x-ctext)))
507 (write-region (point-min) (point-max) out-filename)))))))
509 (defun wl-news-parse-news (lang)
512 (setq news-list (cons
513 (cons (car lang) (wl-news-parse-news-subr (car lang)))
515 (setq lang (cdr lang)))
518 (defun wl-news-parse-news-subr (lang)
519 (let ((filename (wl-news-news-file lang))
520 (reg (cadr (assoc lang wl-news-search-regexp)))
522 (if (and filename reg)
524 (insert-file-contents filename)
525 (while (re-search-forward reg nil t)
526 (let ((beg (match-beginning 0))
527 (version-tmp (split-string (match-string 1) "\\."))
528 version news-string end)
530 (setq version (append version (list (string-to-number (car version-tmp)))))
531 (setq version-tmp (cdr version-tmp)))
532 (re-search-forward "^\\(\\* \\|
\f\\)" nil t)
533 (goto-char (- (match-beginning 0) 1))
535 (setq news-string (buffer-substring beg end))
538 (list (cons version news-string))))))))
544 ;;; * MORE refine code (^_^;