Merge r21-4-11-chise-0_20-=ucs.
[chise/xemacs-chise.git.1] / lisp / update-elc.el
1 ;;; update-elc.el --- Bytecompile out-of-date dumped files
2
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1996 Sun Microsystems, Inc.
5
6 ;; Author: Ben Wing <ben@xemacs.org>, Steven L Baur <steve@xemacs.org>
7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal
9
10 ;; This file is part of XEmacs.
11
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the 
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Synched up with: Not in FSF.
28
29 ;;; Commentary:
30
31 ;; Byte compile the .EL files necessary to dump out xemacs.
32 ;; Use this file like this:
33
34 ;; temacs -batch -l ../lisp/update-elc.el $lisp
35
36 ;; where $lisp comes from the Makefile.  .elc files listed in $lisp will
37 ;; cause the corresponding .el file to be compiled.  .el files listed in
38 ;; $lisp will be ignored.
39
40 ;; (the idea here is that you can bootstrap if your .ELC files
41 ;; are missing or badly out-of-date)
42
43 ;; See also update-elc-2.el
44
45 ;;; Code:
46
47 (defvar processed nil)
48 (defvar update-elc-files-to-compile nil)
49
50 ;(setq update-elc-files-to-compile
51 ;      (delq nil
52 ;           (mapcar (function
53 ;                    (lambda (x)
54 ;                      (if (string-match "\.elc$" x)
55 ;                          (let ((src (substring x 0 -1)))
56 ;                            (if (file-newer-than-file-p src x)
57 ;                                (progn
58 ;                                  (and (file-exists-p x)
59 ;                                       (null (file-writable-p x))
60 ;                                       (set-file-modes x (logior (file-modes x) 128)))
61 ;                                  src))))))
62 ;                   ;; -batch gets filtered out.
63 ;                   (nthcdr 3 command-line-args))))
64
65 (let ((build-root (expand-file-name ".." invocation-directory)))
66   (setq load-path (list (expand-file-name "lisp" build-root))))
67
68 (load "very-early-lisp" nil t)
69
70 (load "find-paths.el")
71 (load "packages.el")
72 (load "setup-paths.el")
73 (load "dump-paths.el")
74
75 (let ((autol (packages-list-autoloads (concat default-directory "../lisp"))))
76   ;; (print (prin1-to-string autol))
77   (while autol
78     (let ((src (car autol)))
79       (if (and (file-exists-p src)
80                (file-newer-than-file-p src (concat src "c")))
81           (setq update-elc-files-to-compile
82                 (cons src update-elc-files-to-compile))))
83     (setq autol (cdr autol))))
84
85 ;; (print (prin1-to-string update-elc-files-to-compile))
86
87 (let (preloaded-file-list site-load-packages need-to-dump dumped-exe)
88   (load (expand-file-name "../lisp/dumped-lisp.el"))
89
90   (when (featurep 'utf-2000)
91     (load (expand-file-name "../lisp/utf-2000/dumped-chars.el")))
92
93   (setq dumped-exe
94         (cond ((file-exists-p "../src/xemacs.exe") "../src/xemacs.exe")
95               ((file-exists-p "../src/xemacs") "../src/xemacs")
96               (t nil)))
97
98   ;; Path setup
99   (let ((package-preloaded-file-list
100          (packages-collect-package-dumped-lisps late-package-load-path)))
101  
102     (setq preloaded-file-list
103           (append package-preloaded-file-list
104                   preloaded-file-list
105                   '("bytecomp")
106                   packages-hardcoded-lisp)))
107
108   (load (concat default-directory "../site-packages") t t)
109   (setq preloaded-file-list
110         (append packages-hardcoded-lisp
111                 preloaded-file-list
112                 (if (featurep 'utf-2000)
113                     system-char-db-source-file-list)
114                 packages-useful-lisp
115                 site-load-packages))
116   (while preloaded-file-list
117     (let ((arg (car preloaded-file-list)))
118       ;; (print (prin1-to-string arg))
119
120       ;; now check if .el or .elc is newer than the dumped exe.
121       ;; if so, need to redump.
122       (let ((frob
123              (if (string-match "\\.elc?\\'" arg)
124                  (substring arg 0 (match-beginning 0))
125                arg)))
126             (when (and dumped-exe
127                        (or (and (file-exists-p
128                                  (concat "../lisp/" frob ".el"))
129                                 (file-newer-than-file-p
130                                  (concat "../lisp/" frob ".el")
131                                  dumped-exe))
132                            (and (file-exists-p
133                                  (concat "../lisp/" frob ".elc"))
134                                 (file-newer-than-file-p
135                                  (concat "../lisp/" frob ".elc")
136                                  dumped-exe))))
137               (setq need-to-dump t)))
138
139       (if (null (member (file-name-nondirectory arg)
140                         packages-unbytecompiled-lisp))
141           (progn
142             (setq arg (locate-library arg))
143             (if (null arg)
144                 (progn
145                   (print (format "Error: Library file %s not found"
146                                  (car preloaded-file-list)))
147                   ;; Uncomment in case of trouble
148                   ;;(print (format "late-packages: %S" late-packages))
149                   ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name)))
150                   (kill-emacs)))
151             (if (string-match "\\.elc?\\'" arg)
152                 (setq arg (substring arg 0 (match-beginning 0))))
153             (if (and (null (member arg processed))
154                      (file-exists-p (concat arg ".el"))
155                      (file-newer-than-file-p (concat arg ".el")
156                                              (concat arg ".elc")))
157                 (setq processed (cons (concat arg ".el") processed)))))
158       (setq preloaded-file-list (cdr preloaded-file-list))))
159
160   (if need-to-dump
161       (condition-case nil
162           (write-region-internal "foo" nil "../src/NEEDTODUMP")
163         (file-error nil)))
164
165   )
166
167 (setq update-elc-files-to-compile (append update-elc-files-to-compile
168                                           (nreverse processed)))
169
170 ;; (print (prin1-to-string update-elc-files-to-compile))
171
172 (if update-elc-files-to-compile
173     (progn
174       (setq command-line-args
175             (append '("-l" "loadup-el.el" "run-temacs"
176                       "-batch" "-q" "-no-site-file"
177                       "-l" "bytecomp" "-f" "batch-byte-compile")
178                     update-elc-files-to-compile))
179       (load "loadup-el.el"))
180   (condition-case nil
181       (delete-file "../src/NOBYTECOMPILE")
182     (file-error nil)))
183
184 (kill-emacs)
185
186 ;;; update-elc.el ends here