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)
|
|
62 (defvar dumped-exe nil)
|
|
63 (defvar dumped-exe-out-of-date-wrt-dump-files nil)
|
|
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"
|
|
110 "version.el"
|
|
111 "very-early-lisp.el")
|
|
112 "Lisp files that should not be byte compiled.")
|
428
|
113
|
528
|
114 (defun update-elc-chop-extension (file)
|
|
115 (if (string-match "\\.elc?$" file)
|
|
116 (substring file 0 (match-beginning 0))
|
|
117 file))
|
428
|
118
|
528
|
119 ;; we used to call packages-list-autoloads here, but it's false generality.
|
|
120 ;; we need to handle each autoload file differently and there are only
|
|
121 ;; two of them.
|
428
|
122
|
1261
|
123 (let (preloaded-file-list site-load-packages files-to-process)
|
528
|
124
|
428
|
125 (load (expand-file-name "../lisp/dumped-lisp.el"))
|
|
126
|
442
|
127 (setq dumped-exe
|
|
128 (cond ((file-exists-p "../src/xemacs.exe") "../src/xemacs.exe")
|
|
129 ((file-exists-p "../src/xemacs") "../src/xemacs")
|
|
130 (t nil)))
|
|
131
|
1261
|
132 (let ((temacs-exe
|
|
133 (cond ((file-exists-p "../src/temacs.exe") "../src/temacs.exe")
|
|
134 ((file-exists-p "../src/temacs") "../src/temacs")
|
|
135 (t nil)))
|
|
136 (data-file
|
|
137 (cond ((file-exists-p "../src/xemacs.dmp") "../src/xemacs.dmp")
|
|
138 (t nil))))
|
|
139
|
|
140 ;; two setups here:
|
|
141 ;; (1) temacs.exe is undumped, dumped into xemacs.exe. Happens with
|
|
142 ;; unexec, but also with pdump under MS Windows native, since
|
|
143 ;; the dumped data is stored as a resource in the xemacs.exe
|
|
144 ;; executable.
|
|
145 ;; (2) xemacs.exe is dumped or undumped. Running `xemacs -nd' gets
|
|
146 ;; you the equivalent of `temacs'. Dumping creates a file
|
|
147 ;; `xemacs.dmp'.
|
|
148
|
|
149 (setq dumped-exe-out-of-date-wrt-undumped-exe
|
|
150 (cond ((not dumped-exe) t)
|
|
151 (temacs-exe (file-newer-than-file-p temacs-exe dumped-exe))
|
|
152 ((not data-file) t)
|
|
153 (t (file-newer-than-file-p dumped-exe data-file))))
|
|
154 )
|
|
155
|
|
156
|
428
|
157 ;; Path setup
|
|
158 (let ((package-preloaded-file-list
|
|
159 (packages-collect-package-dumped-lisps late-package-load-path)))
|
|
160
|
|
161 (setq preloaded-file-list
|
|
162 (append package-preloaded-file-list
|
|
163 preloaded-file-list
|
|
164 packages-hardcoded-lisp)))
|
|
165
|
|
166 (load (concat default-directory "../site-packages") t t)
|
|
167 (setq preloaded-file-list
|
|
168 (append packages-hardcoded-lisp
|
|
169 preloaded-file-list
|
|
170 site-load-packages))
|
1261
|
171 ;; bytecomp, byte-optimize, autoload, etc. are mentioned specially
|
|
172 ;; in the lisp-files-need* variables.
|
|
173 (setq files-to-process (append lisp-files-needed-for-byte-compilation
|
|
174 lisp-files-needing-early-byte-compilation
|
|
175 preloaded-file-list))
|
528
|
176 (while files-to-process
|
|
177 (let* ((arg (car files-to-process))
|
|
178 (arg-is-preloaded (member arg preloaded-file-list))
|
|
179 (arg-sans-extension (update-elc-chop-extension arg))
|
|
180 (full-arg (locate-library arg-sans-extension))
|
|
181 (full-arg-sans-extension
|
|
182 (if (null full-arg)
|
|
183 (progn
|
|
184 (print (format "Error: Library file %s not found" arg))
|
1261
|
185 (backtrace)
|
528
|
186 ;; Uncomment in case of trouble
|
|
187 ;;(print (format "late-packages: %S" late-packages))
|
|
188 ;;(print (format "guessed-roots: %S"
|
|
189 ;; (paths-find-emacs-roots
|
|
190 ;; invocation-directory invocation-name)))
|
|
191 (kill-emacs))
|
|
192 (update-elc-chop-extension full-arg)))
|
|
193 (full-arg-el (concat full-arg-sans-extension ".el"))
|
|
194 (full-arg-elc (concat full-arg-sans-extension ".elc"))
|
1261
|
195 (full-arg-dir (file-name-directory full-arg-el)))
|
528
|
196
|
|
197 ;; (print full-arg-el)
|
442
|
198
|
|
199 ;; now check if .el or .elc is newer than the dumped exe.
|
|
200 ;; if so, need to redump.
|
528
|
201 (when (and dumped-exe arg-is-preloaded
|
|
202 (or (and (file-exists-p full-arg-el)
|
|
203 (file-newer-than-file-p full-arg-el dumped-exe))
|
|
204 (and (file-exists-p full-arg-elc)
|
|
205 (file-newer-than-file-p full-arg-elc dumped-exe))))
|
1261
|
206 (setq dumped-exe-out-of-date-wrt-dump-files t))
|
528
|
207
|
|
208 (if (and (not (member (file-name-nondirectory arg)
|
1261
|
209 unbytecompiled-lisp-files))
|
528
|
210 (not (member full-arg-el processed))
|
|
211 (file-exists-p full-arg-el)
|
|
212 (or (not (file-exists-p full-arg-elc))
|
|
213 (file-newer-than-file-p full-arg-el full-arg-elc)))
|
|
214 (setq processed (cons full-arg-el processed)))
|
|
215
|
|
216 (setq files-to-process (cdr files-to-process))))
|
442
|
217
|
1261
|
218 ;; Check if we need to rebuild the auto-autoloads.el files -- that is,
|
|
219 ;; if ANY .el files have changed.
|
|
220 (let ((dirs-to-check '("../lisp" "../lisp/mule")))
|
|
221 (while dirs-to-check
|
|
222 (let* ((dir (car dirs-to-check))
|
|
223 (full-dir (expand-file-name dir))
|
|
224 (all-files-in-dir (directory-files full-dir t "\\.el$" nil t))
|
|
225 (autoload-file
|
|
226 (expand-file-name "auto-autoloads.el" full-dir))
|
|
227 (autoload-is-mule (equal dir "../lisp/mule")))
|
|
228 (while all-files-in-dir
|
|
229 (let* ((full-arg (car all-files-in-dir)))
|
|
230 (when (or (not (file-exists-p autoload-file))
|
|
231 (and (file-exists-p full-arg)
|
|
232 (file-newer-than-file-p full-arg autoload-file)))
|
|
233 (if autoload-is-mule
|
|
234 (setq need-to-rebuild-mule-autoloads t)
|
|
235 (setq need-to-rebuild-autoloads t))))
|
|
236 (setq all-files-in-dir (cdr all-files-in-dir))))
|
|
237 (setq dirs-to-check (cdr dirs-to-check))))
|
|
238
|
|
239 (if dumped-exe-out-of-date-wrt-dump-files
|
442
|
240 (condition-case nil
|
|
241 (write-region-internal "foo" nil "../src/NEEDTODUMP")
|
|
242 (file-error nil)))
|
|
243
|
|
244 )
|
428
|
245
|
528
|
246 (when (or need-to-rebuild-autoloads
|
|
247 (not (file-exists-p "../lisp/auto-autoloads.el"))
|
|
248 (not (file-exists-p "../lisp/auto-autoloads.elc"))
|
|
249 (file-newer-than-file-p "../lisp/auto-autoloads.el"
|
|
250 "../lisp/auto-autoloads.elc"))
|
|
251 (setq need-to-recompile-autoloads t))
|
|
252
|
|
253 (when (or need-to-rebuild-mule-autoloads
|
|
254 (not (file-exists-p "../lisp/mule/auto-autoloads.el"))
|
|
255 (not (file-exists-p "../lisp/mule/auto-autoloads.elc"))
|
|
256 (file-newer-than-file-p "../lisp/mule/auto-autoloads.el"
|
|
257 "../lisp/mule/auto-autoloads.elc"))
|
|
258 (setq need-to-recompile-mule-autoloads t))
|
|
259
|
|
260 (when (not (featurep 'mule))
|
|
261 ;; sorry charlie.
|
|
262 (setq need-to-rebuild-mule-autoloads nil
|
|
263 need-to-recompile-mule-autoloads nil))
|
|
264
|
428
|
265 (setq update-elc-files-to-compile (append update-elc-files-to-compile
|
622
|
266 (nreverse processed)))
|
428
|
267
|
1261
|
268 ;(print update-elc-files-to-compile)
|
428
|
269
|
1261
|
270 (let ((do-autoload-commands
|
|
271 (append
|
|
272 (if (or need-to-rebuild-autoloads
|
|
273 need-to-rebuild-mule-autoloads)
|
|
274 '("-l" "autoload"))
|
|
275 (if need-to-rebuild-autoloads
|
|
276 '("-f" "autoload-update-directory-autoloads"
|
|
277 "auto" "../lisp"))
|
|
278 (if need-to-rebuild-mule-autoloads
|
|
279 '("-f" "autoload-update-directory-autoloads"
|
|
280 "mule" "../lisp/mule"))
|
|
281 (if need-to-recompile-autoloads
|
|
282 '("-f" "batch-byte-compile-one-file"
|
|
283 "../lisp/auto-autoloads.el"))
|
|
284 (if need-to-recompile-mule-autoloads
|
|
285 '("-f" "batch-byte-compile-one-file"
|
|
286 "../lisp/mule/auto-autoloads.el")))))
|
|
287 (cond ((and (not update-elc-files-to-compile)
|
|
288 (not need-to-rebuild-autoloads)
|
|
289 (not need-to-rebuild-mule-autoloads)
|
|
290 (not need-to-recompile-autoloads)
|
|
291 (not need-to-recompile-mule-autoloads))
|
|
292 ;; (1) Nothing to do at all. BYTECOMPILE_CHANGE is used (only by
|
|
293 ;; the Unix makefile) to indicate whether some files needed
|
|
294 ;; for dump got recompiled, and hence the executable must be
|
|
295 ;; redumped. We remove it if there were no files to compile.
|
|
296 (condition-case nil
|
|
297 (delete-file "../src/BYTECOMPILE_CHANGE")
|
|
298 (file-error nil)))
|
|
299 ((and (not update-elc-files-to-compile)
|
|
300 (not dumped-exe-out-of-date-wrt-dump-files)
|
|
301 (not dumped-exe-out-of-date-wrt-undumped-exe))
|
|
302 ;; (2) We have no files to byte-compile, but we do need to
|
|
303 ;; regenerate and compile the auto-autoloads file. (This will
|
|
304 ;; be needed to be up-to-date before we run update-elc-2.)
|
|
305 ;; If the dumped exe exists and is up-to-date, both with
|
|
306 ;; respect to the undumped exe and the files that will be dumped
|
|
307 ;; into it, then we can use the dumped exe to rebuild the
|
|
308 ;; autoloads. Else, we have to do it the "hard way" by loading
|
|
309 ;; raw temacs, running loadup, then regenerating the autoloads.
|
|
310 ;; #### We should see whether it's possible to load up a
|
|
311 ;; minimal number of files in order to get autoload.el to work.
|
|
312 (load "raw-process.el")
|
|
313 (apply 'call-process-internal dumped-exe nil t nil
|
|
314 (append
|
|
315 '("-batch -no-autoloads -no-packages")
|
|
316 do-autoload-commands))
|
|
317 (condition-case nil
|
|
318 (delete-file "../src/BYTECOMPILE_CHANGE")
|
|
319 (file-error nil)))
|
|
320 (t
|
|
321 (let ((bc-bootstrap
|
|
322 (mapcar #'(lambda (arg)
|
|
323 (concat (update-elc-chop-extension
|
|
324 (locate-library arg)) ".el"))
|
|
325 lisp-files-needed-for-byte-compilation))
|
|
326 (bootstrap-other
|
|
327 (mapcar #'(lambda (arg)
|
|
328 (concat (update-elc-chop-extension
|
|
329 (locate-library arg)) ".el"))
|
|
330 lisp-files-needing-early-byte-compilation)))
|
|
331 (setq inhibit-autoloads t)
|
528
|
332 ;; if bytecomp or byte-optimize need recompiling, then load
|
|
333 ;; the .el version of them first, recompile them, and reload
|
|
334 ;; the .elc versions to recompile everything else (so we won't
|
|
335 ;; be waiting until the cows come home). we need to set
|
|
336 ;; load-ignore-elc-files because byte-optimize gets autoloaded
|
|
337 ;; from bytecomp.
|
1261
|
338 (let ((recompile-bc-bootstrap
|
|
339 (apply #'nconc
|
|
340 (mapcar
|
|
341 #'(lambda (arg)
|
|
342 (when (member arg update-elc-files-to-compile)
|
|
343 (append '("-f" "batch-byte-compile-one-file")
|
|
344 (list arg))))
|
|
345 bc-bootstrap)))
|
|
346 (recompile-bootstrap-other
|
|
347 (apply #'nconc
|
|
348 (mapcar
|
|
349 #'(lambda (arg)
|
|
350 (when (member arg update-elc-files-to-compile)
|
|
351 (append '("-f" "batch-byte-compile-one-file")
|
|
352 (list arg))))
|
|
353 bootstrap-other))))
|
|
354 (mapc-internal
|
|
355 #'(lambda (arg)
|
|
356 (setq update-elc-files-to-compile
|
|
357 (delete arg update-elc-files-to-compile)))
|
|
358 (append bc-bootstrap bootstrap-other))
|
|
359 (setq command-line-args
|
|
360 (append
|
|
361 '("-l" "loadup-el.el" "run-temacs"
|
|
362 "-batch" "-no-packages" "-no-autoloads"
|
|
363 "-eval" "(setq stack-trace-on-error t)"
|
|
364 "-eval" "(setq load-always-display-messages t)")
|
|
365 (when recompile-bc-bootstrap
|
|
366 (append
|
|
367 '("-eval" "(setq load-ignore-elc-files t)"
|
|
368 "-l" "bytecomp")
|
|
369 recompile-bc-bootstrap
|
|
370 '("-eval" "(setq load-ignore-elc-files nil)")))
|
|
371 '("-l" "bytecomp")
|
|
372 ;; likewise, recompile autoload.el etc. if out-of-date.
|
|
373 recompile-bootstrap-other
|
|
374 ;; then generate autoloads for lisp and maybe lisp/mule.
|
|
375 do-autoload-commands
|
|
376 ;; now load the autoloads and compile alles anderes.
|
|
377 '("-eval" "(setq inhibit-autoloads nil)"
|
|
378 "-f" "startup-load-autoloads"
|
|
379 "-f" "batch-byte-compile")
|
|
380 update-elc-files-to-compile
|
|
381 ))))
|
|
382
|
|
383 ;;(print command-line-args)
|
|
384 (load "loadup-el.el"))))
|
428
|
385
|
|
386 (kill-emacs)
|
|
387
|
|
388 ;;; update-elc.el ends here
|