442
|
1 ;;; update-elc-2.el --- Recompile remaining .el files, post-dumping
|
|
2
|
|
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
|
1261
|
4 ;; Copyright (C) 2000, 2003 Ben Wing.
|
442
|
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
|
1261
|
49 ;; Help debug problems.
|
|
50 (setq stack-trace-on-error t
|
|
51 load-always-display-messages t)
|
|
52
|
442
|
53 (defvar update-elc-ignored-dirs
|
|
54 `("." ".." "CVS" "SCCS" "RCS" ,@(unless (featurep 'mule) '("mule"))))
|
|
55
|
|
56 (defvar update-elc-ignored-files
|
|
57 ;; note: entries here are regexps
|
|
58 '("^," ;; #### huh?
|
444
|
59 "^paths\\.el$"
|
|
60 "^loadup\\.el$"
|
|
61 "^loadup-el\\.el$"
|
|
62 "^update-elc\\.el$"
|
|
63 "^update-elc-2\\.el$"
|
|
64 "^dumped-lisp\\.el$"
|
|
65 "^make-docfile\\.el$"
|
|
66 "^site-start\\.el$"
|
|
67 "^site-load\\.el$"
|
|
68 "^site-init\\.el$"
|
|
69 "^version\\.el$"
|
|
70 "^very-early-lisp\\.el$"))
|
442
|
71
|
1298
|
72 (defvar dirfiles-table (make-hash-table :test 'equal))
|
|
73
|
442
|
74 ;; SEEN accumulates the list of already-handled dirs.
|
|
75 (defun do-update-elc-2 (dir compile-stage-p seen)
|
|
76 (setq dir (file-name-as-directory dir))
|
|
77 ;; Only scan this sub-tree if we haven't been here yet.
|
|
78 (unless (member (file-truename dir) seen)
|
|
79 (push (file-truename dir) seen)
|
|
80
|
1298
|
81 (let ((files (or (gethash dir dirfiles-table)
|
|
82 (directory-files dir t nil t))))
|
|
83
|
|
84 ;; Do this directory.
|
|
85 (if compile-stage-p
|
|
86 ;; Stage 2: Recompile necessary .els
|
|
87 (dolist (file files)
|
|
88 (when (string-match "\\.el$" file)
|
|
89 (let ((file-c (concat file "c")))
|
|
90 (when (and (not (member file-c files))
|
|
91 ;; no need to check for out-of-date-ness because
|
|
92 ;; that was already done, and .elc removed.
|
|
93 (let (ignore)
|
|
94 (mapcar
|
|
95 #'(lambda (regexp)
|
|
96 (if (string-match
|
|
97 regexp
|
|
98 (file-name-nondirectory file))
|
|
99 (setq ignore t)))
|
|
100 update-elc-ignored-files)
|
|
101 (not ignore)))
|
|
102 (byte-compile-file file)))))
|
442
|
103
|
1298
|
104 ;; Stage 1.
|
|
105 ;; Remove out-of-date elcs
|
|
106 (let (deleted)
|
|
107 (dolist (file files)
|
|
108 (when (string-match "\\.el$" file)
|
|
109 (let ((file-c (concat file "c")))
|
|
110 (when (and (member file-c files)
|
|
111 (file-newer-than-file-p file file-c))
|
|
112 (message "Removing out-of-date %s" file-c)
|
|
113 (delete-file file-c)
|
|
114 (push file-c deleted)))))
|
442
|
115
|
1298
|
116 ;; Remove elcs without corresponding el
|
|
117 (dolist (file-c files)
|
|
118 (when (string-match "\\.elc$" file-c)
|
|
119 (let ((file (replace-in-string file-c "c$" "")))
|
|
120 (when (not (member file files))
|
|
121 (message "Removing %s; no corresponding .el" file-c)
|
|
122 (delete-file file-c)
|
|
123 (push file-c deleted)))))
|
442
|
124
|
1303
|
125 (setq files (set-difference files deleted :test 'equal))))
|
1298
|
126
|
|
127 (puthash dir files dirfiles-table)
|
|
128
|
|
129 ;; We descend recursively. On my Windows machine, it is much faster
|
|
130 ;; to call directory-files again to recompute than to call
|
|
131 ;; file-directory-p on each member of the files list.
|
|
132 (dolist (dir (directory-files dir t nil t 'dir))
|
|
133 (when (not (member (file-name-nondirectory dir)
|
|
134 update-elc-ignored-dirs))
|
|
135 (do-update-elc-2 dir compile-stage-p seen))))))
|
442
|
136
|
|
137 (defun batch-update-elc-2 ()
|
|
138 (defvar command-line-args-left)
|
|
139 (unless noninteractive
|
|
140 (error "`batch-update-elc-2' is to be used only with -batch"))
|
|
141 (let ((dir (car command-line-args-left)))
|
1298
|
142 ;; don't depend on being able to autoload `update-autoload-files'!
|
|
143 (load "autoload")
|
|
144 (load "bytecomp")
|
|
145 (load "byte-optimize")
|
|
146 ;; #### the API used here is deprecated, convert to one with explicit
|
|
147 ;; arguments when it is available
|
|
148 ;; update-elc.el signals us to rebuild the autoloads when necessary.
|
|
149 ;; in some cases it will rebuild the autoloads itself, but doing it this
|
|
150 ;; way is slow, so we avoid it when possible.
|
|
151 (when (file-exists-p "../src/REBUILD_AUTOLOADS")
|
|
152 (let ((generated-autoload-file (expand-file-name "auto-autoloads.el" dir))
|
|
153 (autoload-package-name "auto")) ; feature prefix
|
|
154 (update-autoload-files (list dir))
|
|
155 (byte-recompile-file generated-autoload-file 0))
|
|
156 (when (featurep 'mule)
|
|
157 (let* ((muledir (expand-file-name "../lisp/mule" (file-truename dir)))
|
|
158 (generated-autoload-file
|
|
159 (expand-file-name "auto-autoloads.el" muledir))
|
|
160 (autoload-package-name "mule")) ; feature prefix
|
|
161 (update-autoload-files (list muledir))
|
|
162 (byte-recompile-file generated-autoload-file 0))))
|
|
163 (when (featurep 'modules)
|
|
164 (let* ((moddir (expand-file-name "../modules" (file-truename dir)))
|
|
165 (generated-autoload-file
|
|
166 (expand-file-name "auto-autoloads.el" moddir))
|
|
167 (autoload-package-name "modules")) ; feature prefix
|
|
168 (update-autoload-files
|
|
169 (delete (concat (file-name-as-directory moddir) ".")
|
|
170 (delete (concat (file-name-as-directory moddir) "..")
|
|
171 (directory-files moddir t nil nil 0)))
|
|
172 t)
|
|
173 (byte-recompile-file generated-autoload-file 0)))
|
|
174 ;; now load the (perhaps newly rebuilt) autoloads; we were called with
|
|
175 ;; -no-autoloads so they're not already loaded.
|
|
176 (load "../lisp/auto-autoloads")
|
|
177 (when (featurep 'mule)
|
|
178 (load "../lisp/mule/auto-autoloads"))
|
442
|
179 ;; We remove all the bad .elcs before any byte-compilation, because
|
|
180 ;; there may be dependencies between one .el and another (even across
|
|
181 ;; directories), and we don't want to load an out-of-date .elc while
|
|
182 ;; byte-compiling a file.
|
|
183 (message "Removing old or spurious .elcs in directory tree `%s'..." dir)
|
|
184 (do-update-elc-2 dir nil nil)
|
|
185 (message "Removing old or spurious .elcs in directory tree `%s'...done"
|
|
186 dir)
|
|
187 (message "Recompiling updated .els in directory tree `%s'..." dir)
|
|
188 (do-update-elc-2 dir t nil)
|
528
|
189 (message "Recompiling updated .els in directory tree `%s'...done" dir)
|
|
190 ;; likewise here.
|
|
191 (load "cus-dep")
|
|
192 (Custom-make-dependencies dir)
|
|
193 (byte-recompile-file (expand-file-name "custom-load.el" dir) 0)
|
|
194 (when (featurep 'mule)
|
|
195 (Custom-make-dependencies (expand-file-name "mule" dir))
|
|
196 (byte-recompile-file (expand-file-name "mule/custom-load.el" dir) 0))
|
|
197 )
|
442
|
198 (setq command-line-args-left nil))
|
|
199
|
444
|
200 ;;; update-elc-2.el ends here
|