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