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."
53 # Split --foo=bar into --foo and bar.
56 # For ease of scripting skip valued options with empty
58 optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
59 option=`expr "X$option" : 'X\([^=]*=\).*'`
62 optarg=`expr "X$option" : 'X--[^-]*-\(.*\)'` \
63 || bad_option "Malformed feature toggle: $option"
64 option=`expr "X$option" : 'X\(--[^-]*\).*'`
75 $optarg_ok && SBCL_PREFIX=$optarg
78 $oparg_ok && SBCL_ARCH=$optarg
81 $optarg_ok && SBCL_XC_HOST=$optarg
83 --dynamic-space-size=)
84 $optarg_ok && SBCL_DYNAMIC_SPACE_SIZE=$optarg
87 WITH_FEATURES="$WITH_FEATURES :$optarg"
90 WITHOUT_FEATURES="$WITHOUT_FEATURES :$optarg"
93 WITH_FEATURES="$WITH_FEATURES :sb-core-compression :sb-xref-for-internals :sb-after-xc-core"
94 # Lower down we add :sb-thread for platforms where it can be built.
98 bad_option "Unknown command-line option to $0: \"$option\""
103 bad_option "Unknown command-line option to $0: \"$option\""
105 legacy_xc_spec=$option
112 if (test -f customize-target-features.lisp && \
113 (test -n "$WITH_FEATURES" || test -n "$WITHOUT_FEATURES"))
115 # Actually there's no reason why it would not work, but it would
116 # be confusing to say --with-thread only to have it turned off by
117 # customize-target-features.lisp...
118 echo "ERROR: Both customize-target-features.lisp, and feature-options"
119 echo "to make.sh present -- cannot use both at the same time."
123 # Previously XC host was provided as a positional argument.
124 if test -n "$legacy_xc_spec"
126 SBCL_XC_HOST="$legacy_xc_spec"
129 if test "$print_help" = "yes"
132 \`make.sh' drives the SBCL build.
134 Usage: $0 [OPTION]...
136 Important: make.sh does not currently control the entirety of the
137 build: configuration file customize-target-features.lisp and certain
138 environment variables play a role as well. see file INSTALL for
142 -h, --help Display this help and exit.
144 --prefix=<path> Specify the install location.
146 Script install.sh installs SBCL under the specified prefix
147 path: runtime as prefix/bin/sbcl, additional files under
148 prefix/lib/sbcl, and documentation under prefix/share.
150 This option also affects the binaries: built-in default for
151 SBCL_HOME is: prefix/lib/sbcl/
153 Default prefix is: /usr/local
155 --dynamic-space-size=<size> Default dynamic-space size for target.
157 This specifies the default dynamic-space size for the SBCL
158 being built. If you need to control the dynamic-space size
159 of the host SBCL, use the --xc-host option.
161 If not provided, the default is platform-specific. <size> is
162 taken to be megabytes unless explicitly suffixed with Gb in
163 order to specify the size in gigabytes.
165 --with-<feature> Build with specified feature.
166 --without-<feature> Build wihout the specfied feature.
168 --arch=<string> Specify the architecture to build for.
170 Mainly for doing x86 builds on x86-64.
172 --xc-host=<string> Specify the Common Lisp compilation host.
174 The string provided should be a command to invoke the
175 cross-compilation Lisp system in such a way, that it reads
176 commands from standard input, and terminates when it reaches end
177 of file on standard input.
181 "sbcl --disable-debugger --no-sysinit --no-userinit"
182 Use an existing SBCL binary as a cross-compilation
183 host even though you have stuff in your
184 initialization files which makes it behave in such a
185 non-standard way that it keeps the build from
186 working. Also disable the debugger instead of
187 waiting endlessly for a programmer to help it out
188 with input on *DEBUG-IO*. (This is the default.)
191 Use an existing SBCL binary as a cross-compilation
192 host, including your initialization files and
193 building with the debugger enabled. Not recommended
196 "lisp -noinit -batch"
197 Use an existing CMU CL binary as a cross-compilation
198 host when you have weird things in your .cmucl-init
205 # Save prefix for make and install.sh.
206 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
207 echo "$SBCL_DYNAMIC_SPACE_SIZE" > output/dynamic-space-size.txt
209 # FIXME: Tweak this script, and the rest of the system, to support
210 # a second bootstrapping pass in which the cross-compilation host is
211 # known to be SBCL itself, so that the cross-compiler can do some
212 # optimizations (especially specializable arrays) that it doesn't
213 # know how to implement how in a portable way. (Or maybe that wouldn't
214 # require a second pass, just testing at build-the-cross-compiler time
215 # whether the cross-compilation host returns suitable values from
216 # UPGRADED-ARRAY-ELEMENT-TYPE?)
218 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
228 . ./generate-version.sh
231 # Now that we've done our option parsing and found various
232 # dependencies, write them out to a file to be sourced by other
235 echo "DEVNULL=\"$DEVNULL\"; export DEVNULL" > output/build-config
236 echo "GNUMAKE=\"$GNUMAKE\"; export GNUMAKE" >> output/build-config
237 echo "SBCL_XC_HOST=\"$SBCL_XC_HOST\"; export SBCL_XC_HOST" >> output/build-config
238 echo "legacy_xc_spec=\"$legacy_xc_spec\"; export legacy_xc_spec" >> output/build-config
240 # And now, sorting out the per-target dependencies...
247 # it's changed name twice since it was called OSF/1: clearly
248 # the marketers forgot to tell the engineers about Digital Unix
264 echo unsupported BSD variant: `uname`
275 CYGWIN* | WindowsNT | MINGW*)
282 echo unsupported OS type: `uname`
288 if [ "$sbcl_os" = "win32" ] ; then
295 remove_dir_safely() {
296 if [ "$sbcl_os" = "win32" ] ; then
297 if [ -d "$1" ] ; then
299 elif [ -e "$1" ] ; then
300 echo "I'm afraid to remove non-directory $1."
304 if [ -h "$1" ] ; then
306 elif [ -w "$1" ] ; then
307 echo "I'm afraid to replace non-symlink $1 with a symlink."
313 echo //entering make-config.sh
315 echo //ensuring the existence of output/ directory
316 if [ ! -d output ] ; then mkdir output; fi
318 echo //guessing default target CPU architecture from host architecture
320 *86) guessed_sbcl_arch=x86 ;;
321 i86pc) guessed_sbcl_arch=x86 ;;
322 *x86_64) guessed_sbcl_arch=x86-64 ;;
323 amd64) guessed_sbcl_arch=x86-64 ;;
324 [Aa]lpha) guessed_sbcl_arch=alpha ;;
325 sparc*) guessed_sbcl_arch=sparc ;;
326 sun*) guessed_sbcl_arch=sparc ;;
327 *ppc) guessed_sbcl_arch=ppc ;;
328 ppc64) guessed_sbcl_arch=ppc ;;
329 Power*Macintosh) guessed_sbcl_arch=ppc ;;
330 parisc) guessed_sbcl_arch=hppa ;;
331 9000/800) guessed_sbcl_arch=hppa ;;
332 mips*) guessed_sbcl_arch=mips ;;
334 # If we're not building on a supported target architecture, we
335 # we have no guess, but it's not an error yet, since maybe
336 # target architecture will be specified explicitly below.
341 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
342 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
343 guessed_sbcl_arch=x86-64
346 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
347 if [ "$sbcl_os" = "darwin" ] && [ "`/usr/sbin/sysctl -n hw.optional.x86_64`" = "1" ]; then
348 guessed_sbcl_arch=x86-64
351 echo //setting up CPU-architecture-dependent information
352 if test -n "$SBCL_ARCH"
355 SBCL_ARCH=`echo $SBCL_ARCH | tr '[A-Z]' '[a-z]' | tr _ -`
357 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
358 echo sbcl_arch=\"$sbcl_arch\"
359 if [ "$sbcl_arch" = "" ] ; then
360 echo "can't guess target SBCL architecture, please specify --arch=<name>"
365 # If --fancy, enable threads on platforms where they can be built.
368 WITH_FEATURES="$WITH_FEATURES :sb-thread"
369 echo "Enabling threads due to --fancy."
372 echo "No threads on this platform."
377 ltf=`pwd`/local-target-features.lisp-expr
378 echo //initializing $ltf
379 echo ';;;; This is a machine-generated file.' > $ltf
380 echo ';;;; Please do not edit it by hand.' >> $ltf
381 echo ';;;; See make-config.sh.' >> $ltf
382 echo "((lambda (features) (set-difference features (list$WITHOUT_FEATURES)))" >> $ltf
383 printf " (union (list$WITH_FEATURES) (list " >> $ltf
385 printf ":%s" "$sbcl_arch" >> $ltf
387 echo //setting up OS-dependent information
388 # Under Darwin x86-64, guess whether Darwin 9+ or below.
389 if [ "$sbcl_os" = "darwin" ] && [ "$sbcl_arch" = "x86-64" ]; then
390 darwin_version=`uname -r`
391 darwin_version_major=${DARWIN_VERSION_MAJOR:-${darwin_version%%.*}}
392 if (( 8 < $darwin_version_major )); then
393 printf ' :inode64 :darwin9-or-better' >> $ltf
399 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
400 # KLUDGE: these two logically belong in the previous section
401 # ("architecture-dependent"); it seems silly to enforce this in terms
402 # of the shell script, though. -- CSR, 2002-02-03
403 link_or_copy $sbcl_arch-arch.h target-arch.h
404 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
407 printf ' :unix' >> $ltf
408 printf ' :elf' >> $ltf
409 printf ' :linux' >> $ltf
411 # If you add other platforms here, don't forget to edit
412 # src/runtime/Config.foo-linux too.
415 printf ' :largefile' >> $ltf
418 printf ' :sb-thread :sb-futex :largefile' >> $ltf
421 printf ' :sb-futex' >> $ltf
425 if [ $sbcl_arch = "x86-64" ]; then
426 link_or_copy Config.x86_64-linux Config
428 link_or_copy Config.$sbcl_arch-linux Config
430 link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
431 link_or_copy linux-os.h target-os.h
434 printf ' :unix' >> $ltf
435 printf ' :elf' >> $ltf
436 printf ' :osf1' >> $ltf
437 link_or_copy Config.$sbcl_arch-osf1 Config
438 link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
439 link_or_copy osf1-os.h target-os.h
442 printf ' :unix' >> $ltf
443 printf ' :elf' >> $ltf
444 printf ' :hpux' >> $ltf
445 link_or_copy Config.$sbcl_arch-hpux Config
446 link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
447 link_or_copy hpux-os.h target-os.h
450 printf ' :unix' >> $ltf
451 printf ' :bsd' >> $ltf
452 link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
453 link_or_copy bsd-os.h target-os.h
456 printf ' :elf' >> $ltf
457 printf ' :freebsd' >> $ltf
458 printf ' :gcc-tls' >> $ltf
459 if [ $sbcl_arch = "x86" ]; then
460 printf ' :restore-tls-segment-register-from-context' >> $ltf
462 link_or_copy Config.$sbcl_arch-freebsd Config
465 printf ' :elf' >> $ltf
466 printf ' :openbsd' >> $ltf
467 link_or_copy Config.$sbcl_arch-openbsd Config
470 printf ' :netbsd' >> $ltf
471 printf ' :elf' >> $ltf
472 link_or_copy Config.$sbcl_arch-netbsd Config
475 echo unsupported BSD variant: `uname`
481 printf ' :unix' >> $ltf
482 printf ' :mach-o' >> $ltf
483 printf ' :bsd' >> $ltf
484 printf ' :darwin' >> $ltf
485 if [ $sbcl_arch = "x86" ]; then
486 printf ' :mach-exception-handler :restore-fs-segment-register-from-tls :ud2-breakpoints' >> $ltf
488 if [ $sbcl_arch = "x86-64" ]; then
489 printf ' :mach-exception-handler :ud2-breakpoints' >> $ltf
491 link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
492 link_or_copy bsd-os.h target-os.h
493 link_or_copy Config.$sbcl_arch-darwin Config
496 printf ' :unix' >> $ltf
497 printf ' :elf' >> $ltf
498 printf ' :sunos' >> $ltf
499 if [ $sbcl_arch = "x86-64" ]; then
500 printf ' :largefile' >> $ltf
502 link_or_copy Config.$sbcl_arch-sunos Config
503 link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
504 link_or_copy sunos-os.h target-os.h
507 printf ' :win32' >> $ltf
508 link_or_copy Config.$sbcl_arch-win32 Config
509 link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
510 link_or_copy win32-os.h target-os.h
513 echo unsupported OS type: `uname`
519 # FIXME: Things like :c-stack-grows-..., etc, should be
520 # *derived-target-features* or equivalent, so that there was a nicer
521 # way to specify them then sprinkling them in this file. They should
522 # still be tweakable by advanced users, though, but probably not
523 # appear in *features* of target. #!+/- should be adjusted to take
524 # them in account as well. At minimum the nicer specification stuff,
527 # (define-feature :dlopen (features)
528 # (union '(:bsd :linux :darwin :sunos) features))
530 # (define-feature :c-stack-grows-downwards-not-upwards (features)
531 # (member :x86 features))
533 # KLUDGE: currently the x86 only works with the generational garbage
534 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
535 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
536 # the absence of :GENCGC in *FEATURES*). This isn't a great
537 # separation, but for now, rather than have :GENCGC in
538 # base-target-features.lisp-expr, we add it into local-target-features
539 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
540 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
541 if [ "$sbcl_arch" = "x86" ]; then
542 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
543 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
544 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
545 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
546 printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
547 printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
549 linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
550 printf ' :linkage-table' >> $ltf
552 if [ "$sbcl_os" = "win32" ]; then
553 # of course it doesn't provide dlopen, but there is
554 # roughly-equivalent magic nevertheless.
555 printf ' :os-provides-dlopen' >> $ltf
557 if [ "$sbcl_os" = "openbsd" ]; then
558 rm -f src/runtime/openbsd-sigcontext.h
559 sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
561 elif [ "$sbcl_arch" = "x86-64" ]; then
562 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
563 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
564 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
565 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
566 printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
567 printf ' :float-eql-vops :inline-constants :memory-barrier-vops' >> $ltf
568 printf ' :multiply-high-vops' >> $ltf
569 elif [ "$sbcl_arch" = "mips" ]; then
570 printf ' :linkage-table' >> $ltf
571 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
572 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
573 printf ' :alien-callbacks' >> $ltf
574 # Use a little C program to try to guess the endianness. Ware
577 # FIXME: integrate to grovel-features, mayhaps
578 $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
579 tools-for-build/determine-endianness >> $ltf
580 elif [ "$sbcl_arch" = "ppc" ]; then
581 printf ' :gencgc :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
582 printf ' :linkage-table :raw-instance-init-vops :memory-barrier-vops' >> $ltf
583 printf ' :compare-and-swap-vops :multiply-high-vops' >> $ltf
584 if [ "$sbcl_os" = "linux" ]; then
585 # Use a C program to detect which kind of glibc we're building on,
586 # to bandage across the break in source compatibility between
587 # versions 2.3.1 and 2.3.2
589 # FIXME: integrate to grovel-features, mayhaps
590 $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
591 tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
592 elif [ "$sbcl_os" = "darwin" ]; then
593 # We provide a dlopen shim, so a little lie won't hurt
594 printf " :os-provides-dlopen :alien-callbacks" >> $ltf
595 # The default stack ulimit under darwin is too small to run PURIFY.
596 # Best we can do is complain and exit at this stage
597 if [ "`ulimit -s`" = "512" ]; then
598 echo "Your stack size limit is too small to build SBCL."
599 echo "See the limit(1) or ulimit(1) commands and the README file."
603 elif [ "$sbcl_arch" = "sparc" ]; then
604 # Test the compiler in order to see if we are building on Sun
605 # toolchain as opposed to GNU binutils, and write the appropriate
606 # FUNCDEF macro for assembler. No harm in running this on sparc-linux
608 sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
609 if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
610 printf ' :linkage-table' >> $ltf
612 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
613 elif [ "$sbcl_arch" = "alpha" ]; then
614 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
615 elif [ "$sbcl_arch" = "hppa" ]; then
616 printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
617 printf ' :stack-allocatable-lists' >> $ltf
619 # Nothing need be done in this case, but sh syntax wants a placeholder.
623 export sbcl_os sbcl_arch
624 sh tools-for-build/grovel-features.sh >> $ltf
626 echo //finishing $ltf
629 # FIXME: The version system should probably be redone along these lines:
631 # echo //setting up version information.
632 # versionfile=version.txt
633 # cp base-version.txt $versionfile
634 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
635 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
637 # Make a unique ID for this build (to discourage people from
638 # mismatching sbcl and *.core files).
639 if [ `uname` = "SunOS" ] ; then
640 # use /usr/xpg4/bin/id instead of /usr/bin/id
641 PATH=/usr/xpg4/bin:$PATH
643 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp