* wl-summary.el (wl-summary-suspend): New function.
[elisp/wanderlust.git] / WL-MK
1 ;;; -*- Emacs-Lisp -*-
2 ;;; WL-MK for byte-compile, install, uninstall
3 ;;;
4 ;;; Original by OKUNISHI Fujikazu <fuji0924@mbox.kyoto-inet.or.jp>
5 ;;; Modified by Yuuichi Teranishi <teranisi@gohome.org>
6
7 ;;;;;;;;;;;;;;;;;;;;;   DO NOT EDIT THIS FILE   ;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;;     INTERNAL USE ONLY     ;;;;;;;;;;;;;;;;;;;;;
9
10 ;;; Code
11
12 (defvar WLDIR "./wl")
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")
19
20 (defvar COMPRESS-SUFFIX-LIST '("" ".gz" ".Z" ".bz2"))
21
22 (defvar wl-install-utils nil
23   "If Non-nil, install `wl-utils-modules'.")
24
25 ;;; INFO
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")
30
31 (defvar wl-info-lang '("ja" "en")
32   "The language of info file (\"ja\" or \"en\").")
33
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 \f
36 (require 'cl)
37 (defvar INFODIR nil)
38
39 (condition-case () (require 'custom) (error nil))
40 ;; for wl-vars.el
41 (unless (and (fboundp 'defgroup)
42              (fboundp 'defcustom)
43              ;; ignore broken module
44              (not (featurep 'tinycustom)))
45   (when (and (boundp 'emacs-major-version)
46              (= emacs-major-version 19)
47              (>= emacs-minor-version 29))
48     (message "%s" "
49   Warning: You don't seem to have \"new custom\" package installed.
50            See README file of APEL package for more information.
51 "))
52   (require 'backquote)
53   (defmacro defgroup (&rest args))
54   (defmacro defcustom (symbol value &optional doc &rest args)
55     (let ((doc (concat "*" (or doc ""))))
56       (` (defvar (, symbol) (, value) (, doc))))))
57
58 (load "bytecomp" nil t)
59
60 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
61   ;; Bind defcustom'ed variables.
62   (put 'custom-declare-variable 'byte-hunk-handler
63        'byte-compile-file-form-custom-declare-variable)
64   (defun byte-compile-file-form-custom-declare-variable (form)
65     (if (memq 'free-vars byte-compile-warnings)
66         (setq byte-compile-bound-variables
67               (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
68     form))
69
70 (condition-case nil
71     (char-after)
72   (wrong-number-of-arguments
73    ;; Optimize byte code for `char-after'.
74    (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
75    (defun byte-optimize-char-after (form)
76      (if (null (cdr form))
77          '(char-after (point))
78        form))))
79
80 (setq byte-compile-warnings '(free-vars unresolved callargs redefine))
81
82 ;; v18, v19
83 (if (boundp 'MULE)
84     (setq max-lisp-eval-depth 400))
85
86 ;; FIXME: it is currently needed to byte-compile with Emacs 21.
87 (setq recursive-load-depth-limit nil)
88
89 (condition-case () (require 'easymenu) (error nil))
90
91 (defvar config-wl-package-done nil)
92
93 (defun config-wl-package-subr ()
94   (unless config-wl-package-done
95     (setq config-wl-package-done t)
96     (setq load-path (cons (expand-file-name ".") load-path))
97     (setq load-path (cons (expand-file-name WLDIR)
98                           (cons (expand-file-name ELMODIR) load-path)))
99     ;; load custom file if exists.  `WL-CFG.el' override for committer.
100     (load "./WL-CFG" t nil nil)
101     ;; load-path
102     (if wl-install-utils
103         (setq load-path (cons (expand-file-name UTILSDIR) load-path)))
104     (require 'install)
105     (load "./WL-ELS" nil nil t)
106     ;; product.el version check
107     (require 'product)
108     (if (not (fboundp 'product-version-as-string))
109         (error "Please install new APEL.  See INSTALL or INSTALL.ja"))
110     ;; smtp.el version check.
111     (require 'smtp)
112     (if (not (fboundp 'smtp-send-buffer))
113         (error "Please install new FLIM.  See INSTALL or INSTALL.ja"))
114     (condition-case ()
115         (require 'mime-setup)
116       (error (error "Cannot load `mime-setup'.  Please install SEMI")))))
117
118 (defun config-wl-pixmap-dir (&optional packagedir)
119   "Examine pixmap directory where icon files should go."
120   (let ((pixmap-dir (car command-line-args-left)))
121     (defvar PIXMAPDIR
122       (if (string= pixmap-dir "NONE")
123           (if packagedir
124               (expand-file-name "etc/wl/" packagedir)
125             (expand-file-name "wl/icons/" data-directory))
126         pixmap-dir)))
127   (if PIXMAPDIR
128       (princ (format "PIXMAPDIR is %s\n" PIXMAPDIR)))
129   (setq command-line-args-left (cdr command-line-args-left)))
130
131 (defun config-wl-package ()
132   (config-wl-package-subr)
133   ;; LISPDIR check.
134   (let ((elispdir (car command-line-args-left)))
135     (if (string= elispdir "NONE")
136         (defvar LISPDIR (install-detect-elisp-directory))
137       (defvar LISPDIR elispdir)))
138   (princ (format "LISPDIR is %s\n" LISPDIR))
139   (setq command-line-args-left (cdr command-line-args-left))
140   ;; PIXMAPDIR check.
141   (config-wl-pixmap-dir)
142   (princ "\n"))
143
144 (defun update-version ()
145   "Update version number of documents."
146   (config-wl-package)
147   (load-file "elmo/elmo-version.el")
148   (let ((version (mapconcat
149                   'number-to-string
150                   (product-version (product-find 'elmo-version))
151                   ".")))
152     (princ (concat "Update version number to " version "\n"))
153     ;; generate version.tex
154     (with-temp-buffer
155       (insert "\\def\\versionnumber{" version "}\n")
156       (write-region (point-min) (point-max) (expand-file-name
157                                              "version.tex" "doc")))
158     ;; generate version.texi
159     (with-temp-buffer
160       (insert "@set VERSION " version "\n")
161       (write-region (point-min) (point-max) (expand-file-name
162                                              "version.texi" "doc")))))
163
164 (defun test-wl ()
165   "Run test suite for developer."
166   (config-wl-package)
167   (require 'lunit)
168   (let ((files (directory-files "tests" t "^test-.*\\.el$"))
169         (suite (lunit-make-test-suite)))
170     (while files
171       (if (file-regular-p (car files))
172           (progn
173             (load-file (car files))
174             (lunit-test-suite-add-test
175              suite (lunit-make-test-suite-from-class
176                     (intern (file-name-sans-extension
177                              (file-name-nondirectory (car files))))))))
178       (setq files (cdr files)))
179     (lunit suite)))
180
181 (defun check-wl ()
182   "Check user environment.  Not for developer."
183   (config-wl-package)
184   (require 'lunit)
185   (let ((files (directory-files "tests" t "^check-.*\\.el$"))
186         (suite (lunit-make-test-suite)))
187     (while files
188       (if (file-regular-p (car files))
189           (progn
190             (load-file (car files))
191             (lunit-test-suite-add-test
192              suite (lunit-make-test-suite-from-class
193                     (intern (file-name-sans-extension
194                              (file-name-nondirectory (car files))))))))
195       (setq files (cdr files)))
196     (lunit suite)))
197
198 (defun wl-scan-source (path)
199   (let (ret)
200     (mapcar
201      '(lambda (x)
202         (mapcar '(lambda (y)
203                    (setq ret (append (list y (concat y "c")) ret)))
204                 (directory-files x nil "\\(.+\\)\\.el$" t)))
205      path)
206     ret))
207
208
209 (defun wl-uninstall (objs path)
210   ;(message (mapconcat 'identity objs " "))
211   (mapcar
212    '(lambda (x)
213       (let ((filename (expand-file-name x path)))
214         (if (and (file-exists-p filename)
215                  (file-writable-p filename))
216             (progn
217               (princ (format "%s was uninstalled.\n" filename))
218               (delete-file filename)))))
219    objs))
220
221
222 (defun compile-wl-package ()
223   (config-wl-package)
224   (mapcar
225    '(lambda (x)
226       (compile-elisp-modules (cdr x) (car x)))
227    modules-alist))
228
229 (defun install-wl-icons ()
230   (if (not (file-directory-p PIXMAPDIR))
231       (make-directory PIXMAPDIR t))
232   (let* ((case-fold-search t)
233          (icons (directory-files ICONDIR t
234                                  (cond ((featurep 'xemacs)
235                                         "\\.x[bp]m$")
236                                        ((and (boundp 'emacs-major-version)
237                                              (>= emacs-major-version 21))
238                                         "\\.img$\\|\\.x[bp]m$")
239                                        ((featurep 'mule)
240                                         "\\.img$\\|\\.xbm$"))))
241          icon dest)
242     (while icons
243       (setq icon (car icons)
244             icons (cdr icons)
245             dest (expand-file-name (file-name-nondirectory icon) PIXMAPDIR))
246       (princ (format "%s->%s\n" icon dest))
247       (copy-file icon dest t))))
248
249 (defun install-wl-package ()
250   (compile-wl-package)
251   (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
252         (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
253     (mapcar
254      '(lambda (x)
255         (install-elisp-modules (cdr x) (car x)
256                                (if (string= (car x) ELMODIR)
257                                    elmo-install-dir
258                                  wl-install-dir)))
259      modules-alist))
260   (if PIXMAPDIR
261       (install-wl-icons)))
262
263
264 (defun uninstall-wl-package ()
265   (config-wl-package)
266   (let ((wl-install-dir (expand-file-name WL_PREFIX
267                                           LISPDIR))
268         (elmo-install-dir (expand-file-name ELMO_PREFIX
269                                             LISPDIR)))
270     (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
271                   wl-install-dir)
272     (wl-uninstall (wl-scan-source (list ELMODIR))
273                   elmo-install-dir))
274   (if PIXMAPDIR
275       (let* ((case-fold-search t)
276              (icons (directory-files PIXMAPDIR t "\\.x[bp]m$"))
277              icon)
278         (while icons
279           (setq icon (car icons)
280                 icons (cdr icons))
281           (if (and (file-exists-p icon)
282                    (file-writable-p icon))
283               (progn
284                 (princ (format "%s was uninstalled.\n" icon))
285                 (delete-file icon)))))))
286
287
288 (defun config-wl-package-xmas ()
289   (if (not (featurep 'xemacs))
290       (error "This directive is only for XEmacs"))
291   (config-wl-package-subr)
292   ;; PACKAGEDIR check.
293   (let (package-dir)
294     (and (setq package-dir (car command-line-args-left))
295          (if (string= "NONE" package-dir)
296              (defvar PACKAGEDIR
297                (if (boundp 'early-packages)
298                    (let ((dirs (append (if early-package-load-path
299                                            early-packages)
300                                        (if late-package-load-path
301                                            late-packages)
302                                        (if last-package-load-path
303                                            last-packages)))
304                          dir)
305                      (while (not (file-exists-p
306                                   (setq dir (car dirs))))
307                        (setq dirs (cdr dirs)))
308                      dir)))
309            (defvar PACKAGEDIR package-dir)))
310     (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
311     (setq command-line-args-left (cdr command-line-args-left)))
312   ;; PIXMAPDIR check.
313   (config-wl-pixmap-dir PACKAGEDIR)
314   (princ "\n"))
315
316 ;; from SEMI-MK
317 (defun compile-wl-package-xmas ()
318   (config-wl-package-xmas)
319   (setq autoload-package-name "wl")
320   (add-to-list 'command-line-args-left WLDIR)
321   (batch-update-directory)
322   (add-to-list 'command-line-args-left WLDIR)
323   (Custom-make-dependencies)
324   ;; WL-AUTOLOAD-MODULES
325   (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
326   (mapcar
327    '(lambda (x)
328       (compile-elisp-modules (cdr x) (car x)))
329    modules-alist))
330
331 (defun install-wl-package-xmas ()
332   (compile-wl-package-xmas)
333   (let ((LISPDIR (expand-file-name "wl"
334                                     (expand-file-name "lisp"
335                                                       PACKAGEDIR)))
336         (DATADIR  (expand-file-name "wl"
337                                     (expand-file-name "etc"
338                                                       PACKAGEDIR)))
339         (INFODIR  (expand-file-name "info" PACKAGEDIR)))
340     (or (file-exists-p DATADIR)
341         (make-directory DATADIR t))
342     (or (file-exists-p INFODIR)
343         (make-directory INFODIR t))
344     ;; copy xpm files
345     (install-wl-icons)
346
347     (mapcar '(lambda (x)
348                (install-elisp-modules (cdr x) (car x) LISPDIR))
349             modules-alist)
350     ;; WL-AUTOLOAD-MODULES
351     (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
352     ;;
353     (wl-texinfo-format)
354     (wl-texinfo-install)))
355
356 \f
357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
358 ;;; Texinfo stuff
359
360 (defun wl-texinfo-format-file (lang)
361   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang))))
362         (texifile (symbol-value (intern (format "wl-%s-texi" lang)))))
363     (require 'wl-vars) ;; for 'wl-cs-local
364     (or (file-newer-than-file-p (expand-file-name infofile DOCDIR)
365                                 (expand-file-name texifile DOCDIR))
366         (let (obuf beg)
367           ;; Support old texinfmt.el
368           (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
369           (find-file (expand-file-name texifile DOCDIR))
370           (setq obuf (current-buffer))
371           ;; We can't know file names if splitted.
372           (texinfo-format-buffer t)
373           ;; Emacs20.2's default is 'raw-text-unix.
374           (and (fboundp 'set-buffer-file-coding-system)
375                (set-buffer-file-coding-system wl-cs-local))
376           (save-buffer)
377           (kill-buffer (current-buffer)) ;; info
378           (kill-buffer obuf)) ;; texi
379         )))
380
381 (defun wl-texinfo-format ()
382   (unless INFODIR
383     (setq INFODIR (wl-detect-info-directory)))
384   (cond ((listp wl-info-lang)
385          (mapcar 'wl-texinfo-format-file wl-info-lang))
386         ((stringp wl-info-lang)
387          (wl-texinfo-format-file wl-info-lang))))
388
389 (defun wl-texinfo-install-file (lang)
390   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang)))))
391     (install-file infofile DOCDIR INFODIR)))
392
393 (defun wl-texinfo-install ()
394   (cond ((listp wl-info-lang)
395          (mapcar 'wl-texinfo-install-file wl-info-lang))
396         ((stringp wl-info-lang)
397          (wl-texinfo-install-file wl-info-lang))))
398
399 (defun wl-primary-info-file ()
400   "Get primary info file (for wl-detect-info-directory)."
401   (cond
402    ((listp wl-info-lang)
403     (let ((wl-info-lang (car wl-info-lang)))
404       (wl-primary-info-file)))
405    ((stringp wl-info-lang)
406     (symbol-value (intern (format "wl-%s-info" wl-info-lang))))))
407
408 (defun wl-detect-info-directory ()
409   (config-wl-package-subr)
410   ;; INFODIR check.
411   (require 'info)
412   (if (fboundp 'info-initialize)
413       (info-initialize))
414   (let ((infodir (car command-line-args-left))
415         (info (wl-primary-info-file))
416         previous INFODIR)
417     (setq INFODIR
418           (if (string= infodir "NONE")
419               (if (setq previous
420                         (exec-installed-p info Info-directory-list
421                                           COMPRESS-SUFFIX-LIST))
422                   ;;(progn
423                   ;;(condition-case nil (delete-file previous))
424                   (directory-file-name (file-name-directory previous));)
425                 (car Info-directory-list))
426             infodir))
427     (setq command-line-args-left (cdr command-line-args-left))
428     (princ (format "INFODIR is %s\n\n" INFODIR))
429     INFODIR))
430
431 (defun install-wl-info ()
432   (wl-texinfo-format)
433   (wl-texinfo-install))
434
435 \f
436 ;;; ToDo
437 ;;; * MORE refine code (^_^;
438
439 ;;; End