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