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."
52 # Split --foo=bar into --foo and bar.
55 # For ease of scripting skip valued options with empty
57 optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
58 option=`expr "X$option" : 'X\([^=]*=\).*'`
61 optarg=`expr "X$option" : 'X--[^-]*-\(.*\)'` \
62 || bad_option "Malformed feature toggle: $option"
63 option=`expr "X$option" : 'X\(--[^-]*\).*'`
74 $optarg_ok && SBCL_PREFIX=$optarg
77 $oparg_ok && SBCL_ARCH=$optarg
80 $optarg_ok && SBCL_XC_HOST=$optarg
82 --dynamic-space-size=)
83 $optarg_ok && SBCL_DYNAMIC_SPACE_SIZE=$optarg
86 WITH_FEATURES="$WITH_FEATURES :$optarg"
89 WITHOUT_FEATURES="$WITHOUT_FEATURES :$optarg"
92 bad_option "Unknown command-line option to $0: \"$option\""
97 bad_option "Unknown command-line option to $0: \"$option\""
99 legacy_xc_spec=$option
106 if (test -f customize-target-features.lisp && \
107 (test -n "$WITH_FEATURES" || test -n "$WITHOUT_FEATURES"))
109 # Actually there's no reason why it would not work, but it would
110 # be confusing to say --with-thread only to have it turned off by
111 # customize-target-features.lisp...
112 echo "ERROR: Both customize-target-features.lisp, and feature-options"
113 echo "to make.sh present -- cannot use both at the same time."
116 # Previously XC host was provided as a positional argument.
117 if test -n "$legacy_xc_spec"
119 SBCL_XC_HOST="$legacy_xc_spec"
122 if test "$print_help" = "yes"
125 \`make.sh' drives the SBCL build.
127 Usage: $0 [OPTION]...
129 Important: make.sh does not currently control the entirety of the
130 build: configuration file customize-target-features.lisp and certain
131 environment variables play a role as well. see file INSTALL for
135 -h, --help Display this help and exit.
137 --prefix=<path> Specify the install location.
139 Script install.sh installs SBCL under the specified prefix
140 path: runtime as prefix/bin/sbcl, additional files under
141 prefix/lib/sbcl, and documentation under prefix/share.
143 This option also affects the binaries: built-in default for
144 SBCL_HOME is: prefix/lib/sbcl/
146 Default prefix is: /usr/local
148 --dynamic-space-size=<size> Default dynamic-space size for target.
150 This specifies the default dynamic-space size for the SBCL
151 being built. If you need to control the dynamic-space size
152 of the host SBCL, use the --xc-host option.
154 If not provided, the default is platform-specific. <size> is
155 taken to be megabytes unless explicitly suffixed with Gb in
156 order to specify the size in gigabytes.
158 --with-<feature> Build with specified feature.
159 --without-<feature> Build wihout the specfied feature.
161 --arch=<string> Specify the architecture to build for.
163 Mainly for doing x86 builds on x86-64.
165 --xc-host=<string> Specify the Common Lisp compilation host.
167 The string provided should be a command to invoke the
168 cross-compilation Lisp system in such a way, that it reads
169 commands from standard input, and terminates when it reaches end
170 of file on standard input.
174 "sbcl --disable-debugger --no-sysinit --no-userinit"
175 Use an existing SBCL binary as a cross-compilation
176 host even though you have stuff in your
177 initialization files which makes it behave in such a
178 non-standard way that it keeps the build from
179 working. Also disable the debugger instead of
180 waiting endlessly for a programmer to help it out
181 with input on *DEBUG-IO*. (This is the default.)
184 Use an existing SBCL binary as a cross-compilation
185 host, including your initialization files and
186 building with the debugger enabled. Not recommended
189 "lisp -noinit -batch"
190 Use an existing CMU CL binary as a cross-compilation
191 host when you have weird things in your .cmucl-init
198 # Save prefix for make and install.sh.
199 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
200 echo "$SBCL_DYNAMIC_SPACE_SIZE" > output/dynamic-space-size.txt
202 # FIXME: Tweak this script, and the rest of the system, to support
203 # a second bootstrapping pass in which the cross-compilation host is
204 # known to be SBCL itself, so that the cross-compiler can do some
205 # optimizations (especially specializable arrays) that it doesn't
206 # know how to implement how in a portable way. (Or maybe that wouldn't
207 # require a second pass, just testing at build-the-cross-compiler time
208 # whether the cross-compilation host returns suitable values from
209 # UPGRADED-ARRAY-ELEMENT-TYPE?)
211 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
221 . ./generate-version.sh
224 # Now that we've done our option parsing and found various
225 # dependencies, write them out to a file to be sourced by other
228 echo "DEVNULL=\"$DEVNULL\"; export DEVNULL" > output/build-config
229 echo "GNUMAKE=\"$GNUMAKE\"; export GNUMAKE" >> output/build-config
230 echo "SBCL_XC_HOST=\"$SBCL_XC_HOST\"; export SBCL_XC_HOST" >> output/build-config
231 echo "legacy_xc_spec=\"$legacy_xc_spec\"; export legacy_xc_spec" >> output/build-config
233 # And now, sorting out the per-target dependencies...
240 # it's changed name twice since it was called OSF/1: clearly
241 # the marketers forgot to tell the engineers about Digital Unix
257 echo unsupported BSD variant: `uname`
268 CYGWIN* | WindowsNT | MINGW*)
275 echo unsupported OS type: `uname`
281 if [ "$sbcl_os" = "win32" ] ; then
288 remove_dir_safely() {
289 if [ "$sbcl_os" = "win32" ] ; then
290 if [ -d "$1" ] ; then
292 elif [ -e "$1" ] ; then
293 echo "I'm afraid to remove non-directory $1."
297 if [ -h "$1" ] ; then
299 elif [ -w "$1" ] ; then
300 echo "I'm afraid to replace non-symlink $1 with a symlink."
306 echo //entering make-config.sh
308 echo //ensuring the existence of output/ directory
309 if [ ! -d output ] ; then mkdir output; fi
311 ltf=`pwd`/local-target-features.lisp-expr
312 echo //initializing $ltf
313 echo ';;;; This is a machine-generated file.' > $ltf
314 echo ';;;; Please do not edit it by hand.' >> $ltf
315 echo ';;;; See make-config.sh.' >> $ltf
316 echo "((lambda (features) (set-difference features (list$WITHOUT_FEATURES)))" >> $ltf
317 printf " (union (list$WITH_FEATURES) (list " >> $ltf
319 echo //guessing default target CPU architecture from host architecture
321 *86) guessed_sbcl_arch=x86 ;;
322 i86pc) guessed_sbcl_arch=x86 ;;
323 *x86_64) guessed_sbcl_arch=x86-64 ;;
324 amd64) guessed_sbcl_arch=x86-64 ;;
325 [Aa]lpha) guessed_sbcl_arch=alpha ;;
326 sparc*) guessed_sbcl_arch=sparc ;;
327 sun*) guessed_sbcl_arch=sparc ;;
328 *ppc) guessed_sbcl_arch=ppc ;;
329 ppc64) guessed_sbcl_arch=ppc ;;
330 Power*Macintosh) guessed_sbcl_arch=ppc ;;
331 parisc) guessed_sbcl_arch=hppa ;;
332 9000/800) guessed_sbcl_arch=hppa ;;
333 mips*) guessed_sbcl_arch=mips ;;
335 # If we're not building on a supported target architecture, we
336 # we have no guess, but it's not an error yet, since maybe
337 # target architecture will be specified explicitly below.
342 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
343 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
344 guessed_sbcl_arch=x86-64
347 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
348 if [ "$sbcl_os" = "darwin" ] && [ "`/usr/sbin/sysctl -n hw.optional.x86_64`" = "1" ]; then
349 guessed_sbcl_arch=x86-64
352 echo //setting up CPU-architecture-dependent information
353 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
354 echo sbcl_arch=\"$sbcl_arch\"
355 if [ "$sbcl_arch" = "" ] ; then
356 echo "can't guess target SBCL architecture, please specify --arch=<name>"
359 printf ":%s" "$sbcl_arch" >> $ltf
361 echo //setting up OS-dependent information
363 # Under Darwin x86-64, guess whether Darwin 9+ or below.
364 if [ "$sbcl_os" = "darwin" ] && [ "$sbcl_arch" = "x86-64" ]; then
365 darwin_version=`uname -r`
366 darwin_version_major=${DARWIN_VERSION_MAJOR:-${darwin_version%%.*}}
367 if (( 8 < $darwin_version_major )); then
368 printf ' :inode64 :darwin9-or-better' >> $ltf
374 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
375 # KLUDGE: these two logically belong in the previous section
376 # ("architecture-dependent"); it seems silly to enforce this in terms
377 # of the shell script, though. -- CSR, 2002-02-03
378 link_or_copy $sbcl_arch-arch.h target-arch.h
379 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
382 printf ' :unix' >> $ltf
383 printf ' :elf' >> $ltf
384 printf ' :linux' >> $ltf
386 # If you add other platforms here, don't forget to edit
387 # src/runtime/Config.foo-linux too.
390 printf ' :largefile' >> $ltf
393 printf ' :sb-thread :sb-futex :largefile' >> $ltf
396 printf ' :sb-futex' >> $ltf
400 if [ $sbcl_arch = "x86-64" ]; then
401 link_or_copy Config.x86_64-linux Config
403 link_or_copy Config.$sbcl_arch-linux Config
405 link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
406 link_or_copy linux-os.h target-os.h
409 printf ' :unix' >> $ltf
410 printf ' :elf' >> $ltf
411 printf ' :osf1' >> $ltf
412 link_or_copy Config.$sbcl_arch-osf1 Config
413 link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
414 link_or_copy osf1-os.h target-os.h
417 printf ' :unix' >> $ltf
418 printf ' :elf' >> $ltf
419 printf ' :hpux' >> $ltf
420 link_or_copy Config.$sbcl_arch-hpux Config
421 link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
422 link_or_copy hpux-os.h target-os.h
425 printf ' :unix' >> $ltf
426 printf ' :bsd' >> $ltf
427 link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
428 link_or_copy bsd-os.h target-os.h
431 printf ' :elf' >> $ltf
432 printf ' :freebsd' >> $ltf
433 printf ' :gcc-tls' >> $ltf
434 if [ $sbcl_arch = "x86" ]; then
435 printf ' :restore-tls-segment-register-from-context' >> $ltf
437 link_or_copy Config.$sbcl_arch-freebsd Config
440 printf ' :elf' >> $ltf
441 printf ' :openbsd' >> $ltf
442 link_or_copy Config.$sbcl_arch-openbsd Config
445 printf ' :netbsd' >> $ltf
446 printf ' :elf' >> $ltf
447 link_or_copy Config.$sbcl_arch-netbsd Config
450 echo unsupported BSD variant: `uname`
456 printf ' :unix' >> $ltf
457 printf ' :mach-o' >> $ltf
458 printf ' :bsd' >> $ltf
459 printf ' :darwin' >> $ltf
460 if [ $sbcl_arch = "x86" ]; then
461 printf ' :mach-exception-handler :restore-fs-segment-register-from-tls :ud2-breakpoints' >> $ltf
463 if [ $sbcl_arch = "x86-64" ]; then
464 printf ' :mach-exception-handler :ud2-breakpoints' >> $ltf
466 link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
467 link_or_copy bsd-os.h target-os.h
468 link_or_copy Config.$sbcl_arch-darwin Config
471 printf ' :unix' >> $ltf
472 printf ' :elf' >> $ltf
473 printf ' :sunos' >> $ltf
474 if [ $sbcl_arch = "x86-64" ]; then
475 printf ' :largefile' >> $ltf
477 link_or_copy Config.$sbcl_arch-sunos Config
478 link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
479 link_or_copy sunos-os.h target-os.h
482 printf ' :win32' >> $ltf
483 link_or_copy Config.$sbcl_arch-win32 Config
484 link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
485 link_or_copy win32-os.h target-os.h
488 echo unsupported OS type: `uname`
494 # FIXME: Things like :c-stack-grows-..., etc, should be
495 # *derived-target-features* or equivalent, so that there was a nicer
496 # way to specify them then sprinkling them in this file. They should
497 # still be tweakable by advanced users, though, but probably not
498 # appear in *features* of target. #!+/- should be adjusted to take
499 # them in account as well. At minimum the nicer specification stuff,
502 # (define-feature :dlopen (features)
503 # (union '(:bsd :linux :darwin :sunos) features))
505 # (define-feature :c-stack-grows-downwards-not-upwards (features)
506 # (member :x86 features))
508 # KLUDGE: currently the x86 only works with the generational garbage
509 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
510 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
511 # the absence of :GENCGC in *FEATURES*). This isn't a great
512 # separation, but for now, rather than have :GENCGC in
513 # base-target-features.lisp-expr, we add it into local-target-features
514 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
515 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
516 if [ "$sbcl_arch" = "x86" ]; then
517 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
518 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
519 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
520 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
521 printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
522 printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
524 linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
525 printf ' :linkage-table' >> $ltf
527 if [ "$sbcl_os" = "win32" ]; then
528 # of course it doesn't provide dlopen, but there is
529 # roughly-equivalent magic nevertheless.
530 printf ' :os-provides-dlopen' >> $ltf
532 if [ "$sbcl_os" = "openbsd" ]; then
533 rm -f src/runtime/openbsd-sigcontext.h
534 sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
536 elif [ "$sbcl_arch" = "x86-64" ]; then
537 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
538 printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
539 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
540 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
541 printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
542 printf ' :float-eql-vops :inline-constants :memory-barrier-vops' >> $ltf
543 printf ' :multiply-high-vops' >> $ltf
544 elif [ "$sbcl_arch" = "mips" ]; then
545 printf ' :linkage-table' >> $ltf
546 printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
547 printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
548 printf ' :alien-callbacks' >> $ltf
549 # Use a little C program to try to guess the endianness. Ware
552 # FIXME: integrate to grovel-features, mayhaps
553 $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
554 tools-for-build/determine-endianness >> $ltf
555 elif [ "$sbcl_arch" = "ppc" ]; then
556 printf ' :gencgc :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
557 printf ' :linkage-table :raw-instance-init-vops :memory-barrier-vops' >> $ltf
558 printf ' :compare-and-swap-vops :multiply-high-vops' >> $ltf
559 if [ "$sbcl_os" = "linux" ]; then
560 # Use a C program to detect which kind of glibc we're building on,
561 # to bandage across the break in source compatibility between
562 # versions 2.3.1 and 2.3.2
564 # FIXME: integrate to grovel-features, mayhaps
565 $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
566 tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
567 elif [ "$sbcl_os" = "darwin" ]; then
568 # We provide a dlopen shim, so a little lie won't hurt
569 printf " :os-provides-dlopen :alien-callbacks" >> $ltf
570 # The default stack ulimit under darwin is too small to run PURIFY.
571 # Best we can do is complain and exit at this stage
572 if [ "`ulimit -s`" = "512" ]; then
573 echo "Your stack size limit is too small to build SBCL."
574 echo "See the limit(1) or ulimit(1) commands and the README file."
578 elif [ "$sbcl_arch" = "sparc" ]; then
579 # Test the compiler in order to see if we are building on Sun
580 # toolchain as opposed to GNU binutils, and write the appropriate
581 # FUNCDEF macro for assembler. No harm in running this on sparc-linux
583 sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
584 if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
585 printf ' :linkage-table' >> $ltf
587 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
588 elif [ "$sbcl_arch" = "alpha" ]; then
589 printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
590 elif [ "$sbcl_arch" = "hppa" ]; then
591 printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
592 printf ' :stack-allocatable-lists' >> $ltf
594 # Nothing need be done in this case, but sh syntax wants a placeholder.
598 export sbcl_os sbcl_arch
599 sh tools-for-build/grovel-features.sh >> $ltf
601 echo //finishing $ltf
604 # FIXME: The version system should probably be redone along these lines:
606 # echo //setting up version information.
607 # versionfile=version.txt
608 # cp base-version.txt $versionfile
609 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
610 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
612 # Make a unique ID for this build (to discourage people from
613 # mismatching sbcl and *.core files).
614 if [ `uname` = "SunOS" ] ; then
615 # use /usr/xpg4/bin/id instead of /usr/bin/id
616 PATH=/usr/xpg4/bin:$PATH
618 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp