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