0.9.4.72:
[sbcl.git] / make-host-2.sh
1 #!/bin/sh
2 set -e
3
4 # This is a script to be run as part of make.sh. The only time you'd
5 # want to run it by itself is if you're trying to cross-compile the
6 # system or if you're doing some kind of troubleshooting.
7
8 # This software is part of the SBCL system. See the README file for
9 # more information.
10 #
11 # This software is derived from the CMU CL system, which was
12 # written at Carnegie Mellon University and released into the
13 # public domain. The software is in the public domain and is
14 # provided with absolutely no warranty. See the COPYING and CREDITS
15 # files for more information.
16
17 echo //entering make-host-2.sh
18
19 LANG=C
20 LC_ALL=C
21 export LANG LC_ALL
22
23 # In some cases, a debugging build of the system will creates a core
24 # file output/after-xc.core in the next step. In cases where it
25 # doesn't, it's confusing and basically useless to have any old copies
26 # lying around, so delete:
27 rm -f output/after-xc.core
28
29 # In a fresh host Lisp invocation, load and run the cross-compiler to
30 # create the target object files describing the target SBCL.
31 #
32 # (There are at least three advantages to running the cross-compiler in a
33 # fresh host Lisp invocation instead of just using the same Lisp invocation
34 # that we used to compile it:
35 #   (1) It reduces the chance that the cross-compilation process
36 #       inadvertently comes to depend on some weird compile-time
37 #       side effect.
38 #   (2) It reduces peak memory demand (because definitions wrapped in
39 #       (EVAL-WHEN (:COMPILE-TOPLEVEL :EXECUTE) ..) aren't defined
40 #       in the fresh image).
41 #   (3) It makes it easier to jump in and retry a step when tweaking
42 #       and experimenting with the bootstrap procedure.
43 # Admittedly, these don't seem to be enormously important advantages, but
44 # the only disadvantage seems to be the extra time required to reload
45 # the fasl files into the new host Lisp, and that doesn't seem to be
46 # an enormously important disadvantage, either.)
47 echo //running cross-compiler to create target object files
48 $SBCL_XC_HOST <<-'EOF'
49
50         ;;;
51         ;;; Set up the cross-compiler.
52         ;;;
53         (setf *print-level* 5 *print-length* 5)
54         (load "src/cold/shared.lisp")
55         (in-package "SB-COLD")
56         (setf *host-obj-prefix* "obj/from-host/"
57               *target-obj-prefix* "obj/from-xc/")
58         (load "src/cold/set-up-cold-packages.lisp")
59         (load "src/cold/defun-load-or-cload-xcompiler.lisp")
60         (load-or-cload-xcompiler #'host-load-stem)
61         (defun proclaim-target-optimization ()
62           (let ((debug (if (position :sb-show *shebang-features*) 2 1)))
63             (sb-xc:proclaim 
64              `(optimize
65                (compilation-speed 1)
66                (debug ,debug)
67                ;; CLISP's pretty-printer is fragile and tends to cause
68                ;; stack corruption or fail internal assertions, as of
69                ;; 2003-04-20; we therefore turn off as many notes as
70                ;; possible.
71                (sb!ext:inhibit-warnings #-clisp 2
72                                         #+clisp 3)
73                ;; SAFETY = SPEED (and < 3) should provide reasonable
74                ;; safety, but might skip some unreasonably expensive
75                ;; stuff (e.g. %DETECT-STACK-EXHAUSTION in sbcl-0.7.2).
76                (safety 2)
77                (space 1)
78                (speed 2)
79                (sb!c:insert-step-conditions 0)
80                (sb!c::stack-allocate-dynamic-extent 3)))))
81         (compile 'proclaim-target-optimization)
82         (defun in-target-cross-compilation-mode (fun)
83           "Call FUN with everything set up appropriately for cross-compiling
84           a target file."
85           (let (;; In order to increase microefficiency of the target Lisp, 
86                 ;; enable old CMU CL defined-function-types-never-change
87                 ;; optimizations. (ANSI says users aren't supposed to
88                 ;; redefine our functions anyway; and developers can
89                 ;; fend for themselves.)
90                 #!-sb-fluid (sb!ext:*derive-function-types* t)
91                 ;; Let the target know that we're the cross-compiler.
92                 (*features* (cons :sb-xc *features*))
93                 ;; We need to tweak the readtable..
94                 (*readtable* (copy-readtable)))
95             ;; ..in order to make backquotes expand into target code
96             ;; instead of host code.
97             ;; FIXME: Isn't this now taken care of automatically by
98             ;; toplevel forms in the xcompiler backq.lisp file?
99             (set-macro-character #\` #'sb!impl::backquote-macro)
100             (set-macro-character #\, #'sb!impl::comma-macro)
101             ;; Control optimization policy.
102             (proclaim-target-optimization)
103             ;; Specify where target machinery lives.
104             (with-additional-nickname ("SB-XC" "SB!XC")
105               (funcall fun))))
106         (compile 'in-target-cross-compilation-mode)
107         (setf *target-compile-file* #'sb-xc:compile-file)
108         (setf *target-assemble-file* #'sb!c:assemble-file)
109         (setf *in-target-compilation-mode-fn*
110               #'in-target-cross-compilation-mode)
111
112         ;;;
113         ;;; Run the cross-compiler to produce cold fasl files.
114         ;;;
115         (load "src/cold/compile-cold-sbcl.lisp")
116  
117         ;;; 
118         ;;; miscellaneous tidying up and saving results
119         ;;; 
120         (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
121           (ensure-directories-exist filename :verbose t)
122           (with-open-file (s filename :direction :output :if-exists :supersede)
123             (write *target-object-file-names* :stream s :readably t)))
124         ;; Let's check that the type system was reasonably sane. (It's
125         ;; easy to spend a long time wandering around confused trying
126         ;; to debug cold init if it wasn't.)
127         (when (position :sb-test *shebang-features*)
128           (load "tests/type.after-xc.lisp"))
129         ;; If you're experimenting with the system under a
130         ;; cross-compilation host which supports CMU-CL-style SAVE-LISP,
131         ;; this can be a good time to run it. The resulting core isn't
132         ;; used in the normal build, but can be handy for experimenting
133         ;; with the system. (See slam.sh for an example.)
134         (when (position :sb-after-xc-core *shebang-features*)
135           #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
136           #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core")
137           #+openmcl (ccl::save-application "output/after-xc.core")
138           #+clisp (ext:saveinitmem "output/after-xc.core"))
139         #+cmu (ext:quit)
140         #+clisp (ext:quit)
141         #+abcl (ext:quit)
142         EOF
143
144 # Run GENESIS (again) in order to create cold-sbcl.core. (The first
145 # time was before we ran the cross-compiler, in order to create the
146 # header file which was needed in order to run gcc on the runtime
147 # code.)
148 sh make-genesis-2.sh