1.0.16.29: workaround for bug 419
[sbcl.git] / make-host-2.lisp
1 ;;; Set up the cross-compiler.
2 (setf *print-level* 5 *print-length* 5)
3 (load "src/cold/shared.lisp")
4 (in-package "SB-COLD")
5 ;;; FIXME: these prefixes look like non-pathnamy ways of defining a
6 ;;; relative pathname.  Investigate whether they can be made relative
7 ;;; pathnames.
8 (setf *host-obj-prefix* "obj/from-host/"
9       *target-obj-prefix* "obj/from-xc/")
10 (load "src/cold/set-up-cold-packages.lisp")
11 (load "src/cold/defun-load-or-cload-xcompiler.lisp")
12 (load-or-cload-xcompiler #'host-load-stem)
13
14 (defun proclaim-target-optimization ()
15   (let ((debug (if (position :sb-show *shebang-features*) 2 1)))
16     (sb-xc:proclaim
17      `(optimize
18        (compilation-speed 1) (debug ,debug)
19        ;; CLISP's pretty-printer is fragile and tends to cause stack
20        ;; corruption or fail internal assertions, as of 2003-04-20; we
21        ;; therefore turn off as many notes as possible.
22        (sb!ext:inhibit-warnings #-clisp 2 #+clisp 3)
23        ;; SAFETY = SPEED (and < 3) should provide reasonable safety,
24        ;; but might skip some unreasonably expensive stuff
25        ;; (e.g. %DETECT-STACK-EXHAUSTION in sbcl-0.7.2).
26        (safety 2) (space 1) (speed 2)
27        ;; sbcl-internal optimization declarations:
28        ;;
29        ;; never insert stepper conditions
30        (sb!c:insert-step-conditions 0)
31        ;; always stack-allocate if requested
32        (sb!c::stack-allocate-dynamic-extent 3)
33        ;; ...even value cells!
34        (sb!c::stack-allocate-value-cells 3)))))
35 (compile 'proclaim-target-optimization)
36
37 (defun in-target-cross-compilation-mode (fun)
38   "Call FUN with everything set up appropriately for cross-compiling
39    a target file."
40   (let (;; In order to increase microefficiency of the target Lisp,
41         ;; enable old CMU CL defined-function-types-never-change
42         ;; optimizations. (ANSI says users aren't supposed to
43         ;; redefine our functions anyway; and developers can
44         ;; fend for themselves.)
45         #!-sb-fluid
46         (sb!ext:*derive-function-types* t)
47         ;; Let the target know that we're the cross-compiler.
48         (*features* (cons :sb-xc *features*))
49         ;; We need to tweak the readtable..
50         (*readtable* (copy-readtable)))
51     ;; ..in order to make backquotes expand into target code
52     ;; instead of host code.
53     ;; FIXME: Isn't this now taken care of automatically by
54     ;; toplevel forms in the xcompiler backq.lisp file?
55     (set-macro-character #\` #'sb!impl::backquote-macro)
56     (set-macro-character #\, #'sb!impl::comma-macro)
57     ;; Control optimization policy.
58     (proclaim-target-optimization)
59     ;; Specify where target machinery lives.
60     (with-additional-nickname ("SB-XC" "SB!XC")
61       (funcall fun))))
62 (compile 'in-target-cross-compilation-mode)
63
64 (setf *target-compile-file* #'sb-xc:compile-file)
65 (setf *target-assemble-file* #'sb!c:assemble-file)
66 (setf *in-target-compilation-mode-fn* #'in-target-cross-compilation-mode)
67 \f
68 ;;; Run the cross-compiler to produce cold fasl files.
69 (load "src/cold/compile-cold-sbcl.lisp")
70
71
72 ;;; miscellaneous tidying up and saving results
73 (let ((filename "output/object-filenames-for-genesis.lisp-expr"))
74   (ensure-directories-exist filename :verbose t)
75   (with-open-file (s filename :direction :output :if-exists :supersede)
76     (write *target-object-file-names* :stream s :readably t)))
77
78 ;;; Let's check that the type system was reasonably sane. (It's easy
79 ;;; to spend a long time wandering around confused trying to debug
80 ;;; cold init if it wasn't.)
81 (when (position :sb-test *shebang-features*)
82   (load "tests/type.after-xc.lisp"))
83
84 ;;; If you're experimenting with the system under a cross-compilation
85 ;;; host which supports CMU-CL-style SAVE-LISP, this can be a good
86 ;;; time to run it. The resulting core isn't used in the normal build,
87 ;;; but can be handy for experimenting with the system. (See slam.sh
88 ;;; for an example.)
89 (when (position :sb-after-xc-core *shebang-features*)
90   #+cmu (ext:save-lisp "output/after-xc.core" :load-init-file nil)
91   #+sbcl (sb-ext:save-lisp-and-die "output/after-xc.core")
92   #+openmcl (ccl::save-application "output/after-xc.core")
93   #+clisp (ext:saveinitmem "output/after-xc.core"))
94 #+cmu (ext:quit)
95 #+clisp (ext:quit)
96 #+abcl (ext:quit)