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