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