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")
41 ("ja" "^\\* [0-9.]*
\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 compile-wl-package ()
242 (compile-elisp-modules (cdr x) (car x)))
245 (defun install-wl-icons ()
246 (if (not (file-directory-p PIXMAPDIR))
247 (make-directory PIXMAPDIR t))
248 (let* ((case-fold-search t)
249 (icons (directory-files ICONDIR nil
250 (cond ((featurep 'xemacs)
252 ((and (boundp 'emacs-major-version)
253 (>= emacs-major-version 21))
254 "\\.img$\\|\\.x[bp]m$")
256 "\\.img$\\|\\.xbm$")))))
257 (install-files icons ICONDIR PIXMAPDIR nil 'overwrite)))
259 (defun install-wl-package ()
261 (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
262 (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
265 (install-elisp-modules (cdr x) (car x)
266 (if (string= (car x) ELMODIR)
274 (defun uninstall-wl-package ()
276 (let ((wl-install-dir (expand-file-name WL_PREFIX
278 (elmo-install-dir (expand-file-name ELMO_PREFIX
280 (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
282 (wl-uninstall (wl-scan-source (list ELMODIR))
285 (let* ((case-fold-search t)
286 (icons (directory-files PIXMAPDIR t "\\.x[bp]m$"))
289 (setq icon (car icons)
291 (if (and (file-exists-p icon)
292 (file-writable-p icon))
294 (princ (format "%s was uninstalled.\n" icon))
295 (delete-file icon)))))))
298 (defun config-wl-package-xmas ()
299 (if (not (featurep 'xemacs))
300 (error "This directive is only for XEmacs"))
301 (config-wl-package-subr)
304 (and (setq package-dir (car command-line-args-left))
305 (if (string= "NONE" package-dir)
307 (if (boundp 'early-packages)
308 (let ((dirs (append (if early-package-load-path
310 (if late-package-load-path
312 (if last-package-load-path
315 (while (not (file-exists-p
316 (setq dir (car dirs))))
317 (setq dirs (cdr dirs)))
319 (defvar PACKAGEDIR package-dir)))
320 (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
321 (setq command-line-args-left (cdr command-line-args-left)))
323 (config-wl-pixmap-dir PACKAGEDIR)
327 (defun compile-wl-package-xmas ()
328 (config-wl-package-xmas)
330 (setq autoload-package-name "wl")
331 (add-to-list 'command-line-args-left WLDIR)
332 (batch-update-directory)
333 (add-to-list 'command-line-args-left WLDIR)
334 (Custom-make-dependencies)
335 ;; WL-AUTOLOAD-MODULES
336 (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
339 (compile-elisp-modules (cdr x) (car x)))
342 (defun install-wl-package-xmas ()
343 (compile-wl-package-xmas)
344 (let ((LISPDIR (expand-file-name "wl"
345 (expand-file-name "lisp"
347 (DATADIR (expand-file-name "wl"
348 (expand-file-name "etc"
350 (INFODIR (expand-file-name "info" PACKAGEDIR)))
351 (or (file-exists-p DATADIR)
352 (make-directory DATADIR t))
353 (or (file-exists-p INFODIR)
354 (make-directory INFODIR t))
359 (install-elisp-modules (cdr x) (car x) LISPDIR))
361 ;; WL-AUTOLOAD-MODULES
362 (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
365 (wl-texinfo-install)))
368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371 (defun wl-texinfo-info-file (lang)
372 (symbol-value (intern (format "wl-%s-info" lang))))
374 (defun wl-texinfo-texi-file (lang)
375 (symbol-value (intern (format "wl-%s-texi" lang))))
377 (defun wl-texinfo-check-newer (lang)
378 (let ((info-file (expand-file-name (wl-texinfo-info-file lang) DOCDIR)))
380 (file-newer-than-file-p info-file
381 (expand-file-name "version.texi" DOCDIR))
382 (file-newer-than-file-p info-file
383 (expand-file-name (wl-texinfo-texi-file lang) DOCDIR)))))
385 (defun wl-texinfo-format-file (lang)
386 (require 'wl-vars) ;; for 'wl-cs-local
387 (or (wl-texinfo-check-newer lang)
389 ;; Support old texinfmt.el
390 (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
391 (find-file (expand-file-name (wl-texinfo-texi-file lang) DOCDIR))
392 (setq obuf (current-buffer))
393 ;; We can't know file names if splitted.
394 (texinfo-format-buffer t)
395 ;; Emacs20.2's default is 'raw-text-unix.
396 (and (fboundp 'set-buffer-file-coding-system)
397 (set-buffer-file-coding-system wl-cs-local))
399 (kill-buffer (current-buffer)) ;; info
400 (kill-buffer obuf)) ;; texi
403 (defun wl-texinfo-format ()
404 (wl-detect-info-directory)
405 (cond ((null wl-info-lang))
406 ((listp wl-info-lang)
407 (mapcar 'wl-texinfo-format-file wl-info-lang))
408 ((stringp wl-info-lang)
409 (wl-texinfo-format-file wl-info-lang))))
411 (defun wl-texinfo-install-file (lang)
412 (let ((infofile (wl-texinfo-info-file lang)))
413 (install-file infofile DOCDIR INFODIR nil 'overwrite)))
415 (defun wl-texinfo-install ()
416 (cond ((null wl-info-lang))
417 ((listp wl-info-lang)
418 (mapcar 'wl-texinfo-install-file wl-info-lang))
419 ((stringp wl-info-lang)
420 (wl-texinfo-install-file wl-info-lang))))
422 (defun wl-primary-info-file ()
423 "Get primary info file (for wl-detect-info-directory)."
424 (cond ((null wl-info-lang))
425 ((listp wl-info-lang)
426 (let ((wl-info-lang (car wl-info-lang)))
427 (wl-primary-info-file)))
428 ((stringp wl-info-lang)
429 (wl-texinfo-info-file wl-info-lang))))
431 (defun wl-detect-info-directory ()
432 (config-wl-package-subr)
436 (if (fboundp 'info-initialize)
439 (let ((infodir (car command-line-args-left))
440 (info (wl-primary-info-file))
443 (if (string= infodir "NONE")
445 (exec-installed-p info Info-directory-list
446 COMPRESS-SUFFIX-LIST))
447 (directory-file-name (file-name-directory previous))
448 (car Info-directory-list))
450 (setq command-line-args-left (cdr command-line-args-left))))
451 (princ (format "INFODIR is %s\n\n" INFODIR))))
453 (defun install-wl-info ()
455 (wl-texinfo-install))
458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 (defun wl-news-news-file (lang)
462 (cadr (assoc lang wl-news-news-file)))
464 (defun wl-news-check-newer (out-filename news-lang)
465 (let ((lang news-lang)
468 (if (file-newer-than-file-p
469 (wl-news-news-file (car lang)) out-filename)
471 (setq lang (cdr lang)))
474 (defun make-wl-news ()
476 (expand-file-name (concat wl-news-filename ".in") WLDIR))
478 (expand-file-name wl-news-filename WLDIR))
479 (wl-news-lang (if (listp wl-news-lang)
481 (list wl-news-lang))))
482 (if (or (file-newer-than-file-p in-filename out-filename)
483 (wl-news-check-newer out-filename wl-news-lang))
486 (insert-file-contents in-filename)
487 (goto-char (point-min))
488 (unless (re-search-forward "^;;; -\\*- news-list -\\*-" nil t)
489 (error "Invalid wl-news.el.in"))
493 (insert "(defconst wl-news-news-alist\n '")
495 (prin1 (wl-news-parse-news wl-news-lang) (current-buffer))
497 (narrow-to-region p (point))
499 (while (re-search-forward "^(" nil t)
500 (replace-match "\\\\(")) ; avoid font-lock confusion
503 (insert "(defconst wl-news-news-alist nil)\n\n"))
504 (let ((buffer-file-coding-system (mime-charset-to-coding-system 'x-ctext)))
505 (write-region (point-min) (point-max) out-filename)))))))
507 (defun wl-news-parse-news (lang)
510 (setq news-list (cons
511 (cons (car lang) (wl-news-parse-news-subr (car lang)))
513 (setq lang (cdr lang)))
516 (defun wl-news-parse-news-subr (lang)
517 (let ((filename (wl-news-news-file lang))
518 (reg (cadr (assoc lang wl-news-search-regexp)))
520 (if (and filename reg)
522 (insert-file-contents filename)
523 (while (re-search-forward reg nil t)
524 (let ((beg (match-beginning 0))
525 (version-tmp (split-string (match-string 1) "\\."))
526 version news-string end)
528 (setq version (append version (list (string-to-int (car version-tmp)))))
529 (setq version-tmp (cdr version-tmp)))
530 (re-search-forward "^\\(\\* \\|
\f\\)" nil t)
531 (goto-char (- (match-beginning 0) 1))
533 (setq news-string (buffer-substring beg end))
536 (list (cons version news-string))))))))
542 ;;; * MORE refine code (^_^;