* wl/wl-demo.el (wl-demo-image-type-alist): Add bitmap for Emacs 21.
[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              (eq 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     (condition-case ()
107         (require 'mime-setup)
108       (error (error "No MIME module was detected. Please install SEMI.")))
109     ;; smtp.el version check.
110     (require 'smtp)
111     (if (not (fboundp 'smtp-send-buffer))
112         (error "Please install new FLIM.  See INSTALL or INSTALL.ja."))))
113
114 (defun config-wl-pixmap-dir (&optional packagedir)
115   "Examine pixmap directory where icon files should go."
116   (let ((pixmap-dir (car command-line-args-left)))
117     (defvar PIXMAPDIR
118       (if (string= pixmap-dir "NONE")
119           (if packagedir
120               (expand-file-name "etc/wl/" packagedir)
121             (expand-file-name "wl/icons/" data-directory))
122         pixmap-dir)))
123   (if PIXMAPDIR
124       (princ (format "PIXMAPDIR is %s\n" PIXMAPDIR)))
125   (setq command-line-args-left (cdr command-line-args-left)))
126
127 (defun config-wl-package ()
128   (config-wl-package-subr)
129   ;; LISPDIR check.
130   (let ((elispdir (car command-line-args-left)))
131     (if (string= elispdir "NONE")
132         (defvar LISPDIR (install-detect-elisp-directory))
133       (defvar LISPDIR elispdir)))
134   (princ (format "LISPDIR is %s\n" LISPDIR))
135   (setq command-line-args-left (cdr command-line-args-left))
136   ;; PIXMAPDIR check.
137   (config-wl-pixmap-dir)
138   (princ "\n"))
139
140 (defun test-wl ()
141   "Run test suite for developer."
142   (config-wl-package)
143   (require 'lunit)
144   (let ((files (directory-files "tests" t "^test-.*\\.el$"))
145         (suite (lunit-make-test-suite)))
146     (while files
147       (if (file-regular-p (car files))
148           (progn
149             (load-file (car files))
150             (lunit-test-suite-add-test
151              suite (lunit-make-test-suite-from-class
152                     (intern (file-name-sans-extension
153                              (file-name-nondirectory (car files))))))))
154       (setq files (cdr files)))
155     (lunit suite)))
156
157 (defun check-wl ()
158   "Check user environment.  Not for developer."
159   (config-wl-package)
160   (require 'lunit)
161   (let ((files (directory-files "tests" t "^check-.*\\.el$"))
162         (suite (lunit-make-test-suite)))
163     (while files
164       (if (file-regular-p (car files))
165           (progn
166             (load-file (car files))
167             (lunit-test-suite-add-test
168              suite (lunit-make-test-suite-from-class
169                     (intern (file-name-sans-extension
170                              (file-name-nondirectory (car files))))))))
171       (setq files (cdr files)))
172     (lunit suite)))
173
174 (defun wl-scan-source (path)
175   (let (ret)
176     (mapcar
177      '(lambda (x)
178         (mapcar '(lambda (y)
179                    (setq ret (append (list y (concat y "c")) ret)))
180                 (directory-files x nil "\\(.+\\)\\.el$" t)))
181      path)
182     ret))
183
184
185 (defun wl-uninstall (objs path)
186   ;(message (mapconcat 'identity objs " "))
187   (mapcar
188    '(lambda (x)
189       (let ((filename (expand-file-name x path)))
190         (if (and (file-exists-p filename)
191                  (file-writable-p filename))
192             (progn
193               (princ (format "%s was uninstalled.\n" filename))
194               (delete-file filename)))))
195    objs))
196
197
198 (defun compile-wl-package ()
199   (config-wl-package)
200   (mapcar
201    '(lambda (x)
202       (compile-elisp-modules (cdr x) (car x)))
203    modules-alist))
204
205 (defun install-wl-icons ()
206   (if (not (file-directory-p PIXMAPDIR))
207       (make-directory PIXMAPDIR t))
208   (let* ((case-fold-search t)
209          (icons (directory-files ICONDIR t
210                                  (cond ((featurep 'xemacs)
211                                         "\\.x[bp]m$")
212                                        ((and (boundp 'emacs-major-version)
213                                              (>= emacs-major-version 21))
214                                         "\\.img$\\|\\.x[bp]m$")
215                                        ((featurep 'mule)
216                                         "\\.img$\\|\\.xbm$"))))
217          icon dest)
218     (while icons
219       (setq icon (car icons)
220             icons (cdr icons)
221             dest (expand-file-name (file-name-nondirectory icon) PIXMAPDIR))
222       (princ (format "%s->%s\n" icon dest))
223       (copy-file icon dest t))))
224
225 (defun install-wl-package ()
226   (compile-wl-package)
227   (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
228         (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
229     (mapcar
230      '(lambda (x)
231         (install-elisp-modules (cdr x) (car x)
232                                (if (string= (car x) ELMODIR)
233                                    elmo-install-dir
234                                  wl-install-dir)))
235      modules-alist))
236   (if PIXMAPDIR
237       (install-wl-icons)))
238
239
240 (defun uninstall-wl-package ()
241   (config-wl-package)
242   (let ((wl-install-dir (expand-file-name WL_PREFIX
243                                           LISPDIR))
244         (elmo-install-dir (expand-file-name ELMO_PREFIX
245                                             LISPDIR)))
246     (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR))
247                   wl-install-dir)
248     (wl-uninstall (wl-scan-source (list ELMODIR))
249                   elmo-install-dir))
250   (if PIXMAPDIR
251       (let* ((case-fold-search t)
252              (icons (directory-files PIXMAPDIR t "\\.x[bp]m$"))
253              icon)
254         (while icons
255           (setq icon (car icons)
256                 icons (cdr icons))
257           (if (and (file-exists-p icon)
258                    (file-writable-p icon))
259               (progn
260                 (princ (format "%s was uninstalled.\n" icon))
261                 (delete-file icon)))))))
262
263
264 (defun config-wl-package-xmas ()
265   (if (not (featurep 'xemacs))
266       (error "This directive is only for XEmacs."))
267   (config-wl-package-subr)
268   ;; PACKAGEDIR check.
269   (let (package-dir)
270     (and (setq package-dir (car command-line-args-left))
271          (if (string= "NONE" package-dir)
272              (defvar PACKAGEDIR
273                (if (boundp 'early-packages)
274                    (let ((dirs (append (if early-package-load-path
275                                            early-packages)
276                                        (if late-package-load-path
277                                            late-packages)
278                                        (if last-package-load-path
279                                            last-packages)))
280                          dir)
281                      (while (not (file-exists-p
282                                   (setq dir (car dirs))))
283                        (setq dirs (cdr dirs)))
284                      dir)))
285            (defvar PACKAGEDIR package-dir)))
286     (princ (format "PACKAGEDIR is %s\n" PACKAGEDIR))
287     (setq command-line-args-left (cdr command-line-args-left)))
288   ;; PIXMAPDIR check.
289   (config-wl-pixmap-dir PACKAGEDIR)
290   (princ "\n"))
291
292 ;; from SEMI-MK
293 (defun compile-wl-package-xmas ()
294   (config-wl-package-xmas)
295   (setq autoload-package-name "wl")
296   (add-to-list 'command-line-args-left WLDIR)
297   (batch-update-directory)
298   (add-to-list 'command-line-args-left WLDIR)
299   (Custom-make-dependencies)
300   ;; WL-AUTOLOAD-MODULES
301   (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
302   (mapcar
303    '(lambda (x)
304       (compile-elisp-modules (cdr x) (car x)))
305    modules-alist))
306
307 (defun install-wl-package-xmas ()
308   (compile-wl-package-xmas)
309   (let ((LISPDIR (expand-file-name "wl"
310                                     (expand-file-name "lisp"
311                                                       PACKAGEDIR)))
312         (DATADIR  (expand-file-name "wl"
313                                     (expand-file-name "etc"
314                                                       PACKAGEDIR)))
315         (INFODIR  (expand-file-name "info" PACKAGEDIR)))
316     (or (file-exists-p DATADIR)
317         (make-directory DATADIR t))
318     (or (file-exists-p INFODIR)
319         (make-directory INFODIR t))
320     ;; copy xpm files
321     (install-wl-icons)
322
323     (mapcar '(lambda (x)
324                (install-elisp-modules (cdr x) (car x) LISPDIR))
325             modules-alist)
326     ;; WL-AUTOLOAD-MODULES
327     (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
328     ;;
329     (wl-texinfo-format)
330     (wl-texinfo-install)))
331
332 \f
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 ;;; Texinfo stuff
335
336 (defun wl-texinfo-format-file (lang)
337   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang))))
338         (texifile (symbol-value (intern (format "wl-%s-texi" lang)))))
339     (require 'wl-vars) ;; for 'wl-cs-local
340     (or (file-newer-than-file-p (expand-file-name infofile DOCDIR)
341                                 (expand-file-name texifile DOCDIR))
342         (let (obuf beg)
343           ;; Support old texinfmt.el
344           (require 'ptexinfmt (expand-file-name "ptexinfmt.el" UTILSDIR))
345           (find-file (expand-file-name texifile DOCDIR))
346           (setq obuf (current-buffer))
347           ;; We can't know file names if splitted.
348           (texinfo-format-buffer t)
349           ;; Emacs20.2's default is 'raw-text-unix.
350           (and (fboundp 'set-buffer-file-coding-system)
351                (set-buffer-file-coding-system wl-cs-local))
352           (save-buffer)
353           (kill-buffer (current-buffer)) ;; info
354           (kill-buffer obuf)) ;; texi
355         )))
356
357 (defun wl-texinfo-format ()
358   (unless INFODIR
359     (setq INFODIR (wl-detect-info-directory)))
360   (cond ((listp wl-info-lang)
361          (mapcar 'wl-texinfo-format-file wl-info-lang))
362         ((stringp wl-info-lang)
363          (wl-texinfo-format-file wl-info-lang))))
364
365 (defun wl-texinfo-install-file (lang)
366   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang)))))
367     (install-file infofile DOCDIR INFODIR)))
368
369 (defun wl-texinfo-install ()
370   (cond ((listp wl-info-lang)
371          (mapcar 'wl-texinfo-install-file wl-info-lang))
372         ((stringp wl-info-lang)
373          (wl-texinfo-install-file wl-info-lang))))
374
375 (defun wl-primary-info-file ()
376   "Get primary info file (for wl-detect-info-directory)."
377   (cond
378    ((listp wl-info-lang)
379     (let ((wl-info-lang (car wl-info-lang)))
380       (wl-primary-info-file)))
381    ((stringp wl-info-lang)
382     (symbol-value (intern (format "wl-%s-info" wl-info-lang))))))
383
384 (defun wl-detect-info-directory ()
385   (config-wl-package-subr)
386   ;; INFODIR check.
387   (require 'info)
388   (if (fboundp 'info-initialize)
389       (info-initialize))
390   (let ((infodir (car command-line-args-left))
391         (info (wl-primary-info-file))
392         previous INFODIR)
393     (setq INFODIR
394           (if (string= infodir "NONE")
395               (if (setq previous
396                         (exec-installed-p info Info-directory-list
397                                           COMPRESS-SUFFIX-LIST))
398                   ;;(progn
399                   ;;(condition-case nil (delete-file previous))
400                   (directory-file-name (file-name-directory previous));)
401                 (car Info-directory-list))
402             infodir))
403     (setq command-line-args-left (cdr command-line-args-left))
404     (princ (format "INFODIR is %s\n\n" INFODIR))
405     INFODIR))
406
407 (defun install-wl-info ()
408   (wl-texinfo-format)
409   (wl-texinfo-install))
410
411 \f
412 ;;; ToDo
413 ;;; * MORE refine code (^_^;
414
415 ;;; End