(g2-UU+5B73): Add `=decomposition@hanyo-denshi'.
[chise/xemacs-chise.git.1] / lisp / update-elc-2.el
1 ;;; update-elc-2.el --- Recompile remaining .el files, post-dumping
2
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
4 ;; Copyright (C) 2000 Ben Wing.
5
6 ;; Author: Ben Wing <ben@xemacs.org>, based on cleantree.el by
7 ;;         Steven L Baur <steve@xemacs.org>
8 ;; Maintainer: XEmacs Development Team
9 ;; Keywords: internal
10
11 ;; This file is part of XEmacs.
12
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ;; 02111-1307, USA.
27
28 ;;; Synched up with: Not in FSF
29
30 ;;; Commentary:
31
32 ;; This file should be used after XEmacs has been dumped, to recompile
33 ;; all remaining out-of-date .els and clean up orphaned .elcs.  It should
34 ;; be called as
35 ;;
36 ;;   xemacs -batch -vanilla -l update-elc-2.el -f batch-update-elc-2 ${dirname}
37 ;;
38 ;; where ${dirname} is the directory tree to recompile, usually `lisp'.
39 ;;
40 ;; Note that this is very different from update-elc.el, which is called
41 ;; BEFORE dumping, handles only the files needed to dump, and is called
42 ;; from temacs instead of xemacs.
43 ;;
44 ;; The original cleantree.el had the comment: This code is derived
45 ;; from Gnus based on a suggestion by David Moore <dmoore@ucsd.edu>
46
47 ;;; Code:
48
49 (defvar update-elc-ignored-dirs
50   `("." ".." "CVS" "SCCS" "RCS" ,@(unless (featurep 'mule) '("mule"))))
51
52 (defvar update-elc-ignored-files
53   ;; note: entries here are regexps
54   '("^," ;; #### huh?
55     "^paths\\.el$"
56     "^loadup\\.el$"
57     "^loadup-el\\.el$"
58     "^update-elc\\.el$"
59     "^update-elc-2\\.el$"
60     "^dumped-lisp\\.el$"
61     "^make-docfile\\.el$"
62     "^site-start\\.el$"
63     "^site-load\\.el$"
64     "^site-init\\.el$"
65     "^version\\.el$"
66     "^very-early-lisp\\.el$"))
67
68 ;; SEEN accumulates the list of already-handled dirs.
69 (defun do-update-elc-2 (dir compile-stage-p seen)
70   (setq dir (file-name-as-directory dir))
71   ;; Only scan this sub-tree if we haven't been here yet.
72   (unless (member (file-truename dir) seen)
73     (push (file-truename dir) seen)
74
75     ;; Do this directory.
76     (if compile-stage-p
77         ;; Stage 2: Recompile necessary .els
78         (let ((files (directory-files dir t "\\.el$"))
79               file file-c)
80           (while (setq file (car files))
81             (setq files (cdr files))
82             (setq file-c (concat file "c"))
83             (when (and (file-exists-p file)
84                        (or (not (file-exists-p file-c))
85                            (file-newer-than-file-p file file-c))
86                        (let (ignore)
87                          (mapcar
88                           #'(lambda (regexp)
89                               (if (string-match regexp
90                                                 (file-name-nondirectory file))
91                                   (setq ignore t)))
92                           update-elc-ignored-files)
93                          (not ignore)))
94               (byte-compile-file file))))
95
96       ;; Stage 1.
97       ;; Remove out-of-date elcs
98       (let ((files (directory-files dir t "\\.el$"))
99             file file-c)
100         (while (setq file (car files))
101           (setq files (cdr files))
102           (setq file-c (concat file "c"))
103           (when (and (file-exists-p file-c)
104                      (file-newer-than-file-p file file-c))
105             (message "Removing out-of-date %s" file-c)
106             (delete-file file-c))))
107       ;; Remove elcs without corresponding el
108       (let ((files (directory-files dir t "\\.elc$"))
109             file file-c)
110         (while (setq file-c (car files))
111           (setq files (cdr files))
112           (setq file (replace-in-string file-c "c$" ""))
113           (when (and (file-exists-p file-c)
114                      (not (file-exists-p file)))
115             (message "Removing %s; no corresponding .el" file-c)
116             (delete-file file-c))))
117
118     ;; We descend recursively
119     (let ((dirs (directory-files dir t nil t))
120           dir)
121       (while (setq dir (pop dirs))
122         (when (and (not (member (file-name-nondirectory dir)
123                                 update-elc-ignored-dirs))
124                    (file-directory-p dir))
125           (do-update-elc-2 dir compile-stage-p seen))))
126
127     )))
128
129
130 (defun batch-update-elc-2 ()
131   (defvar command-line-args-left)
132   (unless noninteractive
133     (error "`batch-update-elc-2' is to be used only with -batch"))
134   (let ((dir (car command-line-args-left)))
135     ;; We remove all the bad .elcs before any byte-compilation, because
136     ;; there may be dependencies between one .el and another (even across
137     ;; directories), and we don't want to load an out-of-date .elc while
138     ;; byte-compiling a file.
139     (message "Removing old or spurious .elcs in directory tree `%s'..." dir)
140     (do-update-elc-2 dir nil nil)
141     (message "Removing old or spurious .elcs in directory tree `%s'...done"
142              dir)
143     (message "Recompiling updated .els in directory tree `%s'..." dir)
144     (do-update-elc-2 dir t nil)
145     (message "Recompiling updated .els in directory tree `%s'...done" dir))
146   (setq command-line-args-left nil))
147
148 ;;; update-elc-2.el ends here