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