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