* wl-vars.el (wl-fldmgr-add-complete-with-current-folder-list):
[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 ;;; Time-stamp: <2000-03-30 15:55:13 teranisi>
8
9 ;;;;;;;;;;;;;;;;;;;;;   DO NOT EDIT THIS FILE   ;;;;;;;;;;;;;;;;;;;;;
10 ;;;;;;;;;;;;;;;;;;;;;     INTERNAL USE ONLY     ;;;;;;;;;;;;;;;;;;;;;
11
12 ;;; Code
13
14 (defvar WLDIR "./wl")
15 (defvar ELMODIR "./elmo")
16 (defvar DOCDIR "./doc")
17 (defvar ICONDIR "./etc/icons")
18 (defvar UTILSDIR "./utils")
19 (defvar SASLDIR "./utils/sasl/lisp")
20 (defvar WL_PREFIX "wl")
21 (defvar ELMO_PREFIX "wl")
22
23 (defvar COMPRESS-SUFFIX-LIST '("" ".gz" ".Z" ".bz2"))
24
25 (defvar wl-install-utils nil
26   "if Non-nil, install `wl-utils-modules'.")
27 (defvar wl-install-sasl nil
28   "if Non-nil, install sasl utilities.")
29
30 ;;; INFO
31 (defconst wl-ja-info "wl-ja.info")
32 (defconst wl-ja-texi "wl-ja.texi")
33 (defconst wl-en-info "wl.info")
34 (defconst wl-en-texi "wl.texi")
35
36 (defvar wl-info-lang "ja"
37   "The language of info file (\"ja\" or \"en\").")
38
39 ;; for Nemacs (dirty!)
40 (or (fboundp 'file-executable-p)
41     (fset 'file-executable-p 'file-exists-p))
42
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 \f
45 (require 'cl)
46 (defvar INFODIR nil)
47
48 (condition-case () (require 'custom) (error nil))
49 ;; for wl-vars.el
50 (unless (and (fboundp 'defgroup)
51              (fboundp 'defcustom)
52              ;; ignore broken module
53              (not (featurep 'tinycustom)))
54   (require 'backquote)
55   (defmacro defgroup (&rest args))
56   (defmacro defcustom (symbol value &optional doc &rest args)
57     (let ((doc (concat "*" (or doc ""))))
58       (` (defvar (, symbol) (, value) (, doc)))))
59   )
60
61 (setq byte-compile-warnings '(free-vars unresolved callargs redefine))
62
63 ;; v18, v19
64 (if (or (boundp 'MULE)
65         (fboundp 'nemacs-version))
66     (setq max-lisp-eval-depth 400))
67
68 (condition-case () (require 'easymenu) (error nil))
69
70 (defvar config-wl-package-done nil)
71
72 (defun config-wl-package-subr ()
73   (unless config-wl-package-done
74   (setq config-wl-package-done t)
75   (setq load-path (cons (expand-file-name ".") load-path))
76   (setq load-path (cons (expand-file-name WLDIR)
77                         (cons (expand-file-name ELMODIR) load-path)))
78   (setq wl-icon-dir (expand-file-name ICONDIR))
79 ;;; load custom file if exists.
80   (load "./WL-CFG" t nil t)
81 ;;; load-path
82   (if wl-install-utils
83       (setq load-path (cons (expand-file-name UTILSDIR) load-path)))
84   (if wl-install-sasl
85       (setq load-path (cons (expand-file-name SASLDIR) load-path)))
86   (require 'install)
87   (load "./WL-ELS")
88   (condition-case ()
89       (require 'mime-setup)
90     (error (error "No MIME module was detected. Please install SEMI or tm.")))
91   (if wl-use-semi
92       (princ (concat "\nUse SEMI" 
93                      (if wl-use-luna " with LUNA\n" " without LUNA\n")))
94     (princ "\nUse tm.\n"))))
95
96 (defun config-wl-package ()
97   (config-wl-package-subr)
98   ;; LISPDIR check.
99   (let ((elispdir (car command-line-args-left)))
100     (if (string= elispdir "NONE")
101         (defvar LISPDIR (install-detect-elisp-directory))
102       (defvar LISPDIR elispdir)))
103   (princ (format "LISPDIR is %s\n\n" LISPDIR))
104   (setq command-line-args-left (cdr command-line-args-left)))
105
106
107 (defun wl-scan-source (path)
108   (let (ret)
109     (mapcar
110      '(lambda (x)
111         (mapcar '(lambda (y)
112                    (setq ret (append (list y (concat y "c")) ret)))
113                 (directory-files x nil "\\(.+\\)\\.el$" t)))
114      path)
115     ret))
116
117
118 (defun wl-uninstall (objs path)
119   ;(message (mapconcat 'identity objs " "))
120   (mapcar
121    '(lambda (x)
122       (let ((filename (expand-file-name x path)))
123         (if (and (file-exists-p filename)
124                  (file-writable-p filename))
125             (progn
126               (princ (format "%s was uninstalled.\n" filename))
127               (delete-file filename)))))
128    objs))
129
130
131 (defun compile-wl-package ()
132   ;; For nemacs byte compiler's strange behavior(?).
133   (config-wl-package)
134   (if (fboundp 'nemacs-version)
135       (load (expand-file-name "wl.el" WLDIR)))
136   (mapcar
137    '(lambda (x)
138       (compile-elisp-modules (cdr x) (car x)))
139    modules-alist))
140
141 (defun install-wl-package ()
142   (compile-wl-package)
143   (let ((wl-install-dir (expand-file-name WL_PREFIX LISPDIR))
144         (elmo-install-dir (expand-file-name ELMO_PREFIX LISPDIR)))
145     (mapcar
146      '(lambda (x)
147         (install-elisp-modules (cdr x) (car x)
148                                (if (string= (car x) ELMODIR)
149                                    elmo-install-dir
150                                  wl-install-dir)))
151      modules-alist)))
152
153
154 (defun uninstall-wl-package ()
155   (config-wl-package)
156   (let ((wl-install-dir (expand-file-name WL_PREFIX
157                                           LISPDIR))
158         (elmo-install-dir (expand-file-name ELMO_PREFIX
159                                             LISPDIR)))
160     (wl-uninstall (wl-scan-source (list WLDIR UTILSDIR SASLDIR))
161                   wl-install-dir)
162     (wl-uninstall (wl-scan-source (list ELMODIR))
163                   elmo-install-dir)
164     ))
165
166
167 (defun config-wl-package-xmas ()
168   (if (not (featurep 'xemacs))
169       (error "This directive is only for XEmacs."))
170   (config-wl-package-subr)
171   ;; PACKAGEDIR check.
172   (let (package-dir)
173     (and (setq package-dir (car command-line-args-left))
174          (if (string= "NONE" package-dir)
175              (defvar PACKAGEDIR
176                (if (boundp 'early-packages)
177                    (let ((dirs (append (if early-package-load-path
178                                            early-packages)
179                                        (if late-package-load-path
180                                            late-packages)
181                                        (if last-package-load-path
182                                            last-packages)))
183                          dir)
184                      (while (not (file-exists-p
185                                   (setq dir (car dirs))))
186                        (setq dirs (cdr dirs)))
187                      dir)))
188            (defvar PACKAGEDIR package-dir)))
189     (princ (format "PACKAGEDIR is %s\n\n" PACKAGEDIR))
190     (setq command-line-args-left (cdr command-line-args-left))))
191
192 ;; from SEMI-MK
193 (defun compile-wl-package-xmas ()
194   (config-wl-package-xmas)
195   (setq autoload-package-name "wl")
196   (add-to-list 'command-line-args-left WLDIR)
197   (batch-update-directory)
198   (add-to-list 'command-line-args-left WLDIR)
199   (Custom-make-dependencies)
200   ;; WL-AUTOLOAD-MODULES
201   (compile-elisp-modules WL-AUTOLOAD-MODULES WLDIR)
202   (mapcar
203    '(lambda (x)
204       (compile-elisp-modules (cdr x) (car x)))
205    modules-alist))
206
207 (defun install-wl-package-xmas ()
208   (compile-wl-package-xmas)
209   (let ((LISPDIR (expand-file-name "wl"
210                                     (expand-file-name "lisp"
211                                                       PACKAGEDIR)))
212         (DATADIR  (expand-file-name "wl"
213                                     (expand-file-name "etc"
214                                                       PACKAGEDIR)))
215         (INFODIR  (expand-file-name "info" PACKAGEDIR)))
216     (or (file-exists-p DATADIR)
217         (make-directory DATADIR t))
218     (or (file-exists-p INFODIR)
219         (make-directory INFODIR t))
220     ;; copy xpm files
221     (mapcar '(lambda (x) 
222                (let* ((src-file-nondirectory (file-name-nondirectory x))
223                       (dst-file (expand-file-name src-file-nondirectory
224                                                   DATADIR)))
225                  (princ (format "%s->%s\n"
226                                 x ; fullpath
227                                 dst-file))
228                  (copy-file x dst-file t)))
229             (directory-files "etc/icons" t "xpm"))
230     (mapcar '(lambda (x)
231              (install-elisp-modules (cdr x) (car x) LISPDIR))
232                   modules-alist)
233     ;; WL-AUTOLOAD-MODULES
234     (install-elisp-modules WL-AUTOLOAD-MODULES WLDIR LISPDIR)
235     ;; 
236     (wl-texinfo-format)
237     (wl-texinfo-install)))
238
239 \f
240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
241 ;;; Texinfo stuff
242
243 (defun wl-texinfo-format-file (lang)
244   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang))))
245         (texifile (symbol-value (intern (format "wl-%s-texi" lang)))))
246     (require 'wl-vars) ;; for 'wl-cs-local
247     (or (file-newer-than-file-p (expand-file-name infofile DOCDIR)
248                                 (expand-file-name texifile DOCDIR))
249         (let (obuf beg)
250           (find-file (expand-file-name texifile DOCDIR))
251           (setq obuf (current-buffer))
252           ;; texinfmt.el 2.37 or earlier can't format @direntry
253           (require 'texinfmt)
254           (unless (fboundp 'texinfo-format-direntry)
255             (goto-char (point-min))
256             (when (re-search-forward "^@direntry" nil t)
257               (replace-match "@ifinfo\nSTART-INFO-DIR-ENTRY"))
258             (when (re-search-forward "^@end direntry" nil t)
259               (replace-match "END-INFO-DIR-ENTRY\n@end ifinfo"))
260             (set-buffer-modified-p nil))
261           ;; We can't know file names if splitted.
262           (texinfo-format-buffer t)
263           ;; Emacs20.2's default is 'raw-text-unix.
264           (and (fboundp 'set-buffer-file-coding-system)
265                (set-buffer-file-coding-system wl-cs-local))
266           (save-buffer)
267           (kill-buffer (current-buffer)) ;; info
268           (kill-buffer obuf)) ;; texi
269         )))
270
271 (defun wl-texinfo-format ()
272   (unless INFODIR
273     (setq INFODIR (wl-detect-info-directory)))
274   (cond ((listp wl-info-lang)
275          (mapcar 'wl-texinfo-format-file wl-info-lang))
276         ((stringp wl-info-lang)
277          (wl-texinfo-format-file wl-info-lang))))
278
279 (defun wl-texinfo-install-file (lang)
280   (let ((infofile (symbol-value (intern (format "wl-%s-info" lang)))))
281     (install-file infofile DOCDIR INFODIR)))
282
283 (defun wl-texinfo-install ()
284   (cond ((listp wl-info-lang)
285          (mapcar 'wl-texinfo-install-file wl-info-lang))
286         ((stringp wl-info-lang)
287          (wl-texinfo-install-file wl-info-lang))))
288
289 (defun wl-primary-info-file ()
290   "Get primary info file (for wl-detect-info-directory)."
291   (cond
292    ((listp wl-info-lang)
293     (let ((wl-info-lang (car wl-info-lang)))
294       (wl-primary-info-file)))
295    ((stringp wl-info-lang)
296     (symbol-value (intern (format "wl-%s-info" wl-info-lang))))))
297
298 (defun wl-detect-info-directory ()
299   (config-wl-package-subr)
300   (if (fboundp 'nemacs-version)
301       (error "Cannot format info on Nemacs. Please use another formatter."))
302   ;; INFODIR check.
303   (require 'info)
304   (let ((infodir (car command-line-args-left))
305         (info (wl-primary-info-file))
306         previous INFODIR)
307     (setq INFODIR
308           (if (string= infodir "NONE")
309               (if (setq previous
310                         (exec-installed-p info Info-directory-list
311                                           COMPRESS-SUFFIX-LIST))
312                   ;;(progn
313                   ;;(condition-case nil (delete-file previous))
314                   (directory-file-name (file-name-directory previous));)
315                 (car Info-directory-list))
316             infodir))
317     (setq command-line-args-left (cdr command-line-args-left))
318     (princ (format "INFODIR is %s\n\n" INFODIR))
319     INFODIR))
320
321 (defun install-wl-info ()
322   (wl-texinfo-format)
323   (wl-texinfo-install))
324
325 \f
326 ;;; ToDo
327 ;;; * MORE refine code (^_^;
328
329 ;;; End