4 # The make-config.sh script uses information about the target machine
5 # to set things up for compilation. It's vaguely like a stripped-down
6 # version of autoconf. It's intended to be run as part of make.sh. The
7 # only time you'd want to run it by itself is if you're trying to
8 # cross-compile the system or if you're doing some kind of
11 # This software is part of the SBCL system. See the README file for
14 # This software is derived from the CMU CL system, which was
15 # written at Carnegie Mellon University and released into the
16 # public domain. The software is in the public domain and is
17 # provided with absolutely no warranty. See the COPYING and CREDITS
18 # files for more information.
22 # The classic form here was to use --userinit $DEVNULL --sysinit
23 # $DEVNULL, but that doesn't work on Win32 because SBCL doesn't handle
24 # device names properly. We still need $DEVNULL to be NUL on Win32
25 # because it's used elsewhere (such as canonicalize-whitespace), so we
26 # need an alternate solution for the init file overrides. --no-foos
27 # have now been available long enough that this should not stop anyone
29 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ]
31 SBCL_PREFIX="$PROGRAMFILES/sbcl"
33 SBCL_PREFIX="/usr/local"
35 SBCL_XC_HOST="sbcl --disable-debugger --no-userinit --no-sysinit"
38 # Parse command-line options.
41 echo "Enter \"$0 --help\" for list of valid options."
49 # Split --foo=bar into --foo and bar.
52 # For ease of scripting treat skip valued options with empty
54 optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
55 option=`expr "X$option" : 'X\([^=]*=\).*'`
66 $optarg_ok && SBCL_PREFIX=$optarg
69 $oparg_ok && SBCL_ARCH=$optarg
72 $optarg_ok && SBCL_XC_HOST=$optarg
74 --dynamic-space-size=)
75 $optarg_ok && SBCL_DYNAMIC_SPACE_SIZE=$optarg
78 bad_option "Unknown command-line option to $0: \"$option\""
83 bad_option "Unknown command-line option to $0: \"$option\""
85 legacy_xc_spec=$option
92 # Previously XC host was provided as a positional argument.
93 if test -n "$legacy_xc_spec"
95 SBCL_XC_HOST="$legacy_xc_spec"
98 if test "$print_help" = "yes"
101 \`make.sh' drives the SBCL build.
103 Usage: $0 [OPTION]...
105 Important: make.sh does not currently control the entirety of the
106 build: configuration file customize-target-features.lisp and certain
107 environment variables play a role as well. see file INSTALL for
111 -h, --help Display this help and exit.
113 --prefix=<path> Specify the install location.
115 Script install.sh installs SBCL under the specified prefix
116 path: runtime as prefix/bin/sbcl, additional files under
117 prefix/lib/sbcl, and documentation under prefix/share.
119 This option also affects the binaries: built-in default for
120 SBCL_HOME is: prefix/lib/sbcl/
122 Default prefix is: /usr/local
124 --dynamic-space-size=<size> Default dynamic-space size for target.
126 This specifies the default dynamic-space size for the SBCL
127 being built. If you need to control the dynamic-space size
128 of the host SBCL, use the --xc-host option.
130 If not provided, the default is platform-specific. <size> is
131 taken to be megabytes unless explicitly suffixed with Gb in
132 order to specify the size in gigabytes.
134 --arch=<string> Specify the architecture to build for.
136 Mainly for doing x86 builds on x86-64.
138 --xc-host=<string> Specify the Common Lisp compilation host.
140 The string provided should be a command to invoke the
141 cross-compilation Lisp system in such a way, that it reads
142 commands from standard input, and terminates when it reaches end
143 of file on standard input.
147 "sbcl --disable-debugger --no-sysinit --no-userinit"
148 Use an existing SBCL binary as a cross-compilation
149 host even though you have stuff in your
150 initialization files which makes it behave in such a
151 non-standard way that it keeps the build from
152 working. Also disable the debugger instead of
153 waiting endlessly for a programmer to help it out
154 with input on *DEBUG-IO*. (This is the default.)
157 Use an existing SBCL binary as a cross-compilation
158 host, including your initialization files and
159 building with the debugger enabled. Not recommended
162 "lisp -noinit -batch"
163 Use an existing CMU CL binary as a cross-compilation
164 host when you have weird things in your .cmucl-init
171 # Save prefix for make and install.sh.
172 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
173 echo "$SBCL_DYNAMIC_SPACE_SIZE" > output/dynamic-space-size.txt
175 # FIXME: Tweak this script, and the rest of the system, to support
176 # a second bootstrapping pass in which the cross-compilation host is
177 # known to be SBCL itself, so that the cross-compiler can do some
178 # optimizations (especially specializable arrays) that it doesn't
179 # know how to implement how in a portable way. (Or maybe that wouldn't
180 # require a second pass, just testing at build-the-cross-compiler time
181 # whether the cross-compilation host returns suitable values from
182 # UPGRADED-ARRAY-ELEMENT-TYPE?)
184 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
194 . ./generate-version.sh
197 # Now that we've done our option parsing and found various
198 # dependencies, write them out to a file to be sourced by other
201 echo "DEVNULL=\"$DEVNULL\"; export DEVNULL" > output/build-config
202 echo "GNUMAKE=\"$GNUMAKE\"; export GNUMAKE" >> output/build-config
203 echo "SBCL_XC_HOST=\"$SBCL_XC_HOST\"; export SBCL_XC_HOST" >> output/build-config
204 echo "legacy_xc_spec=\"$legacy_xc_spec\"; export legacy_xc_spec" >> output/build-config
206 # And now, sorting out the per-target dependencies...
213 # it's changed name twice since it was called OSF/1: clearly
214 # the marketers forgot to tell the engineers about Digital Unix
230 echo unsupported BSD variant: `uname`
241 CYGWIN* | WindowsNT | MINGW*)
248 echo unsupported OS type: `uname`
254 if [ "$sbcl_os" = "win32" ] ; then
261 remove_dir_safely() {
262 if [ "$sbcl_os" = "win32" ] ; then
263 if [ -d "$1" ] ; then
265 elif [ -e "$1" ] ; then
266 echo "I'm afraid to remove non-directory $1."
270 if [ -h "$1" ] ; then
272 elif [ -w "$1" ] ; then
273 echo "I'm afraid to replace non-symlink $1 with a symlink."
279 echo //entering make-config.sh
281 echo //ensuring the existence of output/ directory
282 if [ ! -d output ] ; then mkdir output; fi
284 ltf=`pwd`/local-target-features.lisp-expr
285 echo //initializing $ltf
286 echo ';;;; This is a machine-generated file.' > $ltf
287 echo ';;;; Please do not edit it by hand.' >> $ltf
288 echo ';;;; See make-config.sh.' >> $ltf
291 echo //guessing default target CPU architecture from host architecture
293 *86) guessed_sbcl_arch=x86 ;;
294 i86pc) guessed_sbcl_arch=x86 ;;
295 *x86_64) guessed_sbcl_arch=x86-64 ;;
296 amd64) guessed_sbcl_arch=x86-64 ;;
297 [Aa]lpha) guessed_sbcl_arch=alpha ;;
298 sparc*) guessed_sbcl_arch=sparc ;;
299 sun*) guessed_sbcl_arch=sparc ;;
300 *ppc) guessed_sbcl_arch=ppc ;;
301 ppc64) guessed_sbcl_arch=ppc ;;
302 Power*Macintosh) guessed_sbcl_arch=ppc ;;
303 parisc) guessed_sbcl_arch=hppa ;;
304 9000/800) guessed_sbcl_arch=hppa ;;
305 mips*) guessed_sbcl_arch=mips ;;
307 # If we're not building on a supported target architecture, we
308 # we have no guess, but it's not an error yet, since maybe
309 # target architecture will be specified explicitly below.
314 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
315 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
316 guessed_sbcl_arch=x86-64
319 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
320 if [ "$sbcl_os" = "darwin" ] && [ "`/usr/sbin/sysctl -n hw.optional.x86_64`" = "1" ]; then
321 guessed_sbcl_arch=x86-64
324 echo //setting up CPU-architecture-dependent information
325 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
326 echo sbcl_arch=\"$sbcl_arch\"
327 if [ "$sbcl_arch" = "" ] ; then
328 echo "can't guess target SBCL architecture, please specify --arch=<name>"
331 printf ":%s" "$sbcl_arch" >> $ltf
333 echo //setting up OS-dependent information
335 # Under Darwin x86-64, guess whether Darwin 9+ or below.
336 if [ "$sbcl_os" = "darwin" ] && [ "$sbcl_arch" = "x86-64" ]; then
337 darwin_version=`uname -r`
338 darwin_version_major=${DARWIN_VERSION_MAJOR:-${darwin_version%%.*}}
339 if (( 8 < $darwin_version_major )); then
340 printf ' :inode64 :darwin9-or-better' >> $ltf
346 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
347 # KLUDGE: these two logically belong in the previous section
348 # ("architecture-dependent"); it seems silly to enforce this in terms
349 # of the shell script, though. -- CSR, 2002-02-03
350 link_or_copy $sbcl_arch-arch.h target-arch.h
351 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
354 printf ' :unix' >> $ltf
355 printf ' :elf' >> $ltf
356 printf ' :linux' >> $ltf
358 # If you add other platforms here, don't forget to edit
359 # src/runtime/Config.foo-linux too.
362 printf ' :largefile' >> $ltf
365 printf ' :sb-thread :sb-futex :largefile' >> $ltf
368 printf ' :sb-futex' >> $ltf
372 if [ $sbcl_arch = "x86-64" ]; then
373 link_or_copy Config.x86_64-linux Config
375 link_or_copy Config.$sbcl_arch-linux Config
377 link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
378 link_or_copy linux-os.h target-os.h
381 printf ' :unix' >> $ltf
382 printf ' :elf' >> $ltf
383 printf ' :osf1' >> $ltf
384 link_or_copy Config.$sbcl_arch-osf1 Config
385 link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
386 link_or_copy osf1-os.h target-os.h
389 printf ' :unix' >> $ltf
390 printf ' :elf' >> $ltf
391 printf ' :hpux' >> $ltf
392 link_or_copy Config.$sbcl_arch-hpux Config
393 link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
394 link_or_copy hpux-os.h target-os.h
397 printf ' :unix' >> $ltf
398 printf ' :bsd' >> $ltf
399 link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
400 link_or_copy bsd-os.h target-os.h
403 printf ' :elf' >> $ltf
404 printf ' :freebsd' >> $ltf
405 printf ' :gcc-tls' >> $ltf
406 if [ $sbcl_arch = "x86" ]; then
407 printf ' :restore-tls-segment-register-from-context' >> $ltf
409 link_or_copy Config.$sbcl_arch-freebsd Config
412 printf ' :elf' >> $ltf
413 printf ' :openbsd' >> $ltf
414 link_or_copy Config.$sbcl_arch-openbsd Config
417 printf ' :netbsd' >> $ltf
418 printf ' :elf' >> $ltf
419 link_or_copy Config.$sbcl_arch-netbsd Config
422 echo unsupported BSD variant: `uname`
428 printf ' :unix' >> $ltf
429 printf ' :mach-o' >> $ltf
430 printf ' :bsd' >> $ltf
431 printf ' :darwin' >> $ltf
432 if [ $sbcl_arch = "x86" ]; then
433 printf ' :mach-exception-handler :restore-fs-segment-register-from-tls :ud2-breakpoints' >> $ltf
435 if [ $sbcl_arch = "x86-64" ]; then
436 printf ' :mach-exception-handler :ud2-breakpoints' >> $ltf
438 link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
439 link_or_copy bsd-os.h target-os.h
440 link_or_copy Config.$sbcl_arch-darwin Config
443 printf ' :unix' >> $ltf
444 printf ' :elf' >> $ltf
445 printf ' :sunos' >> $ltf
446 if [ $sbcl_arch = "x86-64" ]; then
447 printf ' :largefile' >> $ltf
449 link_or_copy Config.$sbcl_arch-sunos Config
450 link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
451 link_or_copy sunos-os.h target-os.h
454 printf ' :win32' >> $ltf
455 link_or_copy Config.$sbcl_arch-win32 Config
456 link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
457 link_or_copy win32-os.h target-os.h
460 echo unsupported OS type: `uname`
466 # FIXME: Things like :c-stack-grows-..., etc, should be
467 # *derived-target-features* or equivalent, so that there was a nicer
468 # way to specify them then sprinkling them in this file. They should
469 # still be tweakable by advanced users, though, but probably not
470 # appear in *features* of target. #!+/- should be adjusted to take
471 # them in account as well. At minimum the nicer specification stuff,
474 # (define-feature :dlopen (features)
475 # (union '(:bsd :linux :darwin :sunos) features))
477 # (define-feature :c-stack-grows-downwards-not-upwards (features)
478 # (member :x86 features))
480 # KLUDGE: currently the x86 only works with the generational garbage
481 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
482 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
483 # the absence of :GENCGC in *FEATURES*). This isn't a great
484 # separation, but for now, rather than have :GENCGC in
485 # base-target-features.lisp-expr, we add it into local-target-features
486 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
487 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
488 if [ "$sbcl_arch" = "x86" ]; then
489 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
490 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
491 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
492 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
493 printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
494 printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
496 linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
497 printf ' :linkage-table' >> $ltf
499 if [ "$sbcl_os" = "win32" ]; then
500 # of course it doesn't provide dlopen, but there is
501 # roughly-equivalent magic nevertheless.
502 printf ' :os-provides-dlopen' >> $ltf
504 if [ "$sbcl_os" = "openbsd" ]; then
505 rm -f src/runtime/openbsd-sigcontext.h
506 sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
508 elif [ "$sbcl_arch" = "x86-64" ]; then
509 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
510 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
511 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
512 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
513 printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
514 printf ' :float-eql-vops :inline-constants :memory-barrier-vops' >> $ltf
515 printf ' :multiply-high-vops' >> $ltf
516 elif [ "$sbcl_arch" = "mips" ]; then
517 printf ' :linkage-table' >> $ltf
518 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
519 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
520 printf ' :alien-callbacks' >> $ltf
521 # Use a little C program to try to guess the endianness. Ware
524 # FIXME: integrate to grovel-features, mayhaps
525 $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
526 tools-for-build/determine-endianness >> $ltf
527 elif [ "$sbcl_arch" = "ppc" ]; then
528 printf ' :gencgc :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
529 printf ' :linkage-table :raw-instance-init-vops :memory-barrier-vops' >> $ltf
530 printf ' :compare-and-swap-vops :multiply-high-vops' >> $ltf
531 if [ "$sbcl_os" = "linux" ]; then
532 # Use a C program to detect which kind of glibc we're building on,
533 # to bandage across the break in source compatibility between
534 # versions 2.3.1 and 2.3.2
536 # FIXME: integrate to grovel-features, mayhaps
537 $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
538 tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
539 elif [ "$sbcl_os" = "darwin" ]; then
540 # We provide a dlopen shim, so a little lie won't hurt
541 printf " :os-provides-dlopen :alien-callbacks" >> $ltf
542 # The default stack ulimit under darwin is too small to run PURIFY.
543 # Best we can do is complain and exit at this stage
544 if [ "`ulimit -s`" = "512" ]; then
545 echo "Your stack size limit is too small to build SBCL."
546 echo "See the limit(1) or ulimit(1) commands and the README file."
550 elif [ "$sbcl_arch" = "sparc" ]; then
551 # Test the compiler in order to see if we are building on Sun
552 # toolchain as opposed to GNU binutils, and write the appropriate
553 # FUNCDEF macro for assembler. No harm in running this on sparc-linux
555 sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
556 if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
557 printf ' :linkage-table' >> $ltf
559 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
560 elif [ "$sbcl_arch" = "alpha" ]; then
561 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
562 elif [ "$sbcl_arch" = "hppa" ]; then
563 printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
564 printf ' :stack-allocatable-lists' >> $ltf
566 # Nothing need be done in this case, but sh syntax wants a placeholder.
570 export sbcl_os sbcl_arch
571 sh tools-for-build/grovel-features.sh >> $ltf
573 echo //finishing $ltf
576 # FIXME: The version system should probably be redone along these lines:
578 # echo //setting up version information.
579 # versionfile=version.txt
580 # cp base-version.txt $versionfile
581 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
582 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
584 # Make a unique ID for this build (to discourage people from
585 # mismatching sbcl and *.core files).
586 if [ `uname` = "SunOS" ] ; then
587 # use /usr/xpg4/bin/id instead of /usr/bin/id
588 PATH=/usr/xpg4/bin:$PATH
590 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp