1.0.41.53: more make.sh tweakery, part N
[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 bad_option() {
43     echo $1
44     echo "Enter \"$0 --help\" for list of valid options."
45     exit 1
46 }
47
48 some_options=false
49 for option
50 do
51   optarg_ok=true
52   # Split --foo=bar into --foo and bar.
53   case $option in
54       *=*)
55         # For ease of scripting treat skip valued options with empty
56         # values.
57         optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
58         option=`expr "X$option" : 'X\([^=]*=\).*'`
59         ;;
60       *)
61         optarg=""
62         ;;
63   esac
64
65   case $option in
66       --help | -help | -h)
67         print_help="yes" ;;
68       --prefix=)
69         $optarg_ok && SBCL_PREFIX=$optarg
70         ;;
71       --xc-host=)
72         $optarg_ok && SBCL_XC_HOST=$optarg
73         ;;
74       -*)
75         bad_option "Unknown command-line option to $0: \"$option\""
76         ;;
77       *)
78         if $some_options
79         then
80             bad_option "Unknown command-line option to $0: \"$option\""
81         else
82             legacy_xc_spec=$option
83         fi
84         ;;
85   esac
86   some_options=true
87 done
88
89 # Previously XC host was provided as a positional argument. 
90 if test -n "$legacy_xc_spec"
91 then
92     SBCL_XC_HOST="$legacy_xc_spec"
93 fi
94
95 if test "$print_help" = "yes"
96 then
97   cat <<EOF
98 \`make.sh' drives the SBCL build.
99
100 Usage: $0 [OPTION]...
101
102   Important: make.sh does not currently control the entirety of the
103   build: configuration file customize-target-features.lisp and certain
104   environment variables play a role as well. see file INSTALL for
105   details.
106
107 Options:
108   -h, --help           Display this help and exit.
109
110   --prefix=<path>      Specify the install location.
111
112       Script install.sh installs SBCL under the specified prefix
113       path: runtime as prefix/bin/sbcl, additional files under
114       prefix/lib/sbcl, and documentation under prefix/share.
115
116       This option also affects the binaries: built-in default for
117       SBCL_HOME is: prefix/lib/sbcl/
118
119       Default prefix is: /usr/local
120
121   --xc-host=<string>   Specify the Common Lisp compilation host.
122
123       The string provided should be a command to invoke the
124       cross-compilation Lisp system in such a way, that it reads
125       commands from standard input, and terminates when it reaches end
126       of file on standard input.
127
128       Examples:
129
130        "sbcl --disable-debugger --no-sysinit --no-userinit"
131                   Use an existing SBCL binary as a cross-compilation
132                   host even though you have stuff in your
133                   initialization files which makes it behave in such a
134                   non-standard way that it keeps the build from
135                   working. Also disable the debugger instead of
136                   waiting endlessly for a programmer to help it out
137                   with input on *DEBUG-IO*. (This is the default.)
138
139        "sbcl"
140                   Use an existing SBCL binary as a cross-compilation
141                   host, including your initialization files and
142                   building with the debugger enabled. Not recommended
143                   for casual users.
144
145        "lisp -noinit -batch"
146                   Use an existing CMU CL binary as a cross-compilation
147                   host when you have weird things in your .cmucl-init
148                   file.
149 EOF
150   exit
151 fi
152
153 build_started=`date`
154 echo "//Starting build: $build_started"
155 # Apparently option parsing succeeded. Print out the results.
156 echo "//Options: --prefix='$SBCL_PREFIX' --xc-host='$SBCL_XC_HOST'"
157
158 # Save prefix for make and install.sh.
159 mkdir -p output
160 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
161
162 # FIXME: Tweak this script, and the rest of the system, to support
163 # a second bootstrapping pass in which the cross-compilation host is
164 # known to be SBCL itself, so that the cross-compiler can do some
165 # optimizations (especially specializable arrays) that it doesn't
166 # know how to implement how in a portable way. (Or maybe that wouldn't
167 # require a second pass, just testing at build-the-cross-compiler time
168 # whether the cross-compilation host returns suitable values from
169 # UPGRADED-ARRAY-ELEMENT-TYPE?)
170
171 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
172     DEVNULL=NUL
173 else
174     DEVNULL=/dev/null
175 fi
176 export DEVNULL
177
178 . ./find-gnumake.sh
179 find_gnumake
180
181 # If you're cross-compiling, you should probably just walk through the
182 # make-config.sh script by hand doing the right thing on both the host
183 # and target machines.
184 sh make-config.sh
185
186 # Enforce the source policy for no bogus whitespace
187 tools-for-build/canonicalize-whitespace
188
189 # The make-host-*.sh scripts are run on the cross-compilation host,
190 # and the make-target-*.sh scripts are run on the target machine. In
191 # ordinary compilation, we just do these phases consecutively on the
192 # same machine, but if you wanted to cross-compile from one machine
193 # which supports Common Lisp to another which does not (yet:-) support
194 # Common Lisp, you could do something like this:
195 #   Create copies of the source tree on both the host and the target.
196 #   Read the make-config.sh script carefully and emulate it by hand
197 #     on both machines (e.g. creating "target"-named symlinks to
198 #     identify the target architecture).
199 #   On the host system:
200 #     SBCL_XC_HOST=<whatever> sh make-host-1.sh
201 #   Copy src/runtime/genesis/*.h from the host system to the target
202 #     system.
203 #   On the target system:
204 #     sh make-target-1.sh
205 #   Copy src/runtime/sbcl.nm and output/stuff-groveled-from-headers.lisp
206 #     from the target system to the host system.
207 #   On the host system:
208 #     SBCL_XC_HOST=<whatever> sh make-host-2.sh
209 #   Copy output/cold-sbcl.core from the host system to the target system.
210 #   On the target system:
211 #     sh make-target-2.sh
212 #     sh make-target-contrib.sh
213 # Or, if you can set up the files somewhere shared (with NFS, AFS, or
214 # whatever) between the host machine and the target machine, the basic
215 # procedure above should still work, but you can skip the "copy" steps.
216 time sh make-host-1.sh
217 time sh make-target-1.sh
218 time sh make-host-2.sh
219 time sh make-target-2.sh
220 time sh make-target-contrib.sh
221
222 NCONTRIBS=`find contrib -name Makefile -print | wc -l`
223 NPASSED=`find contrib -name test-passed -print | wc -l`
224 echo
225 echo "The build seems to have finished successfully, including $NPASSED (out of $NCONTRIBS)"
226 echo "contributed modules. If you would like to run more extensive tests on"
227 echo "the new SBCL, you can try:"
228 echo
229 echo "  cd tests && sh ./run-tests.sh"
230 echo
231 echo "  (All tests should pass on x86/Linux, x86/FreeBSD4, and ppc/Darwin. On"
232 echo "  other platforms some failures are currently expected; patches welcome"
233 echo "  as always.)"
234 echo
235 echo "To build documentation:"
236 echo
237 echo "  cd doc/manual && make"
238 echo
239 echo "To install SBCL (more information in INSTALL):"
240 echo
241 echo "  sh install.sh"
242
243 # This is probably the best place to ensure people will see this.
244 if test -n "$legacy_xc_spec"
245 then
246     echo <<EOF
247 ******************************************************************************
248 **
249 **  Old-style XC-host specification detected: '$SBCL_XC_HOST'
250 **
251 **  Since 1.0.41.45 SBCL expects the XC-host to be specified using
252 **  the --xc-host='myhost' command line option, not with a positional
253 **  argument. The legacy style still works, but will not be supported
254 **  indefinitely. Please update your build procedure.
255 **
256 ******************************************************************************
257 EOF
258 fi
259
260 build_finished=`date`
261 echo
262 echo "//build started:  $build_started"
263 echo "//build finished: $build_finished"