428
|
1 ;;; update-elc.el --- Bytecompile out-of-date dumped files
|
|
2
|
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
|
442
|
4 ;; Copyright (C) 1996 Sun Microsystems, Inc.
|
1261
|
5 ;; Copyright (C) 2001, 2003 Ben Wing.
|
428
|
6
|
528
|
7 ;; Author: Ben Wing <ben@xemacs.org>
|
|
8 ;; Based On: Original by Steven L Baur <steve@xemacs.org>
|
428
|
9 ;; Maintainer: XEmacs Development Team
|
|
10 ;; Keywords: internal
|
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
15 ;; under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28
|
|
29 ;;; Synched up with: Not in FSF.
|
|
30
|
|
31 ;;; Commentary:
|
|
32
|
|
33 ;; Byte compile the .EL files necessary to dump out xemacs.
|
1261
|
34 ;; Also update the auto-autoloads.el files.
|
|
35
|
428
|
36 ;; Use this file like this:
|
|
37
|
|
38 ;; temacs -batch -l ../lisp/update-elc.el $lisp
|
|
39
|
|
40 ;; where $lisp comes from the Makefile. .elc files listed in $lisp will
|
|
41 ;; cause the corresponding .el file to be compiled. .el files listed in
|
|
42 ;; $lisp will be ignored.
|
|
43
|
|
44 ;; (the idea here is that you can bootstrap if your .ELC files
|
|
45 ;; are missing or badly out-of-date)
|
|
46
|
442
|
47 ;; See also update-elc-2.el
|
428
|
48
|
|
49 ;;; Code:
|
|
50
|
1261
|
51 ;; Help debug problems.
|
|
52 (setq stack-trace-on-error t
|
|
53 load-always-display-messages t)
|
|
54
|
428
|
55 (defvar processed nil)
|
|
56 (defvar update-elc-files-to-compile nil)
|
528
|
57 (defvar need-to-rebuild-autoloads nil)
|
|
58 (defvar need-to-rebuild-mule-autoloads nil)
|
|
59 (defvar need-to-recompile-autoloads nil)
|
|
60 (defvar need-to-recompile-mule-autoloads nil)
|
1261
|
61 (defvar undumped-exe nil)
|
1298
|
62 ;(defvar dumped-exe nil)
|
1261
|
63 (defvar dumped-exe-out-of-date-wrt-dump-files nil)
|
1298
|
64 ;(defvar dumped-exe-out-of-date-wrt-undumped-exe nil)
|
428
|
65
|
|
66 ;(setq update-elc-files-to-compile
|
|
67 ; (delq nil
|
|
68 ; (mapcar (function
|
|
69 ; (lambda (x)
|
|
70 ; (if (string-match "\.elc$" x)
|
|
71 ; (let ((src (substring x 0 -1)))
|
|
72 ; (if (file-newer-than-file-p src x)
|
|
73 ; (progn
|
|
74 ; (and (file-exists-p x)
|
|
75 ; (null (file-writable-p x))
|
|
76 ; (set-file-modes x (logior (file-modes x) 128)))
|
|
77 ; src))))))
|
|
78 ; ;; -batch gets filtered out.
|
|
79 ; (nthcdr 3 command-line-args))))
|
|
80
|
442
|
81 (let ((build-root (expand-file-name ".." invocation-directory)))
|
|
82 (setq load-path (list (expand-file-name "lisp" build-root))))
|
428
|
83
|
1261
|
84 (load "very-early-lisp.el")
|
428
|
85 (load "find-paths.el")
|
|
86 (load "packages.el")
|
|
87 (load "setup-paths.el")
|
1261
|
88 (load "dump-paths.el") ;; #### take out in my fixup ws
|
|
89
|
|
90 ;; Lisp files loaded in order to byte compile anything. If any are out of
|
|
91 ;; date, we need to load them as .el's, byte compile them, and reload as
|
|
92 ;; .elc's.
|
|
93 (defvar lisp-files-needed-for-byte-compilation
|
|
94 '("bytecomp"
|
|
95 "byte-optimize"))
|
|
96
|
1263
|
97 ;; Lisp files not in `lisp-files-needed-for-byte-compilation' that need
|
|
98 ;; early byte compilation. These are files loaded by update-elc.el in
|
|
99 ;; order to do the compilation of all the rest of the files.
|
1261
|
100 (defvar lisp-files-needing-early-byte-compilation
|
|
101 '(;"easy-mmode"
|
|
102 "autoload"
|
|
103 "shadow"
|
|
104 "cl-macs"))
|
|
105
|
|
106 (defvar unbytecompiled-lisp-files
|
|
107 '("paths.el"
|
|
108 "dumped-lisp.el"
|
|
109 "dumped-pkg-lisp.el"
|
1275
|
110 "raw-process.el"
|
1261
|
111 "version.el"
|
|
112 "very-early-lisp.el")
|
|
113 "Lisp files that should not be byte compiled.")
|
428
|
114
|
1298
|
115 (defvar lisp-files-ignored-when-checking-for-autoload-updating
|
|
116 '("custom-load.el"
|
|
117 "auto-autoloads.el")
|
|
118 "Lisp files that should not trigger auto-autoloads rebuilding.")
|
|
119
|
528
|
120 (defun update-elc-chop-extension (file)
|
|
121 (if (string-match "\\.elc?$" file)
|
|
122 (substring file 0 (match-beginning 0))
|
|
123 file))
|
428
|
124
|
528
|
125 ;; we used to call packages-list-autoloads here, but it's false generality.
|
|
126 ;; we need to handle each autoload file differently and there are only
|
|
127 ;; two of them.
|
428
|
128
|
1261
|
129 (let (preloaded-file-list site-load-packages files-to-process)
|
528
|
130
|
428
|
131 (load (expand-file-name "../lisp/dumped-lisp.el"))
|
|
132
|
442
|
133 (setq dumped-exe
|
|
134 (cond ((file-exists-p "../src/xemacs.exe") "../src/xemacs.exe")
|
|
135 ((file-exists-p "../src/xemacs") "../src/xemacs")
|
|
136 (t nil)))
|
|
137
|
1298
|
138 ;; Not currently used but might be at some point.
|
|
139 ; (let ((temacs-exe
|
|
140 ; (cond ((file-exists-p "../src/temacs.exe") "../src/temacs.exe")
|
|
141 ; ((file-exists-p "../src/temacs") "../src/temacs")
|
|
142 ; (t nil)))
|
|
143 ; (data-file
|
|
144 ; (cond ((file-exists-p "../src/xemacs.dmp") "../src/xemacs.dmp")
|
|
145 ; (t nil))))
|
1261
|
146
|
1298
|
147 ; ;; two setups here:
|
|
148 ; ;; (1) temacs.exe is undumped, dumped into xemacs.exe. Happens with
|
|
149 ; ;; unexec, but also with pdump under MS Windows native, since
|
|
150 ; ;; the dumped data is stored as a resource in the xemacs.exe
|
|
151 ; ;; executable.
|
|
152 ; ;; (2) xemacs.exe is dumped or undumped. Running `xemacs -nd' gets
|
|
153 ; ;; you the equivalent of `temacs'. Dumping creates a file
|
|
154 ; ;; `xemacs.dmp'.
|
1261
|
155
|
1298
|
156 ; (setq dumped-exe-out-of-date-wrt-undumped-exe
|
|
157 ; (cond ((not dumped-exe) t)
|
|
158 ; (temacs-exe (file-newer-than-file-p temacs-exe dumped-exe))
|
|
159 ; ((not data-file) t)
|
|
160 ; (t (file-newer-than-file-p dumped-exe data-file))))
|
|
161 ; (setq dumped-exe-exists (or (and temacs-exe dumped-exe)
|
|
162 ; (and data-file dumped-exe))))
|
1261
|
163
|
428
|
164 ;; Path setup
|
|
165 (let ((package-preloaded-file-list
|
|
166 (packages-collect-package-dumped-lisps late-package-load-path)))
|
|
167
|
|
168 (setq preloaded-file-list
|
|
169 (append package-preloaded-file-list
|
|
170 preloaded-file-list
|
|
171 packages-hardcoded-lisp)))
|
|
172
|
|
173 (load (concat default-directory "../site-packages") t t)
|
|
174 (setq preloaded-file-list
|
|
175 (append packages-hardcoded-lisp
|
|
176 preloaded-file-list
|
|
177 site-load-packages))
|
1261
|
178 ;; bytecomp, byte-optimize, autoload, etc. are mentioned specially
|
|
179 ;; in the lisp-files-need* variables.
|
|
180 (setq files-to-process (append lisp-files-needed-for-byte-compilation
|
|
181 lisp-files-needing-early-byte-compilation
|
|
182 preloaded-file-list))
|
528
|
183 (while files-to-process
|
|
184 (let* ((arg (car files-to-process))
|
|
185 (arg-is-preloaded (member arg preloaded-file-list))
|
|
186 (arg-sans-extension (update-elc-chop-extension arg))
|
|
187 (full-arg (locate-library arg-sans-extension))
|
|
188 (full-arg-sans-extension
|
|
189 (if (null full-arg)
|
|
190 (progn
|
|
191 (print (format "Error: Library file %s not found" arg))
|
1261
|
192 (backtrace)
|
528
|
193 ;; Uncomment in case of trouble
|
|
194 ;;(print (format "late-packages: %S" late-packages))
|
|
195 ;;(print (format "guessed-roots: %S"
|
|
196 ;; (paths-find-emacs-roots
|
|
197 ;; invocation-directory invocation-name)))
|
|
198 (kill-emacs))
|
|
199 (update-elc-chop-extension full-arg)))
|
|
200 (full-arg-el (concat full-arg-sans-extension ".el"))
|
|
201 (full-arg-elc (concat full-arg-sans-extension ".elc"))
|
1261
|
202 (full-arg-dir (file-name-directory full-arg-el)))
|
528
|
203
|
|
204 ;; (print full-arg-el)
|
442
|
205
|
|
206 ;; now check if .el or .elc is newer than the dumped exe.
|
|
207 ;; if so, need to redump.
|
528
|
208 (when (and dumped-exe arg-is-preloaded
|
1298
|
209 ;; no need to check for existence of either of the files
|
|
210 ;; because of the definition of file-newer-than-file-p.
|
|
211 (or (file-newer-than-file-p full-arg-el dumped-exe)
|
|
212 (file-newer-than-file-p full-arg-elc dumped-exe)))
|
1261
|
213 (setq dumped-exe-out-of-date-wrt-dump-files t))
|
528
|
214
|
|
215 (if (and (not (member (file-name-nondirectory arg)
|
1261
|
216 unbytecompiled-lisp-files))
|
528
|
217 (not (member full-arg-el processed))
|
1298
|
218 ;; no need to check for existence of either of the files
|
|
219 ;; because of the definition of file-newer-than-file-p.
|
|
220 (file-newer-than-file-p full-arg-el full-arg-elc))
|
528
|
221 (setq processed (cons full-arg-el processed)))
|
|
222
|
|
223 (setq files-to-process (cdr files-to-process))))
|
442
|
224
|
1261
|
225 ;; Check if we need to rebuild the auto-autoloads.el files -- that is,
|
|
226 ;; if ANY .el files have changed.
|
|
227 (let ((dirs-to-check '("../lisp" "../lisp/mule")))
|
|
228 (while dirs-to-check
|
|
229 (let* ((dir (car dirs-to-check))
|
|
230 (full-dir (expand-file-name dir))
|
|
231 (all-files-in-dir (directory-files full-dir t "\\.el$" nil t))
|
|
232 (autoload-file
|
|
233 (expand-file-name "auto-autoloads.el" full-dir))
|
|
234 (autoload-is-mule (equal dir "../lisp/mule")))
|
|
235 (while all-files-in-dir
|
|
236 (let* ((full-arg (car all-files-in-dir)))
|
1298
|
237 ;; custom-load.el always gets regenerated so don't let that
|
|
238 ;; trigger us.
|
|
239 (when (and (not
|
|
240 (member
|
|
241 (file-name-nondirectory full-arg)
|
|
242 lisp-files-ignored-when-checking-for-autoload-updating
|
|
243 ))
|
|
244 (file-newer-than-file-p full-arg autoload-file))
|
1261
|
245 (if autoload-is-mule
|
|
246 (setq need-to-rebuild-mule-autoloads t)
|
|
247 (setq need-to-rebuild-autoloads t))))
|
|
248 (setq all-files-in-dir (cdr all-files-in-dir))))
|
|
249 (setq dirs-to-check (cdr dirs-to-check))))
|
|
250
|
|
251 (if dumped-exe-out-of-date-wrt-dump-files
|
442
|
252 (condition-case nil
|
|
253 (write-region-internal "foo" nil "../src/NEEDTODUMP")
|
|
254 (file-error nil)))
|
|
255
|
|
256 )
|
428
|
257
|
528
|
258 (when (or need-to-rebuild-autoloads
|
1298
|
259 ;; no real need for the following check either, because if the file
|
|
260 ;; doesn't exist, need-to-rebuild-autoloads gets set above. but
|
|
261 ;; it's only one call, so it won't slow things down much and it keeps
|
|
262 ;; the logic cleaner.
|
528
|
263 (not (file-exists-p "../lisp/auto-autoloads.el"))
|
1298
|
264 ;; no need to check for file-exists of .elc due to definition
|
|
265 ;; of file-newer-than-file-p
|
528
|
266 (file-newer-than-file-p "../lisp/auto-autoloads.el"
|
|
267 "../lisp/auto-autoloads.elc"))
|
|
268 (setq need-to-recompile-autoloads t))
|
|
269
|
|
270 (when (or need-to-rebuild-mule-autoloads
|
1298
|
271 ;; not necessary but ... see comment above.
|
528
|
272 (not (file-exists-p "../lisp/mule/auto-autoloads.el"))
|
1298
|
273 ;; no need to check for file-exists of .elc due to definition
|
|
274 ;; of file-newer-than-file-p
|
528
|
275 (file-newer-than-file-p "../lisp/mule/auto-autoloads.el"
|
|
276 "../lisp/mule/auto-autoloads.elc"))
|
|
277 (setq need-to-recompile-mule-autoloads t))
|
|
278
|
|
279 (when (not (featurep 'mule))
|
|
280 ;; sorry charlie.
|
|
281 (setq need-to-rebuild-mule-autoloads nil
|
|
282 need-to-recompile-mule-autoloads nil))
|
|
283
|
428
|
284 (setq update-elc-files-to-compile (append update-elc-files-to-compile
|
622
|
285 (nreverse processed)))
|
428
|
286
|
1261
|
287 ;(print update-elc-files-to-compile)
|
428
|
288
|
1261
|
289 (let ((do-autoload-commands
|
|
290 (append
|
|
291 (if (or need-to-rebuild-autoloads
|
|
292 need-to-rebuild-mule-autoloads)
|
|
293 '("-l" "autoload"))
|
|
294 (if need-to-rebuild-autoloads
|
|
295 '("-f" "autoload-update-directory-autoloads"
|
|
296 "auto" "../lisp"))
|
|
297 (if need-to-rebuild-mule-autoloads
|
|
298 '("-f" "autoload-update-directory-autoloads"
|
|
299 "mule" "../lisp/mule"))
|
|
300 (if need-to-recompile-autoloads
|
|
301 '("-f" "batch-byte-compile-one-file"
|
|
302 "../lisp/auto-autoloads.el"))
|
|
303 (if need-to-recompile-mule-autoloads
|
|
304 '("-f" "batch-byte-compile-one-file"
|
|
305 "../lisp/mule/auto-autoloads.el")))))
|
1298
|
306 (condition-case nil
|
|
307 (delete-file "../src/REBUILD_AUTOLOADS")
|
|
308 (file-error nil))
|
1261
|
309 (cond ((and (not update-elc-files-to-compile)
|
|
310 (not need-to-rebuild-autoloads)
|
|
311 (not need-to-rebuild-mule-autoloads)
|
|
312 (not need-to-recompile-autoloads)
|
|
313 (not need-to-recompile-mule-autoloads))
|
|
314 ;; (1) Nothing to do at all. BYTECOMPILE_CHANGE is used (only by
|
|
315 ;; the Unix makefile) to indicate whether some files needed
|
|
316 ;; for dump got recompiled, and hence the executable must be
|
|
317 ;; redumped. We remove it if there were no files to compile.
|
|
318 (condition-case nil
|
|
319 (delete-file "../src/BYTECOMPILE_CHANGE")
|
|
320 (file-error nil)))
|
1298
|
321 ((not update-elc-files-to-compile)
|
1261
|
322 ;; (2) We have no files to byte-compile, but we do need to
|
1298
|
323 ;; regenerate and compile the auto-autoloads file, so signal
|
|
324 ;; update-elc-2 to do it. This is much faster than loading
|
|
325 ;; all the .el's and doing it here. (We only need to rebuild
|
|
326 ;; the autoloads here when we have files to compile, since
|
|
327 ;; they may depend on the updated autoloads.)
|
|
328 (condition-case nil
|
|
329 (write-region-internal "foo" nil "../src/REBUILD_AUTOLOADS")
|
|
330 (file-error nil))
|
1261
|
331 (condition-case nil
|
|
332 (delete-file "../src/BYTECOMPILE_CHANGE")
|
|
333 (file-error nil)))
|
|
334 (t
|
|
335 (let ((bc-bootstrap
|
|
336 (mapcar #'(lambda (arg)
|
|
337 (concat (update-elc-chop-extension
|
|
338 (locate-library arg)) ".el"))
|
|
339 lisp-files-needed-for-byte-compilation))
|
|
340 (bootstrap-other
|
|
341 (mapcar #'(lambda (arg)
|
|
342 (concat (update-elc-chop-extension
|
|
343 (locate-library arg)) ".el"))
|
|
344 lisp-files-needing-early-byte-compilation)))
|
|
345 (setq inhibit-autoloads t)
|
528
|
346 ;; if bytecomp or byte-optimize need recompiling, then load
|
|
347 ;; the .el version of them first, recompile them, and reload
|
|
348 ;; the .elc versions to recompile everything else (so we won't
|
|
349 ;; be waiting until the cows come home). we need to set
|
|
350 ;; load-ignore-elc-files because byte-optimize gets autoloaded
|
|
351 ;; from bytecomp.
|
1261
|
352 (let ((recompile-bc-bootstrap
|
|
353 (apply #'nconc
|
|
354 (mapcar
|
|
355 #'(lambda (arg)
|
|
356 (when (member arg update-elc-files-to-compile)
|
|
357 (append '("-f" "batch-byte-compile-one-file")
|
|
358 (list arg))))
|
|
359 bc-bootstrap)))
|
|
360 (recompile-bootstrap-other
|
|
361 (apply #'nconc
|
|
362 (mapcar
|
|
363 #'(lambda (arg)
|
|
364 (when (member arg update-elc-files-to-compile)
|
|
365 (append '("-f" "batch-byte-compile-one-file")
|
|
366 (list arg))))
|
|
367 bootstrap-other))))
|
|
368 (mapc-internal
|
|
369 #'(lambda (arg)
|
|
370 (setq update-elc-files-to-compile
|
|
371 (delete arg update-elc-files-to-compile)))
|
|
372 (append bc-bootstrap bootstrap-other))
|
|
373 (setq command-line-args
|
|
374 (append
|
|
375 '("-l" "loadup-el.el" "run-temacs"
|
|
376 "-batch" "-no-packages" "-no-autoloads"
|
|
377 "-eval" "(setq stack-trace-on-error t)"
|
|
378 "-eval" "(setq load-always-display-messages t)")
|
|
379 (when recompile-bc-bootstrap
|
|
380 (append
|
|
381 '("-eval" "(setq load-ignore-elc-files t)"
|
|
382 "-l" "bytecomp")
|
|
383 recompile-bc-bootstrap
|
|
384 '("-eval" "(setq load-ignore-elc-files nil)")))
|
|
385 '("-l" "bytecomp")
|
|
386 ;; likewise, recompile autoload.el etc. if out-of-date.
|
|
387 recompile-bootstrap-other
|
|
388 ;; then generate autoloads for lisp and maybe lisp/mule.
|
|
389 do-autoload-commands
|
|
390 ;; now load the autoloads and compile alles anderes.
|
|
391 '("-eval" "(setq inhibit-autoloads nil)"
|
|
392 "-f" "startup-load-autoloads"
|
|
393 "-f" "batch-byte-compile")
|
|
394 update-elc-files-to-compile
|
|
395 ))))
|
|
396
|
|
397 ;;(print command-line-args)
|
|
398 (load "loadup-el.el"))))
|
428
|
399
|
1298
|
400 ;(kill-emacs)
|
428
|
401
|
|
402 ;;; update-elc.el ends here
|