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."
47 FANCY_FEATURES=":sb-core-compression :sb-xref-for-internals :sb-after-xc-core"
54 # Split --foo=bar into --foo and bar.
57 # For ease of scripting skip valued options with empty
59 optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
60 option=`expr "X$option" : 'X\([^=]*=\).*'`
63 optarg=`expr "X$option" : 'X--[^-]*-\(.*\)'` \
64 || bad_option "Malformed feature toggle: $option"
65 option=`expr "X$option" : 'X\(--[^-]*\).*'`
76 $optarg_ok && SBCL_PREFIX=$optarg
79 $oparg_ok && SBCL_ARCH=$optarg
82 $optarg_ok && SBCL_XC_HOST=$optarg
84 --dynamic-space-size=)
85 $optarg_ok && SBCL_DYNAMIC_SPACE_SIZE=$optarg
88 WITH_FEATURES="$WITH_FEATURES :$optarg"
91 WITHOUT_FEATURES="$WITHOUT_FEATURES :$optarg"
94 WITH_FEATURES="$WITH_FEATURES $FANCY_FEATURES"
95 # Lower down we add :sb-thread for platforms where it can be built.
99 bad_option "Unknown command-line option to $0: \"$option\""
104 bad_option "Unknown command-line option to $0: \"$option\""
106 legacy_xc_spec=$option
113 if (test -f customize-target-features.lisp && \
114 (test -n "$WITH_FEATURES" || test -n "$WITHOUT_FEATURES"))
116 # Actually there's no reason why it would not work, but it would
117 # be confusing to say --with-thread only to have it turned off by
118 # customize-target-features.lisp...
119 echo "ERROR: Both customize-target-features.lisp, and feature-options"
120 echo "to make.sh present -- cannot use both at the same time."
124 # Previously XC host was provided as a positional argument.
125 if test -n "$legacy_xc_spec"
127 SBCL_XC_HOST="$legacy_xc_spec"
130 if test "$print_help" = "yes"
133 \`make.sh' drives the SBCL build.
135 Usage: $0 [OPTION]...
137 Important: make.sh does not currently control the entirety of the
138 build: configuration file customize-target-features.lisp and certain
139 environment variables play a role as well. see file INSTALL for
143 -h, --help Display this help and exit.
145 --prefix=<path> Specify the install location.
147 Script install.sh installs SBCL under the specified prefix
148 path: runtime as prefix/bin/sbcl, additional files under
149 prefix/lib/sbcl, and documentation under prefix/share.
151 This option also affects the binaries: built-in default for
152 SBCL_HOME is: prefix/lib/sbcl/
154 Default prefix is: /usr/local
156 --dynamic-space-size=<size> Default dynamic-space size for target.
158 This specifies the default dynamic-space size for the SBCL
159 being built. If you need to control the dynamic-space size
160 of the host SBCL, use the --xc-host option.
162 If not provided, the default is platform-specific. <size> is
163 taken to be megabytes unless explicitly suffixed with Gb in
164 order to specify the size in gigabytes.
166 --with-<feature> Build with specified feature.
167 --without-<feature> Build wihout the specfied feature.
169 --fancy Build with several optional features:
173 Plus threading on platforms which support it.
175 --arch=<string> Specify the architecture to build for.
177 Mainly for doing x86 builds on x86-64.
179 --xc-host=<string> Specify the Common Lisp compilation host.
181 The string provided should be a command to invoke the
182 cross-compilation Lisp system in such a way, that it reads
183 commands from standard input, and terminates when it reaches end
184 of file on standard input.
188 "sbcl --disable-debugger --no-sysinit --no-userinit"
189 Use an existing SBCL binary as a cross-compilation
190 host even though you have stuff in your
191 initialization files which makes it behave in such a
192 non-standard way that it keeps the build from
193 working. Also disable the debugger instead of
194 waiting endlessly for a programmer to help it out
195 with input on *DEBUG-IO*. (This is the default.)
198 Use an existing SBCL binary as a cross-compilation
199 host, including your initialization files and
200 building with the debugger enabled. Not recommended
203 "lisp -noinit -batch"
204 Use an existing CMU CL binary as a cross-compilation
205 host when you have weird things in your .cmucl-init
212 # Save prefix for make and install.sh.
213 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
214 echo "$SBCL_DYNAMIC_SPACE_SIZE" > output/dynamic-space-size.txt
216 # FIXME: Tweak this script, and the rest of the system, to support
217 # a second bootstrapping pass in which the cross-compilation host is
218 # known to be SBCL itself, so that the cross-compiler can do some
219 # optimizations (especially specializable arrays) that it doesn't
220 # know how to implement how in a portable way. (Or maybe that wouldn't
221 # require a second pass, just testing at build-the-cross-compiler time
222 # whether the cross-compilation host returns suitable values from
223 # UPGRADED-ARRAY-ELEMENT-TYPE?)
225 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
235 . ./generate-version.sh
238 # Now that we've done our option parsing and found various
239 # dependencies, write them out to a file to be sourced by other
242 echo "DEVNULL=\"$DEVNULL\"; export DEVNULL" > output/build-config
243 echo "GNUMAKE=\"$GNUMAKE\"; export GNUMAKE" >> output/build-config
244 echo "SBCL_XC_HOST=\"$SBCL_XC_HOST\"; export SBCL_XC_HOST" >> output/build-config
245 echo "legacy_xc_spec=\"$legacy_xc_spec\"; export legacy_xc_spec" >> output/build-config
247 # And now, sorting out the per-target dependencies...
254 # it's changed name twice since it was called OSF/1: clearly
255 # the marketers forgot to tell the engineers about Digital Unix
271 echo unsupported BSD variant: `uname`
282 CYGWIN* | WindowsNT | MINGW*)
289 echo unsupported OS type: `uname`
295 if [ "$sbcl_os" = "win32" ] ; then
302 remove_dir_safely() {
303 if [ "$sbcl_os" = "win32" ] ; then
304 if [ -d "$1" ] ; then
306 elif [ -e "$1" ] ; then
307 echo "I'm afraid to remove non-directory $1."
311 if [ -h "$1" ] ; then
313 elif [ -w "$1" ] ; then
314 echo "I'm afraid to replace non-symlink $1 with a symlink."
320 echo //entering make-config.sh
322 echo //ensuring the existence of output/ directory
323 if [ ! -d output ] ; then mkdir output; fi
325 echo //guessing default target CPU architecture from host architecture
327 *86) guessed_sbcl_arch=x86 ;;
328 i86pc) guessed_sbcl_arch=x86 ;;
329 *x86_64) guessed_sbcl_arch=x86-64 ;;
330 amd64) guessed_sbcl_arch=x86-64 ;;
331 [Aa]lpha) guessed_sbcl_arch=alpha ;;
332 sparc*) guessed_sbcl_arch=sparc ;;
333 sun*) guessed_sbcl_arch=sparc ;;
334 *ppc) guessed_sbcl_arch=ppc ;;
335 ppc64) guessed_sbcl_arch=ppc ;;
336 Power*Macintosh) guessed_sbcl_arch=ppc ;;
337 parisc) guessed_sbcl_arch=hppa ;;
338 9000/800) guessed_sbcl_arch=hppa ;;
339 mips*) guessed_sbcl_arch=mips ;;
341 # If we're not building on a supported target architecture, we
342 # we have no guess, but it's not an error yet, since maybe
343 # target architecture will be specified explicitly below.
348 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
349 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
350 guessed_sbcl_arch=x86-64
353 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
354 if [ "$sbcl_os" = "darwin" ] && [ "`/usr/sbin/sysctl -n hw.optional.x86_64`" = "1" ]; then
355 guessed_sbcl_arch=x86-64
358 echo //setting up CPU-architecture-dependent information
359 if test -n "$SBCL_ARCH"
362 SBCL_ARCH=`echo $SBCL_ARCH | tr '[A-Z]' '[a-z]' | tr _ -`
364 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
365 echo sbcl_arch=\"$sbcl_arch\"
366 if [ "$sbcl_arch" = "" ] ; then
367 echo "can't guess target SBCL architecture, please specify --arch=<name>"
372 # If --fancy, enable threads on platforms where they can be built.
375 if [ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]
377 echo "No threads on this platform."
379 WITH_FEATURES="$WITH_FEATURES :sb-thread"
380 echo "Enabling threads due to --fancy."
384 echo "No threads on this platform."
389 ltf=`pwd`/local-target-features.lisp-expr
390 echo //initializing $ltf
391 echo ';;;; This is a machine-generated file.' > $ltf
392 echo ';;;; Please do not edit it by hand.' >> $ltf
393 echo ';;;; See make-config.sh.' >> $ltf
394 echo "((lambda (features) (set-difference features (list$WITHOUT_FEATURES)))" >> $ltf
395 printf " (union (list$WITH_FEATURES) (list " >> $ltf
397 printf ":%s" "$sbcl_arch" >> $ltf
399 echo //setting up OS-dependent information
400 # Under Darwin x86-64, guess whether Darwin 9+ or below.
401 if [ "$sbcl_os" = "darwin" ] && [ "$sbcl_arch" = "x86-64" ]; then
402 darwin_version=`uname -r`
403 darwin_version_major=${DARWIN_VERSION_MAJOR:-${darwin_version%%.*}}
404 if (( 8 < $darwin_version_major )); then
405 printf ' :inode64 :darwin9-or-better' >> $ltf
411 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
412 # KLUDGE: these two logically belong in the previous section
413 # ("architecture-dependent"); it seems silly to enforce this in terms
414 # of the shell script, though. -- CSR, 2002-02-03
415 link_or_copy $sbcl_arch-arch.h target-arch.h
416 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
419 printf ' :unix' >> $ltf
420 printf ' :elf' >> $ltf
421 printf ' :linux' >> $ltf
423 # If you add other platforms here, don't forget to edit
424 # src/runtime/Config.foo-linux too.
427 printf ' :largefile' >> $ltf
430 printf ' :sb-thread :sb-futex :largefile' >> $ltf
433 printf ' :sb-futex' >> $ltf
437 if [ $sbcl_arch = "x86-64" ]; then
438 link_or_copy Config.x86_64-linux Config
440 link_or_copy Config.$sbcl_arch-linux Config
442 link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
443 link_or_copy linux-os.h target-os.h
446 printf ' :unix' >> $ltf
447 printf ' :elf' >> $ltf
448 printf ' :osf1' >> $ltf
449 link_or_copy Config.$sbcl_arch-osf1 Config
450 link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
451 link_or_copy osf1-os.h target-os.h
454 printf ' :unix' >> $ltf
455 printf ' :elf' >> $ltf
456 printf ' :hpux' >> $ltf
457 link_or_copy Config.$sbcl_arch-hpux Config
458 link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
459 link_or_copy hpux-os.h target-os.h
462 printf ' :unix' >> $ltf
463 printf ' :bsd' >> $ltf
464 link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
465 link_or_copy bsd-os.h target-os.h
468 printf ' :elf' >> $ltf
469 printf ' :freebsd' >> $ltf
470 printf ' :gcc-tls' >> $ltf
471 if [ $sbcl_arch = "x86" ]; then
472 printf ' :restore-tls-segment-register-from-context' >> $ltf
474 link_or_copy Config.$sbcl_arch-freebsd Config
477 printf ' :elf' >> $ltf
478 printf ' :openbsd' >> $ltf
479 link_or_copy Config.$sbcl_arch-openbsd Config
482 printf ' :netbsd' >> $ltf
483 printf ' :elf' >> $ltf
484 link_or_copy Config.$sbcl_arch-netbsd Config
487 echo unsupported BSD variant: `uname`
493 printf ' :unix' >> $ltf
494 printf ' :mach-o' >> $ltf
495 printf ' :bsd' >> $ltf
496 printf ' :darwin' >> $ltf
497 if [ $sbcl_arch = "x86" ]; then
498 printf ' :mach-exception-handler :restore-fs-segment-register-from-tls :ud2-breakpoints' >> $ltf
500 if [ $sbcl_arch = "x86-64" ]; then
501 printf ' :mach-exception-handler :ud2-breakpoints' >> $ltf
503 link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
504 link_or_copy bsd-os.h target-os.h
505 link_or_copy Config.$sbcl_arch-darwin Config
508 printf ' :unix' >> $ltf
509 printf ' :elf' >> $ltf
510 printf ' :sunos' >> $ltf
511 if [ $sbcl_arch = "x86-64" ]; then
512 printf ' :largefile' >> $ltf
514 link_or_copy Config.$sbcl_arch-sunos Config
515 link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
516 link_or_copy sunos-os.h target-os.h
519 printf ' :win32' >> $ltf
520 link_or_copy Config.$sbcl_arch-win32 Config
521 link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
522 link_or_copy win32-os.h target-os.h
525 echo unsupported OS type: `uname`
531 # FIXME: Things like :c-stack-grows-..., etc, should be
532 # *derived-target-features* or equivalent, so that there was a nicer
533 # way to specify them then sprinkling them in this file. They should
534 # still be tweakable by advanced users, though, but probably not
535 # appear in *features* of target. #!+/- should be adjusted to take
536 # them in account as well. At minimum the nicer specification stuff,
539 # (define-feature :dlopen (features)
540 # (union '(:bsd :linux :darwin :sunos) features))
542 # (define-feature :c-stack-grows-downwards-not-upwards (features)
543 # (member :x86 features))
545 # KLUDGE: currently the x86 only works with the generational garbage
546 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
547 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
548 # the absence of :GENCGC in *FEATURES*). This isn't a great
549 # separation, but for now, rather than have :GENCGC in
550 # base-target-features.lisp-expr, we add it into local-target-features
551 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
552 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
553 if [ "$sbcl_arch" = "x86" ]; then
554 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
555 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
556 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
557 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
558 printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
559 printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
561 linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
562 printf ' :linkage-table' >> $ltf
564 if [ "$sbcl_os" = "win32" ]; then
565 # of course it doesn't provide dlopen, but there is
566 # roughly-equivalent magic nevertheless.
567 printf ' :os-provides-dlopen' >> $ltf
569 if [ "$sbcl_os" = "openbsd" ]; then
570 rm -f src/runtime/openbsd-sigcontext.h
571 sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
573 elif [ "$sbcl_arch" = "x86-64" ]; then
574 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
575 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
576 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
577 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
578 printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
579 printf ' :float-eql-vops :inline-constants :memory-barrier-vops' >> $ltf
580 printf ' :multiply-high-vops' >> $ltf
581 elif [ "$sbcl_arch" = "mips" ]; then
582 printf ' :cheneygc :linkage-table' >> $ltf
583 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
584 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
585 printf ' :alien-callbacks' >> $ltf
586 elif [ "$sbcl_arch" = "ppc" ]; then
587 printf ' :gencgc :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
588 printf ' :linkage-table :raw-instance-init-vops :memory-barrier-vops' >> $ltf
589 printf ' :compare-and-swap-vops :multiply-high-vops' >> $ltf
590 if [ "$sbcl_os" = "linux" ]; then
591 # Use a C program to detect which kind of glibc we're building on,
592 # to bandage across the break in source compatibility between
593 # versions 2.3.1 and 2.3.2
595 # FIXME: integrate to grovel-features, mayhaps
596 $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
597 tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
598 elif [ "$sbcl_os" = "darwin" ]; then
599 # We provide a dlopen shim, so a little lie won't hurt
600 printf " :os-provides-dlopen :alien-callbacks" >> $ltf
601 # The default stack ulimit under darwin is too small to run PURIFY.
602 # Best we can do is complain and exit at this stage
603 if [ "`ulimit -s`" = "512" ]; then
604 echo "Your stack size limit is too small to build SBCL."
605 echo "See the limit(1) or ulimit(1) commands and the README file."
609 elif [ "$sbcl_arch" = "sparc" ]; then
610 # Test the compiler in order to see if we are building on Sun
611 # toolchain as opposed to GNU binutils, and write the appropriate
612 # FUNCDEF macro for assembler. No harm in running this on sparc-linux
614 sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
615 printf ' :cheneygc' >> $ltf
616 if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
617 printf ' :linkage-table' >> $ltf
619 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
620 elif [ "$sbcl_arch" = "alpha" ]; then
621 printf ' :cheneygc' >> $ltf
622 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
623 elif [ "$sbcl_arch" = "hppa" ]; then
624 printf ' :cheneygc' >> $ltf
625 printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
626 printf ' :stack-allocatable-lists' >> $ltf
628 # Nothing need be done in this case, but sh syntax wants a placeholder.
632 # Use a little C program to try to guess the endianness. Ware
635 # FIXME: integrate to grovel-features, mayhaps
636 $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
637 tools-for-build/determine-endianness >> $ltf
639 export sbcl_os sbcl_arch
640 sh tools-for-build/grovel-features.sh >> $ltf
642 echo //finishing $ltf
645 # FIXME: The version system should probably be redone along these lines:
647 # echo //setting up version information.
648 # versionfile=version.txt
649 # cp base-version.txt $versionfile
650 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
651 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
653 # Make a unique ID for this build (to discourage people from
654 # mismatching sbcl and *.core files).
655 if [ `uname` = "SunOS" ] ; then
656 # use /usr/xpg4/bin/id instead of /usr/bin/id
657 PATH=/usr/xpg4/bin:$PATH
659 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp