0.6.11.23:
[sbcl.git] / make-host-2.sh
1 #!/bin/sh
2
3 # This is a script to be run as part of make.sh. The only time you'd
4 # want to run it by itself is if you're trying to cross-compile the
5 # system or if you're doing some kind of troubleshooting.
6
7 # This software is part of the SBCL system. See the README file for
8 # more information.
9 #
10 # This software is derived from the CMU CL system, which was
11 # written at Carnegie Mellon University and released into the
12 # public domain. The software is in the public domain and is
13 # provided with absolutely no warranty. See the COPYING and CREDITS
14 # files for more information.
15
16 echo //entering make-host-2.sh
17
18 # In a fresh host Lisp invocation, load and run the cross-compiler to
19 # create the target object files describing the target SBCL.
20 #
21 # (There are at least three advantages to running the cross-compiler in a
22 # fresh host Lisp invocation instead of just using the same Lisp invocation
23 # that we used to compile it:
24 #   (1) It reduces the chance that the cross-compilation process
25 #       inadvertently comes to depend on some weird compile-time
26 #       side-effect.
27 #   (2) It reduces peak memory demand (because definitions wrapped in
28 #       (EVAL-WHEN (:COMPILE-TOPLEVEL :EXECUTE) ..) aren't defined
29 #       in the fresh image).
30 #   (3) It makes it easier to jump in and retry a step when tweaking
31 #       and experimenting with the bootstrap procedure.
32 # Admittedly, these don't seem to be enormously important advantages, but
33 # the only disadvantage seems to be the extra time required to reload
34 # the fasl files into the new host Lisp, and that doesn't seem to be
35 # an enormously important disadvantage, either.)
36 echo //running cross-compiler to create target object files
37 $SBCL_XC_HOST <<-'EOF' || exit 1
38         (setf *print-level* 5 *print-length* 5)
39         (load "src/cold/shared.lisp")
40         (in-package "SB-COLD")
41         (setf *host-obj-prefix* "obj/from-host/"
42               *target-obj-prefix* "obj/from-xc/")
43         (load "src/cold/set-up-cold-packages.lisp")
44         (load "src/cold/defun-load-or-cload-xcompiler.lisp")
45         (load-or-cload-xcompiler #'host-load-stem)
46         (defun proclaim-target-optimization ()
47           (let ((debug (if (find :sb-show *shebang-features*) 2 1)))
48             (sb-xc:proclaim `(optimize (compilation-speed 1)
49                                        (debug ,debug)
50                                        (sb!ext:inhibit-warnings 2)
51                                        (safety 3)
52                                        (space 1)
53                                        (speed 2)))))
54         (compile 'proclaim-target-optimization)
55         (defun in-target-cross-compilation-mode (fn)
56           "Call FN with everything set up appropriately for cross-compiling
57           a target file."
58           (let (;; Life is simpler at genesis/cold-load time if we
59                 ;; needn't worry about byte-compiled code.
60                 (sb!ext:*byte-compile-top-level* nil)
61                 ;; In order to reduce peak memory usage during GENESIS,
62                 ;; it helps to stuff several toplevel forms together 
63                 ;; into the same function.
64                 (sb!c::*top-level-lambda-max* 10)
65                 ;; Let the target know that we're the cross-compiler.
66                 (*features* (cons :sb-xc *features*))
67                 ;; the CROSS-FLOAT-INFINITY-KLUDGE: When building a
68                 ;; compiler which runs under the SBCL runtime, which
69                 ;; supports floating point infinities, it's safe to
70                 ;; build with true PROPAGATE-FLOAT-TYPE and
71                 ;; PROPAGATE-FUN-TYPE features. (It wasn't safe
72                 ;; when building a cross-compiler to run under the
73                 ;; cross-compilation host Lisp).
74                 #+nil ; FIXME: suppressed since 0.6.11.3 has no fp infinities
75                 (sb-cold:*shebang-features*
76                  (substitute
77                   :propagate-float-type
78                   :will-propagate-float-type
79                   (substitute
80                    :propagate-fun-type
81                    :will-propagate-fun-type
82                    sb-cold:*shebang-features*)))
83                 ;; We need to tweak the readtable..
84                 (*readtable* (copy-readtable)))
85             ;; ..in order to make backquotes expand into target code
86             ;; instead of host code.
87             ;; FIXME: Isn't this now taken care of automatically by
88             ;; toplevel forms in the xcompiler backq.lisp file?
89             (set-macro-character #\` #'sb!impl::backquote-macro)
90             (set-macro-character #\, #'sb!impl::comma-macro)
91             ;; Control optimization policy.
92             (proclaim-target-optimization)
93             ;; Specify where target machinery lives.
94             (with-additional-nickname ("SB-XC" "SB!XC")
95               (funcall fn))))
96         (compile 'in-target-cross-compilation-mode)
97         (setf *target-compile-file* 'sb-xc:compile-file)
98         (setf *target-assemble-file* 'sb!c:assemble-file)
99         (setf *in-target-compilation-mode-fn*
100               #'in-target-cross-compilation-mode)
101         (load "src/cold/compile-cold-sbcl.lisp")
102         (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
103           (ensure-directories-exist filename :verbose t)
104           (with-open-file (s filename :direction :output)
105             (write *target-object-file-names* :stream s :readably t)))
106         ;; Let's check that the type system was reasonably sane. (It's
107         ;; easy to spend a long time wandering around confused trying
108         ;; to debug cold init if it wasn't.)
109         (when (find :sb-test *shebang-features*)
110           (load "tests/type.after-xc.lisp"))
111         ;; If you're experimenting with the system under a
112         ;; cross-compilation host which supports CMU-CL-style SAVE-LISP,
113         ;; this can be a good time to run it. The resulting core isn't
114         ;; used in the normal build, but can be handy for experimenting
115         ;; with the system.
116         (when (find :sb-show *shebang-features*)
117           #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
118           #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core"))
119         EOF
120
121 # Run GENESIS again in order to create cold-sbcl.core.
122 #
123 # In a fresh host Lisp invocation, load the cross-compiler (in order
124 # to get various definitions that GENESIS needs, not in order to
125 # cross-compile GENESIS, then load and run GENESIS. (We use a fresh
126 # host Lisp invocation here for basically the same reasons we did
127 # before when loading and running the cross-compiler.)
128 #
129 # (Why do we need this second invocation of GENESIS? In order to
130 # create a .core file, as opposed to just a .h file, GENESIS needs
131 # symbol table data on the C runtime. And we can get that symbol
132 # data only after the C runtime has been built. Therefore, even
133 # though we ran GENESIS earlier, we couldn't get it to make a .core
134 # file at that time; but we needed to run it earlier in order to 
135 # get to where we can write a .core file.)
136 echo //loading and running GENESIS to create cold-sbcl.core
137 $SBCL_XC_HOST <<-'EOF' || exit 1
138         (setf *print-level* 5 *print-length* 5)
139         (load "src/cold/shared.lisp")
140         (in-package "SB-COLD")
141         (setf *host-obj-prefix* "obj/from-host/"
142               *target-obj-prefix* "obj/from-xc/")
143         (load "src/cold/set-up-cold-packages.lisp")
144         (load "src/cold/defun-load-or-cload-xcompiler.lisp")
145         (load-or-cload-xcompiler #'host-load-stem)
146         (defparameter *target-object-file-names*
147           (with-open-file (s "output/object-filenames-for-genesis.lisp-expr"
148                              :direction :input)
149             (read s)))
150         (host-load-stem "compiler/generic/genesis")
151         (sb!vm:genesis :object-file-names *target-object-file-names*
152                        :c-header-file-name "output/sbcl2.h"
153                        :symbol-table-file-name "src/runtime/sbcl.nm"
154                        :core-file-name "output/cold-sbcl.core"
155                        ;; The map file is not needed by the system, but can
156                        ;; be very handy when debugging cold init problems.
157                        :map-file-name "output/cold-sbcl.map")
158         EOF
159
160 echo //testing for consistency of first and second GENESIS passes
161 if cmp src/runtime/sbcl.h output/sbcl2.h; then
162     echo //sbcl2.h matches sbcl.h -- good.
163 else
164     echo error: sbcl2.h does not match sbcl.h.
165     exit 1
166 fi