linux: Enable :SB-FUTEX by default on PPC.
[sbcl.git] / make-config.sh
1 #!/bin/sh
2 set -e
3
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
9 # troubleshooting.
10
11 # This software is part of the SBCL system. See the README file for
12 # more information.
13 #
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.
19
20 print_help="no"
21
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
28 # from building.
29 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ]
30 then
31     SBCL_PREFIX="$PROGRAMFILES/sbcl"
32 else
33     SBCL_PREFIX="/usr/local"
34 fi
35 SBCL_XC_HOST="sbcl --disable-debugger --no-userinit --no-sysinit"
36 export SBCL_XC_HOST
37
38 # Parse command-line options.
39 bad_option() {
40     echo $1
41     echo "Enter \"$0 --help\" for list of valid options."
42     exit 1
43 }
44
45 some_options=false
46 for option
47 do
48   optarg_ok=true
49   # Split --foo=bar into --foo and bar.
50   case $option in
51       *=*)
52         # For ease of scripting treat skip valued options with empty
53         # values.
54         optarg=`expr "X$option" : '[^=]*=\(.*\)'` || optarg_ok=false
55         option=`expr "X$option" : 'X\([^=]*=\).*'`
56         ;;
57       *)
58         optarg=""
59         ;;
60   esac
61
62   case $option in
63       --help | -help | -h)
64         print_help="yes" ;;
65       --prefix=)
66         $optarg_ok && SBCL_PREFIX=$optarg
67         ;;
68       --xc-host=)
69         $optarg_ok && SBCL_XC_HOST=$optarg
70         ;;
71       --dynamic-space-size=)
72         $optarg_ok && SBCL_DYNAMIC_SPACE_SIZE=$optarg
73         ;;
74       -*)
75         bad_option "Unknown command-line option to $0: \"$option\""
76         ;;
77       *)
78         if $some_options
79         then
80             bad_option "Unknown command-line option to $0: \"$option\""
81         else
82             legacy_xc_spec=$option
83         fi
84         ;;
85   esac
86   some_options=true
87 done
88
89 # Previously XC host was provided as a positional argument. 
90 if test -n "$legacy_xc_spec"
91 then
92     SBCL_XC_HOST="$legacy_xc_spec"
93 fi
94
95 if test "$print_help" = "yes"
96 then
97   cat <<EOF
98 \`make.sh' drives the SBCL build.
99
100 Usage: $0 [OPTION]...
101
102   Important: make.sh does not currently control the entirety of the
103   build: configuration file customize-target-features.lisp and certain
104   environment variables play a role as well. see file INSTALL for
105   details.
106
107 Options:
108   -h, --help           Display this help and exit.
109
110   --prefix=<path>      Specify the install location.
111
112       Script install.sh installs SBCL under the specified prefix
113       path: runtime as prefix/bin/sbcl, additional files under
114       prefix/lib/sbcl, and documentation under prefix/share.
115
116       This option also affects the binaries: built-in default for
117       SBCL_HOME is: prefix/lib/sbcl/
118
119       Default prefix is: /usr/local
120
121   --dynamic-space-size=<size> Default dynamic-space size for target.
122
123       This specifies the default dynamic-space size for the SBCL
124       being built. If you need to control the dynamic-space size
125       of the host SBCL, use the --xc-host option.
126
127       If not provided, the default is platform-specific. <size> is
128       taken to be megabytes unless explicitly suffixed with Gb in
129       order to specify the size in gigabytes.
130
131   --xc-host=<string>   Specify the Common Lisp compilation host.
132
133       The string provided should be a command to invoke the
134       cross-compilation Lisp system in such a way, that it reads
135       commands from standard input, and terminates when it reaches end
136       of file on standard input.
137
138       Examples:
139
140        "sbcl --disable-debugger --no-sysinit --no-userinit"
141                   Use an existing SBCL binary as a cross-compilation
142                   host even though you have stuff in your
143                   initialization files which makes it behave in such a
144                   non-standard way that it keeps the build from
145                   working. Also disable the debugger instead of
146                   waiting endlessly for a programmer to help it out
147                   with input on *DEBUG-IO*. (This is the default.)
148
149        "sbcl"
150                   Use an existing SBCL binary as a cross-compilation
151                   host, including your initialization files and
152                   building with the debugger enabled. Not recommended
153                   for casual users.
154
155        "lisp -noinit -batch"
156                   Use an existing CMU CL binary as a cross-compilation
157                   host when you have weird things in your .cmucl-init
158                   file.
159 EOF
160   exit 1
161 fi
162
163 mkdir -p output
164 # Save prefix for make and install.sh.
165 echo "SBCL_PREFIX='$SBCL_PREFIX'" > output/prefix.def
166 echo "$SBCL_DYNAMIC_SPACE_SIZE" > output/dynamic-space-size.txt
167
168 # FIXME: Tweak this script, and the rest of the system, to support
169 # a second bootstrapping pass in which the cross-compilation host is
170 # known to be SBCL itself, so that the cross-compiler can do some
171 # optimizations (especially specializable arrays) that it doesn't
172 # know how to implement how in a portable way. (Or maybe that wouldn't
173 # require a second pass, just testing at build-the-cross-compiler time
174 # whether the cross-compilation host returns suitable values from
175 # UPGRADED-ARRAY-ELEMENT-TYPE?)
176
177 if [ "$OSTYPE" = "cygwin" -o "$OSTYPE" = "msys" ] ; then
178     DEVNULL=NUL
179 else
180     DEVNULL=/dev/null
181 fi
182 export DEVNULL
183
184 . ./find-gnumake.sh
185 find_gnumake
186
187 . ./generate-version.sh
188 generate_version
189
190 # Now that we've done our option parsing and found various
191 # dependencies, write them out to a file to be sourced by other
192 # scripts.
193
194 echo "DEVNULL=\"$DEVNULL\"; export DEVNULL" > output/build-config
195 echo "GNUMAKE=\"$GNUMAKE\"; export GNUMAKE" >> output/build-config
196 echo "SBCL_XC_HOST=\"$SBCL_XC_HOST\"; export SBCL_XC_HOST" >> output/build-config
197 echo "legacy_xc_spec=\"$legacy_xc_spec\"; export legacy_xc_spec" >> output/build-config
198
199 # And now, sorting out the per-target dependencies...
200
201 case `uname` in
202     Linux)
203         sbcl_os="linux"
204         ;;
205     OSF1)
206         # it's changed name twice since it was called OSF/1: clearly
207         # the marketers forgot to tell the engineers about Digital Unix
208         # _or_ OSF/1 ...
209         sbcl_os="osf1"
210         ;;
211     *BSD)
212         case `uname` in
213             FreeBSD)
214                 sbcl_os="freebsd"
215                 ;;
216             OpenBSD)
217                 sbcl_os="openbsd"
218                 ;;
219             NetBSD)
220                 sbcl_os="netbsd"
221                 ;;
222             *)
223                 echo unsupported BSD variant: `uname`
224                 exit 1
225                 ;;
226         esac
227         ;;
228     Darwin)
229         sbcl_os="darwin"
230         ;;
231     SunOS)
232         sbcl_os="sunos"
233         ;;
234     CYGWIN* | WindowsNT | MINGW*)
235         sbcl_os="win32"
236         ;;
237     HP-UX)
238         sbcl_os="hpux"
239         ;;
240     *)
241         echo unsupported OS type: `uname`
242         exit 1
243         ;;
244 esac
245
246 link_or_copy() {
247    if [ "$sbcl_os" = "win32" ] ; then
248        cp -r "$1" "$2"
249    else
250        ln -s "$1" "$2"
251    fi
252 }
253
254 remove_dir_safely() {
255    if [ "$sbcl_os" = "win32" ] ; then
256         if [ -d "$1" ] ; then
257             rm -rf "$1"
258         elif [ -e "$1" ] ; then
259             echo "I'm afraid to remove non-directory $1."
260             exit 1
261         fi
262     else
263         if [ -h "$1" ] ; then
264             rm "$1"
265         elif [ -w "$1" ] ; then
266             echo "I'm afraid to replace non-symlink $1 with a symlink."
267             exit 1
268         fi
269     fi
270 }
271
272 echo //entering make-config.sh
273
274 echo //ensuring the existence of output/ directory
275 if [ ! -d output ] ; then mkdir output; fi
276
277 ltf=`pwd`/local-target-features.lisp-expr
278 echo //initializing $ltf
279 echo ';;;; This is a machine-generated file.' > $ltf
280 echo ';;;; Please do not edit it by hand.' >> $ltf
281 echo ';;;; See make-config.sh.' >> $ltf
282 printf '(' >> $ltf
283
284 echo //guessing default target CPU architecture from host architecture
285 case `uname -m` in
286     *86) guessed_sbcl_arch=x86 ;;
287     i86pc) guessed_sbcl_arch=x86 ;;
288     *x86_64) guessed_sbcl_arch=x86-64 ;;
289     amd64) guessed_sbcl_arch=x86-64 ;;
290     [Aa]lpha) guessed_sbcl_arch=alpha ;;
291     sparc*) guessed_sbcl_arch=sparc ;;
292     sun*) guessed_sbcl_arch=sparc ;;
293     *ppc) guessed_sbcl_arch=ppc ;;
294     ppc64) guessed_sbcl_arch=ppc ;;
295     Power*Macintosh) guessed_sbcl_arch=ppc ;;
296     parisc) guessed_sbcl_arch=hppa ;;
297     9000/800) guessed_sbcl_arch=hppa ;;
298     mips*) guessed_sbcl_arch=mips ;;
299     *)
300         # If we're not building on a supported target architecture, we
301         # we have no guess, but it's not an error yet, since maybe
302         # target architecture will be specified explicitly below.
303         guessed_sbcl_arch=''
304         ;;
305 esac
306
307 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
308 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
309     guessed_sbcl_arch=x86-64
310 fi
311
312 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
313 if [ "$sbcl_os" = "darwin" ] && [ "`/usr/sbin/sysctl -n hw.optional.x86_64`" = "1" ]; then
314     guessed_sbcl_arch=x86-64
315 fi
316
317 echo //setting up CPU-architecture-dependent information
318 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
319 echo sbcl_arch=\"$sbcl_arch\"
320 if [ "$sbcl_arch" = "" ] ; then
321     echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
322     exit 1
323 fi
324 printf ":%s" "$sbcl_arch" >> $ltf
325
326 echo //setting up OS-dependent information
327
328 # Under Darwin x86-64, guess whether Darwin 9+ or below.
329 if [ "$sbcl_os" = "darwin" ] && [ "$sbcl_arch" = "x86-64" ]; then
330     darwin_version=`uname -r`
331     darwin_version_major=${DARWIN_VERSION_MAJOR:-${darwin_version%%.*}}
332     if (( 8 < $darwin_version_major )); then
333         printf ' :inode64 :darwin9-or-better' >> $ltf
334     fi
335 fi
336
337 original_dir=`pwd`
338 cd ./src/runtime/
339 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
340 # KLUDGE: these two logically belong in the previous section
341 # ("architecture-dependent"); it seems silly to enforce this in terms
342 # of the shell script, though. -- CSR, 2002-02-03
343 link_or_copy $sbcl_arch-arch.h target-arch.h
344 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
345 case "$sbcl_os" in
346     linux)
347         printf ' :unix' >> $ltf
348         printf ' :elf' >> $ltf
349         printf ' :linux' >> $ltf
350
351         # If you add other platforms here, don't forget to edit
352         # src/runtime/Config.foo-linux too.
353         case "$sbcl_arch" in
354             mips)
355                 printf ' :largefile' >> $ltf
356                 ;;
357             x86 | x86-64)
358                 printf ' :sb-thread :sb-futex :largefile' >> $ltf
359                 ;;
360             ppc)
361                 printf ' :sb-futex' >> $ltf
362                 ;;
363         esac
364
365         if [ $sbcl_arch = "x86-64" ]; then
366             link_or_copy Config.x86_64-linux Config
367         else
368             link_or_copy Config.$sbcl_arch-linux Config
369         fi
370         link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
371         link_or_copy linux-os.h target-os.h
372         ;;
373     osf1)
374         printf ' :unix' >> $ltf
375         printf ' :elf' >> $ltf
376         printf ' :osf1' >> $ltf
377         link_or_copy Config.$sbcl_arch-osf1 Config
378         link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
379         link_or_copy osf1-os.h target-os.h
380         ;;
381     hpux)
382         printf ' :unix' >> $ltf
383         printf ' :elf' >> $ltf
384         printf ' :hpux' >> $ltf
385         link_or_copy Config.$sbcl_arch-hpux Config
386         link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
387         link_or_copy hpux-os.h target-os.h
388         ;;
389     *bsd)
390         printf ' :unix' >> $ltf
391         printf ' :bsd' >> $ltf
392         link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
393         link_or_copy bsd-os.h target-os.h
394         case "$sbcl_os" in
395             freebsd)
396                 printf ' :elf' >> $ltf
397                 printf ' :freebsd' >> $ltf
398                 printf ' :gcc-tls' >> $ltf
399                 if [ $sbcl_arch = "x86" ]; then
400                     printf ' :restore-tls-segment-register-from-context' >> $ltf
401                 fi
402                 link_or_copy Config.$sbcl_arch-freebsd Config
403                 ;;
404             openbsd)
405                 printf ' :elf' >> $ltf
406                 printf ' :openbsd' >> $ltf
407                 link_or_copy Config.$sbcl_arch-openbsd Config
408                 ;;
409             netbsd)
410                 printf ' :netbsd' >> $ltf
411                 printf ' :elf' >> $ltf
412                 link_or_copy Config.$sbcl_arch-netbsd Config
413                 ;;
414             *)
415                 echo unsupported BSD variant: `uname`
416                 exit 1
417                 ;;
418         esac
419         ;;
420     darwin)
421         printf ' :unix' >> $ltf
422         printf ' :mach-o' >> $ltf
423         printf ' :bsd' >> $ltf
424         printf ' :darwin' >> $ltf
425         if [ $sbcl_arch = "x86" ]; then
426             printf ' :mach-exception-handler :restore-fs-segment-register-from-tls :ud2-breakpoints' >> $ltf
427         fi
428         if [ $sbcl_arch = "x86-64" ]; then
429             printf ' :mach-exception-handler :ud2-breakpoints' >> $ltf
430         fi
431         link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
432         link_or_copy bsd-os.h target-os.h
433         link_or_copy Config.$sbcl_arch-darwin Config
434         ;;
435     sunos)
436         printf ' :unix' >> $ltf
437         printf ' :elf' >> $ltf
438         printf ' :sunos' >> $ltf
439         if [ $sbcl_arch = "x86-64" ]; then
440             printf ' :largefile' >> $ltf
441         fi
442         link_or_copy Config.$sbcl_arch-sunos Config
443         link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
444         link_or_copy sunos-os.h target-os.h
445         ;;
446     win32)
447         printf ' :win32' >> $ltf
448         link_or_copy Config.$sbcl_arch-win32 Config
449         link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
450         link_or_copy win32-os.h target-os.h
451         ;;
452     *)
453         echo unsupported OS type: `uname`
454         exit 1
455         ;;
456 esac
457 cd "$original_dir"
458
459 # FIXME: Things like :c-stack-grows-..., etc, should be
460 # *derived-target-features* or equivalent, so that there was a nicer
461 # way to specify them then sprinkling them in this file. They should
462 # still be tweakable by advanced users, though, but probably not
463 # appear in *features* of target. #!+/- should be adjusted to take
464 # them in account as well. At minimum the nicer specification stuff,
465 # though:
466 #
467 # (define-feature :dlopen (features)
468 #   (union '(:bsd :linux :darwin :sunos) features))
469 #
470 # (define-feature :c-stack-grows-downwards-not-upwards (features)
471 #   (member :x86 features))
472
473 # KLUDGE: currently the x86 only works with the generational garbage
474 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
475 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
476 # the absence of :GENCGC in *FEATURES*). This isn't a great
477 # separation, but for now, rather than have :GENCGC in
478 # base-target-features.lisp-expr, we add it into local-target-features
479 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
480 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
481 if [ "$sbcl_arch" = "x86" ]; then
482     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
483     printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
484     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
485     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
486     printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
487     printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
488     case "$sbcl_os" in
489     linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
490         printf ' :linkage-table' >> $ltf
491     esac
492     if [ "$sbcl_os" = "win32" ]; then
493         # of course it doesn't provide dlopen, but there is
494         # roughly-equivalent magic nevertheless.
495         printf ' :os-provides-dlopen' >> $ltf
496     fi
497     if [ "$sbcl_os" = "openbsd" ]; then
498         rm -f src/runtime/openbsd-sigcontext.h
499         sh tools-for-build/openbsd-sigcontext.sh > src/runtime/openbsd-sigcontext.h
500     fi
501 elif [ "$sbcl_arch" = "x86-64" ]; then
502     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
503     printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
504     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
505     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
506     printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
507     printf ' :float-eql-vops :inline-constants :memory-barrier-vops' >> $ltf
508     printf ' :multiply-high-vops' >> $ltf
509 elif [ "$sbcl_arch" = "mips" ]; then
510     printf ' :linkage-table' >> $ltf
511     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
512     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
513     printf ' :alien-callbacks' >> $ltf
514     # Use a little C program to try to guess the endianness.  Ware
515     # cross-compilers!
516     #
517     # FIXME: integrate to grovel-features, mayhaps
518     $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
519     tools-for-build/determine-endianness >> $ltf
520 elif [ "$sbcl_arch" = "ppc" ]; then
521     printf ' :gencgc :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
522     printf ' :linkage-table :raw-instance-init-vops :memory-barrier-vops' >> $ltf
523     printf ' :compare-and-swap-vops :multiply-high-vops' >> $ltf
524     if [ "$sbcl_os" = "linux" ]; then
525         # Use a C program to detect which kind of glibc we're building on,
526         # to bandage across the break in source compatibility between
527         # versions 2.3.1 and 2.3.2
528         #
529         # FIXME: integrate to grovel-features, mayhaps
530         $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
531         tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
532     elif [ "$sbcl_os" = "darwin" ]; then
533         # We provide a dlopen shim, so a little lie won't hurt
534         printf " :os-provides-dlopen :alien-callbacks" >> $ltf
535         # The default stack ulimit under darwin is too small to run PURIFY.
536         # Best we can do is complain and exit at this stage
537         if [ "`ulimit -s`" = "512" ]; then
538             echo "Your stack size limit is too small to build SBCL."
539             echo "See the limit(1) or ulimit(1) commands and the README file."
540             exit 1
541         fi
542     fi
543 elif [ "$sbcl_arch" = "sparc" ]; then
544     # Test the compiler in order to see if we are building on Sun
545     # toolchain as opposed to GNU binutils, and write the appropriate
546     # FUNCDEF macro for assembler. No harm in running this on sparc-linux
547     # as well.
548     sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
549     if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
550         printf ' :linkage-table' >> $ltf
551     fi
552     printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
553 elif [ "$sbcl_arch" = "alpha" ]; then
554     printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
555 elif [ "$sbcl_arch" = "hppa" ]; then
556     printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
557     printf ' :stack-allocatable-lists' >> $ltf
558 else
559     # Nothing need be done in this case, but sh syntax wants a placeholder.
560     echo > /dev/null
561 fi
562
563 export sbcl_os sbcl_arch
564 sh tools-for-build/grovel-features.sh >> $ltf
565
566 echo //finishing $ltf
567 echo ')' >> $ltf
568
569 # FIXME: The version system should probably be redone along these lines:
570 #
571 # echo //setting up version information.
572 # versionfile=version.txt
573 # cp base-version.txt $versionfile
574 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
575 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
576
577 # Make a unique ID for this build (to discourage people from
578 # mismatching sbcl and *.core files).
579 if [ `uname` = "SunOS" ] ; then
580   # use /usr/xpg4/bin/id instead of /usr/bin/id
581   PATH=/usr/xpg4/bin:$PATH
582 fi
583 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp