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