0.6.12.7.flaky1.1:
[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 some cases, a debugging build of the system will creates a core
19 # file output/after-xc.core in the next step. In cases where it
20 # doesn't, it's confusing and basically useless to have any old copies
21 # lying around, so delete:
22 rm -f output/after-xc.core
23
24 # In a fresh host Lisp invocation, load and run the cross-compiler to
25 # create the target object files describing the target SBCL.
26 #
27 # (There are at least three advantages to running the cross-compiler in a
28 # fresh host Lisp invocation instead of just using the same Lisp invocation
29 # that we used to compile it:
30 #   (1) It reduces the chance that the cross-compilation process
31 #       inadvertently comes to depend on some weird compile-time
32 #       side-effect.
33 #   (2) It reduces peak memory demand (because definitions wrapped in
34 #       (EVAL-WHEN (:COMPILE-TOPLEVEL :EXECUTE) ..) aren't defined
35 #       in the fresh image).
36 #   (3) It makes it easier to jump in and retry a step when tweaking
37 #       and experimenting with the bootstrap procedure.
38 # Admittedly, these don't seem to be enormously important advantages, but
39 # the only disadvantage seems to be the extra time required to reload
40 # the fasl files into the new host Lisp, and that doesn't seem to be
41 # an enormously important disadvantage, either.)
42 echo //running cross-compiler to create target object files
43 $SBCL_XC_HOST <<-'EOF' || exit 1
44         (setf *print-level* 5 *print-length* 5)
45         (load "src/cold/shared.lisp")
46         (in-package "SB-COLD")
47         (setf *host-obj-prefix* "obj/from-host/"
48               *target-obj-prefix* "obj/from-xc/")
49         (load "src/cold/set-up-cold-packages.lisp")
50         (load "src/cold/defun-load-or-cload-xcompiler.lisp")
51         (load-or-cload-xcompiler #'host-load-stem)
52         (defun proclaim-target-optimization ()
53           (let ((debug (if (find :sb-show *shebang-features*) 2 1)))
54             (sb-xc:proclaim `(optimize (compilation-speed 1)
55                                        (debug ,debug)
56                                        (sb!ext:inhibit-warnings 2)
57                                        (safety 3)
58                                        (space 1)
59                                        (speed 2)))))
60         (compile 'proclaim-target-optimization)
61         (defun in-target-cross-compilation-mode (fn)
62           "Call FN with everything set up appropriately for cross-compiling
63           a target file."
64           (let (;; Life is simpler at genesis/cold-load time if we
65                 ;; needn't worry about byte-compiled code.
66                 (sb!ext:*byte-compile-top-level* nil)
67                 ;; In order to reduce peak memory usage during GENESIS,
68                 ;; it helps to stuff several toplevel forms together 
69                 ;; into the same function.
70                 (sb!c::*top-level-lambda-max* 10)
71                 ;; Let the target know that we're the cross-compiler.
72                 (*features* (cons :sb-xc *features*))
73                 ;; We need to tweak the readtable..
74                 (*readtable* (copy-readtable)))
75             ;; ..in order to make backquotes expand into target code
76             ;; instead of host code.
77             ;; FIXME: Isn't this now taken care of automatically by
78             ;; toplevel forms in the xcompiler backq.lisp file?
79             (set-macro-character #\` #'sb!impl::backquote-macro)
80             (set-macro-character #\, #'sb!impl::comma-macro)
81             ;; Control optimization policy.
82             (proclaim-target-optimization)
83             ;; Specify where target machinery lives.
84             (with-additional-nickname ("SB-XC" "SB!XC")
85               (funcall fn))))
86         (compile 'in-target-cross-compilation-mode)
87         (setf *target-compile-file* 'sb-xc:compile-file)
88         (setf *target-assemble-file* 'sb!c:assemble-file)
89         (setf *in-target-compilation-mode-fn*
90               #'in-target-cross-compilation-mode)
91         (load "src/cold/compile-cold-sbcl.lisp")
92         (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
93           (ensure-directories-exist filename :verbose t)
94           (with-open-file (s filename :direction :output)
95             (write *target-object-file-names* :stream s :readably t)))
96         ;; Let's check that the type system was reasonably sane. (It's
97         ;; easy to spend a long time wandering around confused trying
98         ;; to debug cold init if it wasn't.)
99         (when (find :sb-test *shebang-features*)
100           (load "tests/type.after-xc.lisp"))
101         ;; If you're experimenting with the system under a
102         ;; cross-compilation host which supports CMU-CL-style SAVE-LISP,
103         ;; this can be a good time to run it. The resulting core isn't
104         ;; used in the normal build, but can be handy for experimenting
105         ;; with the system.
106         
107         ;; REMOVEME: should be conditional on :SB-SHOW again
108         ;;(when (find :sb-show *shebang-features*)
109           #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
110           #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core")
111           ;;)
112         EOF
113
114 # Run GENESIS (again) in order to create cold-sbcl.core. (The first
115 # time was before we ran the cross-compiler, in order to create the
116 # header file which was needed in order to run gcc on the runtime
117 # code.)
118 sh make-genesis-2.sh