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