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