1 | ;;; compile-system.lisp |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 2004-2008 Peter Graves |
---|
4 | ;;; $Id: compile-system.lisp 12831 2010-07-28 22:13:15Z astalla $ |
---|
5 | ;;; |
---|
6 | ;;; This program is free software; you can redistribute it and/or |
---|
7 | ;;; modify it under the terms of the GNU General Public License |
---|
8 | ;;; as published by the Free Software Foundation; either version 2 |
---|
9 | ;;; of the License, or (at your option) any later version. |
---|
10 | ;;; |
---|
11 | ;;; This program is distributed in the hope that it will be useful, |
---|
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | ;;; GNU General Public License for more details. |
---|
15 | ;;; |
---|
16 | ;;; You should have received a copy of the GNU General Public License |
---|
17 | ;;; along with this program; if not, write to the Free Software |
---|
18 | ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
19 | ;;; |
---|
20 | ;;; As a special exception, the copyright holders of this library give you |
---|
21 | ;;; permission to link this library with independent modules to produce an |
---|
22 | ;;; executable, regardless of the license terms of these independent |
---|
23 | ;;; modules, and to copy and distribute the resulting executable under |
---|
24 | ;;; terms of your choice, provided that you also meet, for each linked |
---|
25 | ;;; independent module, the terms and conditions of the license of that |
---|
26 | ;;; module. An independent module is a module which is not derived from |
---|
27 | ;;; or based on this library. If you modify this library, you may extend |
---|
28 | ;;; this exception to your version of the library, but you are not |
---|
29 | ;;; obligated to do so. If you do not wish to do so, delete this |
---|
30 | ;;; exception statement from your version. |
---|
31 | |
---|
32 | (in-package "SYSTEM") |
---|
33 | |
---|
34 | (require "LOOP") |
---|
35 | (require "COLLECT") |
---|
36 | (require "COMPILE-FILE") |
---|
37 | |
---|
38 | (defun check-lisp-home () |
---|
39 | (loop |
---|
40 | (cond ((and *lisp-home* |
---|
41 | (probe-directory (pathname *lisp-home*))) |
---|
42 | (return)) |
---|
43 | (t |
---|
44 | (cerror "Continue" |
---|
45 | "*LISP-HOME* is NIL or invalid.~% Please set *LISP-HOME* to the full pathname of the directory containing the Lisp system files."))))) |
---|
46 | |
---|
47 | (defun grovel-java-definitions-in-file (file out) |
---|
48 | (with-open-file (in file) |
---|
49 | (declare (type stream in)) |
---|
50 | (let ((system-package (find-package "SYSTEM")) |
---|
51 | (line-number 1)) |
---|
52 | (loop |
---|
53 | (let ((text (read-line in nil))) |
---|
54 | (when (null text) |
---|
55 | (return)) |
---|
56 | (let ((position (search "###" text))) |
---|
57 | (when position |
---|
58 | (let* ((name (string (read-from-string (subseq text (+ position 3))))) |
---|
59 | (symbol (or (find-symbol name system-package) ; uses CL and EXT |
---|
60 | (find-symbol name (find-package "MOP")) |
---|
61 | (find-symbol name (find-package "JAVA"))))) |
---|
62 | (when symbol |
---|
63 | ;; Force the symbol's package prefix to be written out |
---|
64 | ;; with "::" instead of ":" so there won't be a reader |
---|
65 | ;; error if a symbol that's external now is no longer |
---|
66 | ;; external when we read the tags file. |
---|
67 | (%format out "~A::~A ~S ~S~%" |
---|
68 | (package-name (symbol-package symbol)) |
---|
69 | name |
---|
70 | file line-number))))) |
---|
71 | (incf line-number)))))) |
---|
72 | |
---|
73 | (defun grovel-java-definitions () |
---|
74 | (check-lisp-home) |
---|
75 | (time |
---|
76 | (let ((files (directory (merge-pathnames "*.java" *lisp-home*)))) |
---|
77 | (with-open-file (stream (merge-pathnames "tags" *lisp-home*) |
---|
78 | :direction :output :if-exists :supersede) |
---|
79 | (dolist (file files) |
---|
80 | (grovel-java-definitions-in-file file stream)))))) |
---|
81 | |
---|
82 | (defun %compile-system (&key output-path) |
---|
83 | (let ((*default-pathname-defaults* (pathname *lisp-home*)) |
---|
84 | (*warn-on-redefinition* nil)) |
---|
85 | (unless output-path |
---|
86 | (setf output-path *default-pathname-defaults*)) |
---|
87 | (flet ((do-compile (file) |
---|
88 | (let ((out (make-pathname :type "abcl" |
---|
89 | :defaults (merge-pathnames |
---|
90 | file output-path)))) |
---|
91 | (compile-file-if-needed file :output-file out)))) |
---|
92 | (load (do-compile "coerce.lisp")) |
---|
93 | (load (do-compile "open.lisp")) |
---|
94 | (load (do-compile "dump-form.lisp")) |
---|
95 | (load (do-compile "compiler-types.lisp")) |
---|
96 | (load (do-compile "compile-file.lisp")) |
---|
97 | (load (do-compile "precompiler.lisp")) |
---|
98 | (load (do-compile "compiler-pass1.lisp")) |
---|
99 | (load (do-compile "compiler-pass2.lisp")) |
---|
100 | (load (do-compile "jvm.lisp")) |
---|
101 | (load (do-compile "source-transform.lisp")) |
---|
102 | (load (do-compile "compiler-macro.lisp")) |
---|
103 | (load (do-compile "opcodes.lisp")) |
---|
104 | (load (do-compile "setf.lisp")) |
---|
105 | (load (do-compile "extensible-sequences-base.lisp")) |
---|
106 | (load (do-compile "require.lisp")) |
---|
107 | (load (do-compile "substitute.lisp")) |
---|
108 | (load (do-compile "clos.lisp")) |
---|
109 | ;; Order matters for these files. |
---|
110 | (mapc #'do-compile '("collect.lisp" |
---|
111 | "macros.lisp" |
---|
112 | "loop.lisp")) |
---|
113 | (load (do-compile "backquote.lisp")) |
---|
114 | (load (do-compile "early-defuns.lisp")) |
---|
115 | (load (do-compile "typep.lisp")) |
---|
116 | (load (do-compile "subtypep.lisp")) |
---|
117 | (load (do-compile "find.lisp")) |
---|
118 | (load (do-compile "print.lisp")) |
---|
119 | (load (do-compile "pprint-dispatch.lisp")) |
---|
120 | (load (do-compile "pprint.lisp")) |
---|
121 | (load (do-compile "format.lisp")) |
---|
122 | (load (do-compile "delete.lisp")) |
---|
123 | (load (do-compile "concatenate.lisp")) |
---|
124 | (load (do-compile "ldb.lisp")) |
---|
125 | (load (do-compile "destructuring-bind.lisp")) |
---|
126 | (load (do-compile "asdf.lisp")) |
---|
127 | ;; But not for these. |
---|
128 | (mapc #'do-compile '("adjoin.lisp" |
---|
129 | "and.lisp" |
---|
130 | "apropos.lisp" |
---|
131 | "arrays.lisp" |
---|
132 | "assert.lisp" |
---|
133 | "assoc.lisp" |
---|
134 | "autoloads.lisp" |
---|
135 | "aver.lisp" |
---|
136 | "bit-array-ops.lisp" |
---|
137 | "boole.lisp" |
---|
138 | ;;"boot.lisp" |
---|
139 | "butlast.lisp" |
---|
140 | "byte-io.lisp" |
---|
141 | "case.lisp" |
---|
142 | "chars.lisp" |
---|
143 | "check-type.lisp" |
---|
144 | "compile-file-pathname.lisp" |
---|
145 | "compile-system.lisp" |
---|
146 | "compiler-error.lisp" |
---|
147 | "cond.lisp" |
---|
148 | "copy-seq.lisp" |
---|
149 | "copy-symbol.lisp" |
---|
150 | "count.lisp" |
---|
151 | "debug.lisp" |
---|
152 | "define-modify-macro.lisp" |
---|
153 | "define-symbol-macro.lisp" |
---|
154 | "defmacro.lisp" |
---|
155 | "defpackage.lisp" |
---|
156 | "defsetf.lisp" |
---|
157 | "defstruct.lisp" |
---|
158 | "deftype.lisp" |
---|
159 | "delete-duplicates.lisp" |
---|
160 | "deposit-field.lisp" |
---|
161 | "describe.lisp" |
---|
162 | "describe-compiler-policy.lisp" |
---|
163 | "directory.lisp" |
---|
164 | "disassemble.lisp" |
---|
165 | "do-all-symbols.lisp" |
---|
166 | "do-external-symbols.lisp" |
---|
167 | "do-symbols.lisp" |
---|
168 | "do.lisp" |
---|
169 | "dolist.lisp" |
---|
170 | "dotimes.lisp" |
---|
171 | "dribble.lisp" |
---|
172 | "dump-class.lisp" |
---|
173 | "ed.lisp" |
---|
174 | "enough-namestring.lisp" |
---|
175 | "ensure-directories-exist.lisp" |
---|
176 | "error.lisp" |
---|
177 | "extensible-sequences.lisp" |
---|
178 | "featurep.lisp" |
---|
179 | "fdefinition.lisp" |
---|
180 | "fill.lisp" |
---|
181 | "find-all-symbols.lisp" |
---|
182 | "gentemp.lisp" |
---|
183 | "gray-streams.lisp" |
---|
184 | "gui.lisp" |
---|
185 | "inline.lisp" |
---|
186 | "inspect.lisp" |
---|
187 | ;;"j.lisp" |
---|
188 | "java.lisp" |
---|
189 | "java-collections.lisp" |
---|
190 | "known-functions.lisp" |
---|
191 | "known-symbols.lisp" |
---|
192 | "late-setf.lisp" |
---|
193 | "lcm.lisp" |
---|
194 | "ldiff.lisp" |
---|
195 | "list-length.lisp" |
---|
196 | "list.lisp" |
---|
197 | "load.lisp" |
---|
198 | "make-hash-table.lisp" |
---|
199 | "make-load-form-saving-slots.lisp" |
---|
200 | "make-sequence.lisp" |
---|
201 | "make-string-output-stream.lisp" |
---|
202 | "make-string.lisp" |
---|
203 | "map-into.lisp" |
---|
204 | "map.lisp" |
---|
205 | "map1.lisp" |
---|
206 | "mask-field.lisp" |
---|
207 | "member-if.lisp" |
---|
208 | "mismatch.lisp" |
---|
209 | "multiple-value-bind.lisp" |
---|
210 | "multiple-value-list.lisp" |
---|
211 | "multiple-value-setq.lisp" |
---|
212 | "nsubstitute.lisp" |
---|
213 | "nth-value.lisp" |
---|
214 | "numbers.lisp" |
---|
215 | "or.lisp" |
---|
216 | "parse-integer.lisp" |
---|
217 | "parse-lambda-list.lisp" |
---|
218 | "package.lisp" |
---|
219 | "pathnames.lisp" |
---|
220 | "print-object.lisp" |
---|
221 | "print-unreadable-object.lisp" |
---|
222 | "proclaim.lisp" |
---|
223 | "profiler.lisp" |
---|
224 | "prog.lisp" |
---|
225 | "psetf.lisp" |
---|
226 | "query.lisp" |
---|
227 | "read-circle.lisp" |
---|
228 | "read-conditional.lisp" |
---|
229 | "read-from-string.lisp" |
---|
230 | "read-sequence.lisp" |
---|
231 | "reduce.lisp" |
---|
232 | "remf.lisp" |
---|
233 | "remove-duplicates.lisp" |
---|
234 | "remove.lisp" |
---|
235 | "replace.lisp" |
---|
236 | "restart.lisp" |
---|
237 | "revappend.lisp" |
---|
238 | "rotatef.lisp" |
---|
239 | ;;"run-benchmarks.lisp" |
---|
240 | "run-shell-command.lisp" |
---|
241 | ;;"runtime-class.lisp" |
---|
242 | "search.lisp" |
---|
243 | "sequences.lisp" |
---|
244 | "sets.lisp" |
---|
245 | "shiftf.lisp" |
---|
246 | "signal.lisp" |
---|
247 | "socket.lisp" |
---|
248 | "sort.lisp" |
---|
249 | "step.lisp" |
---|
250 | "strings.lisp" |
---|
251 | "sublis.lisp" |
---|
252 | "subst.lisp" |
---|
253 | "tailp.lisp" |
---|
254 | "threads.lisp" |
---|
255 | "time.lisp" |
---|
256 | "top-level.lisp" |
---|
257 | "trace.lisp" |
---|
258 | "tree-equal.lisp" |
---|
259 | "upgraded-complex-part-type.lisp" |
---|
260 | "with-accessors.lisp" |
---|
261 | "with-hash-table-iterator.lisp" |
---|
262 | "with-input-from-string.lisp" |
---|
263 | "with-open-file.lisp" |
---|
264 | "with-output-to-string.lisp" |
---|
265 | "with-package-iterator.lisp" |
---|
266 | "with-slots.lisp" |
---|
267 | "with-standard-io-syntax.lisp" |
---|
268 | "write-sequence.lisp"))) |
---|
269 | t)) |
---|
270 | |
---|
271 | (defun compile-system (&key quit (zip t) output-path) |
---|
272 | (let ((status -1)) |
---|
273 | (check-lisp-home) |
---|
274 | (time |
---|
275 | (with-compilation-unit () |
---|
276 | (let ((*compile-file-zip* zip) |
---|
277 | failure-p) |
---|
278 | (handler-bind (((or warning |
---|
279 | compiler-error) |
---|
280 | #'(lambda (c) |
---|
281 | (declare (ignore c)) |
---|
282 | (setf failure-p t) |
---|
283 | ;; only register that we had this type of signal |
---|
284 | ;; defer the actual handling to another handler |
---|
285 | nil))) |
---|
286 | (%compile-system :output-path output-path)) |
---|
287 | (unless failure-p |
---|
288 | (setf status 0))))) |
---|
289 | (create-system-logical-translations output-path) |
---|
290 | (when quit |
---|
291 | (quit :status status)))) |
---|
292 | |
---|
293 | (defun create-system-logical-translations (output-path) |
---|
294 | (let* ((dir (directory-namestring (pathname output-path))) |
---|
295 | (system (merge-pathnames "system.lisp" dir)) |
---|
296 | (home (pathname *lisp-home*)) |
---|
297 | (src (format nil "~A**/*.*" home)) |
---|
298 | (java (format nil "~A../../../**/*.*" home))) |
---|
299 | (with-open-file (s system :direction :output |
---|
300 | :if-exists :supersede) |
---|
301 | (pprint `(setf (logical-pathname-translations "sys") |
---|
302 | '(("SYS:SRC;**;*.*" ,src) |
---|
303 | ("SYS:JAVA;**;*.*" ,java))) |
---|
304 | s)))) |
---|
305 | |
---|