0.6.8.9:
[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                 ;; Let the target know that we're the cross-compiler.
62                 (*features* (cons :sb-xc *features*))
63                 ;; We need to tweak the readtable..
64                 (*readtable* (copy-readtable))
65                 ;; In order to reduce peak memory usage during GENESIS,
66                 ;; it helps to stuff several toplevel forms together 
67                 ;; into the same function.
68                 (sb!c::*top-level-lambda-max* 10))
69             ;; ..in order to make backquotes expand into target code
70             ;; instead of host code.
71             ;; FIXME: Isn't this now taken care of automatically by
72             ;; toplevel forms in the xcompiler backq.lisp file?
73             (set-macro-character #\` #'sb!impl::backquote-macro)
74             (set-macro-character #\, #'sb!impl::comma-macro)
75             ;; Control optimization policy.
76             (proclaim-target-optimization)
77             ;; Specify where target machinery lives.
78             (with-additional-nickname ("SB-XC" "SB!XC")
79               (funcall fn))))
80         (compile 'in-target-cross-compilation-mode)
81         (setf *target-compile-file* 'sb-xc:compile-file)
82         (setf *target-assemble-file* 'sb!c:assemble-file)
83         (setf *in-target-compilation-mode-fn*
84               #'in-target-cross-compilation-mode)
85         (load "src/cold/compile-cold-sbcl.lisp")
86         (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
87           (ensure-directories-exist filename :verbose t)
88           (with-open-file (s filename :direction :output)
89             (write *target-object-file-names* :stream s :readably t)))
90         ;; If you're experimenting with the system under a
91         ;; cross-compilation host which supports CMU-CL-style SAVE-LISP,
92         ;; this can be a good time to run it. The resulting core isn't
93         ;; used in the normal build, but can be handy for experimenting
94         ;; with the system.
95         (when (find :sb-show *shebang-features*)
96           #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
97           #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core"))
98         EOF
99
100 # Run GENESIS again in order to create cold-sbcl.core.
101 #
102 # In a fresh host Lisp invocation, load the cross-compiler (in order
103 # to get various definitions that GENESIS needs, not in order to
104 # cross-compile GENESIS, then load and run GENESIS. (We use a fresh
105 # host Lisp invocation here for basically the same reasons we did
106 # before when loading and running the cross-compiler.)
107 #
108 # (Why do we need this second invocation of GENESIS? In order to
109 # create a .core file, as opposed to just a .h file, GENESIS needs
110 # symbol table data on the C runtime. And we can get that symbol
111 # data only after the C runtime has been built. Therefore, even
112 # though we ran GENESIS earlier, we couldn't get it to make a .core
113 # file at that time; but we needed to run it earlier in order to 
114 # get to where we can write a .core file.)
115 echo //loading and running GENESIS to create cold-sbcl.core
116 $SBCL_XC_HOST <<-'EOF' || exit 1
117         (setf *print-level* 5 *print-length* 5)
118         (load "src/cold/shared.lisp")
119         (in-package "SB-COLD")
120         (setf *host-obj-prefix* "obj/from-host/"
121               *target-obj-prefix* "obj/from-xc/")
122         (load "src/cold/set-up-cold-packages.lisp")
123         (load "src/cold/defun-load-or-cload-xcompiler.lisp")
124         (load-or-cload-xcompiler #'host-load-stem)
125         (defparameter *target-object-file-names*
126           (with-open-file (s "output/object-filenames-for-genesis.lisp-expr"
127                              :direction :input)
128             (read s)))
129         (host-load-stem "compiler/generic/genesis")
130         (sb!vm:genesis :object-file-names *target-object-file-names*
131                        :c-header-file-name "output/sbcl2.h"
132                        :symbol-table-file-name "src/runtime/sbcl.nm"
133                        :core-file-name "output/cold-sbcl.core"
134                        ;; The map file is not needed by the system, but can
135                        ;; be very handy when debugging cold init problems.
136                        :map-file-name "output/cold-sbcl.map")
137         EOF
138
139 echo //testing for consistency of first and second GENESIS passes
140 if cmp src/runtime/sbcl.h output/sbcl2.h; then
141     echo //sbcl2.h matches sbcl.h -- good.
142 else
143     echo error: sbcl2.h does not match sbcl.h.
144     exit 1
145 fi