1.0.41.46: further make.sh tweaks
[sbcl.git] / make.sh
1 #!/bin/sh
2 set -e
3
4 LANG=C
5 LC_ALL=C
6 export LANG LC_ALL
7
8 # "When we build software, it's a good idea to have a reliable method
9 # for getting an executable from it. We want any two reconstructions
10 # starting from the same source to end up in the same result. That's
11 # just a basic intellectual premise."
12 #     -- Christian Queinnec, in _Lisp In Small Pieces_, p. 313
13
14 # This software is part of the SBCL system. See the README file for
15 # more information.
16 #
17 # This software is derived from the CMU CL system, which was
18 # written at Carnegie Mellon University and released into the
19 # public domain. The software is in the public domain and is
20 # provided with absolutely no warranty. See the COPYING and CREDITS
21 # files for more information.
22
23 print_help="no"
24
25 # The classic form here was to use --userinit $DEVNULL --sysinit
26 # $DEVNULL, but that doesn't work on Win32 because SBCL doesn't handle
27 # device names properly. We still need $DEVNULL to be NUL on Win32
28 # because it's used elsewhere (such as canonicalize-whitespace), so we
29 # need an alternate solution for the init file overrides. --no-foos
30 # have now been available long enough that this should not stop anyone
31 # from building.
32 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ]
33 then
34     SBCL_PREFIX="$PROGRAMFILES/sbcl"
35 else
36     SBCL_PREFIX="/usr/local"
37 fi
38 SBCL_XC_HOST="sbcl --disable-debugger --no-userinit --no-sysinit"
39 export SBCL_XC_HOST
40
41 # Parse command-line options.
42 function bad_option() {
43     echo $1
44     echo "Enter \"$0 --help\" for list of valid options."
45     exit 1
46 }
47
48 for option
49 do
50   # Split --foo=bar into --foo and bar.
51   case $option in
52       *=*)
53         optarg=`expr "X$option" : '[^=]*=\(.*\)'` || true
54         option=`expr "X$option" : 'X\([^=]*=\).*'`
55         if test -z "$optarg"
56         then
57             bad_option "Command-line option has no value: $option"
58         fi
59         ;;
60       *)
61         optarg=""
62         ;;
63   esac
64
65   case $option in
66       --help | -help | -h)
67           print_help="yes" ;;
68       --prefix=)
69           SBCL_PREFIX=$optarg ;;
70       --xc-host=)
71           SBCL_XC_HOST=$optarg ;;
72
73   *)
74     bad_option "Unknown command-line option to $0: \"$option\""
75   esac
76 done
77
78 if test "$print_help" = "yes"
79 then
80   cat <<EOF
81 \`make.sh' drives the SBCL build.
82
83 Usage: $0 [OPTION]...
84
85   Important: make.sh does not currently control the entirety of the
86   build: configuration file customize-target-features.lisp and certain
87   environment variables play a role as well. see file INSTALL for
88   details.
89
90 Options:
91   -h, --help           Display this help and exit.
92
93   --prefix=<path>      Specify the install location.
94
95       Script install.sh installs SBCL under the specified prefix
96       path: runtime as prefix/bin/sbcl, additional files under
97       prefix/lib/sbcl, and documentation under prefix/share.
98
99       This option also affects the binaries: built-in default for
100       SBCL_HOME is: prefix/lib/sbcl/
101
102       Default prefix is: /usr/local
103
104   --xc-host=<string>   Specify the Common Lisp compilation host.
105
106       The string provided should be a command to invoke the
107       cross-compilation Lisp system in such a way, that it reads
108       commands from standard input, and terminates when it reaches end
109       of file on standard input.
110
111       Examples:
112
113        "sbcl --disable-debugger --no-sysinit --no-userinit"
114                   Use an existing SBCL binary as a cross-compilation
115                   host even though you have stuff in your
116                   initialization files which makes it behave in such a
117                   non-standard way that it keeps the build from
118                   working. Also disable the debugger instead of
119                   waiting endlessly for a programmer to help it out
120                   with input on *DEBUG-IO*. (This is the default.)
121
122        "sbcl"
123                   Use an existing SBCL binary as a cross-compilation
124                   host, including your initialization files and
125                   building with the debugger enabled. Not recommended
126                   for casual users.
127
128        "lisp -noinit -batch"
129                   Use an existing CMU CL binary as a cross-compilation
130                   host when you have weird things in your .cmucl-init
131                   file.
132 EOF
133   exit
134 fi
135
136 build_started=`date`
137 echo "//Starting build: $build_started"
138 # Apparently option parsing succeeded. Print out the results.
139 echo "//Options: --prefix='$SBCL_PREFIX' --xc-host='$SBCL_XC_HOST'"
140
141 # Save prefix for make and install.sh.
142 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
143
144 # FIXME: Tweak this script, and the rest of the system, to support
145 # a second bootstrapping pass in which the cross-compilation host is
146 # known to be SBCL itself, so that the cross-compiler can do some
147 # optimizations (especially specializable arrays) that it doesn't
148 # know how to implement how in a portable way. (Or maybe that wouldn't
149 # require a second pass, just testing at build-the-cross-compiler time
150 # whether the cross-compilation host returns suitable values from
151 # UPGRADED-ARRAY-ELEMENT-TYPE?)
152
153 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
154     DEVNULL=NUL
155 else
156     DEVNULL=/dev/null
157 fi
158 export DEVNULL
159
160 . ./find-gnumake.sh
161 find_gnumake
162
163 # If you're cross-compiling, you should probably just walk through the
164 # make-config.sh script by hand doing the right thing on both the host
165 # and target machines.
166 sh make-config.sh
167
168 # Enforce the source policy for no bogus whitespace
169 tools-for-build/canonicalize-whitespace
170
171 # The make-host-*.sh scripts are run on the cross-compilation host,
172 # and the make-target-*.sh scripts are run on the target machine. In
173 # ordinary compilation, we just do these phases consecutively on the
174 # same machine, but if you wanted to cross-compile from one machine
175 # which supports Common Lisp to another which does not (yet:-) support
176 # Common Lisp, you could do something like this:
177 #   Create copies of the source tree on both the host and the target.
178 #   Read the make-config.sh script carefully and emulate it by hand
179 #     on both machines (e.g. creating "target"-named symlinks to
180 #     identify the target architecture).
181 #   On the host system:
182 #     SBCL_XC_HOST=<whatever> sh make-host-1.sh
183 #   Copy src/runtime/genesis/*.h from the host system to the target
184 #     system.
185 #   On the target system:
186 #     sh make-target-1.sh
187 #   Copy src/runtime/sbcl.nm and output/stuff-groveled-from-headers.lisp
188 #     from the target system to the host system.
189 #   On the host system:
190 #     SBCL_XC_HOST=<whatever> sh make-host-2.sh
191 #   Copy output/cold-sbcl.core from the host system to the target system.
192 #   On the target system:
193 #     sh make-target-2.sh
194 #     sh make-target-contrib.sh
195 # Or, if you can set up the files somewhere shared (with NFS, AFS, or
196 # whatever) between the host machine and the target machine, the basic
197 # procedure above should still work, but you can skip the "copy" steps.
198 time sh make-host-1.sh
199 time sh make-target-1.sh
200 time sh make-host-2.sh
201 time sh make-target-2.sh
202 time sh make-target-contrib.sh
203
204 NCONTRIBS=`find contrib -name Makefile -print | wc -l`
205 NPASSED=`find contrib -name test-passed -print | wc -l`
206 echo
207 echo "The build seems to have finished successfully, including $NPASSED (out of $NCONTRIBS)"
208 echo "contributed modules. If you would like to run more extensive tests on"
209 echo "the new SBCL, you can try:"
210 echo
211 echo "  cd tests && sh ./run-tests.sh"
212 echo
213 echo "  (All tests should pass on x86/Linux, x86/FreeBSD4, and ppc/Darwin. On"
214 echo "  other platforms some failures are currently expected; patches welcome"
215 echo "  as always.)"
216 echo
217 echo "To build documentation:"
218 echo
219 echo "  cd doc/manual && make"
220 echo
221 echo "To install SBCL (more information in INSTALL):"
222 echo
223 echo "  sh install.sh"
224
225 build_finished=`date`
226 echo
227 echo "//build started:  $build_started"
228 echo "//build finished: $build_finished"