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