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