1.0.33.26: enabled threads by default on x86[-64] Linux
[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 case `uname` in
21     Linux)
22         sbcl_os="linux"
23         ;;
24     OSF1)
25         # it's changed name twice since it was called OSF/1: clearly
26         # the marketers forgot to tell the engineers about Digital Unix
27         # _or_ OSF/1 ...
28         sbcl_os="osf1"
29         ;;
30     *BSD)
31         case `uname` in
32             FreeBSD)
33                 sbcl_os="freebsd"
34                 ;;
35             OpenBSD)
36                 sbcl_os="openbsd"
37                 ;;
38             NetBSD)
39                 sbcl_os="netbsd"
40                 ;;
41             *)
42                 echo unsupported BSD variant: `uname`
43                 exit 1
44                 ;;
45         esac
46         ;;
47     Darwin)
48         sbcl_os="darwin"
49         ;;
50     SunOS)
51         sbcl_os="sunos"
52         ;;
53     CYGWIN* | WindowsNT | MINGW*)
54         sbcl_os="win32"
55         ;;
56     HP-UX)
57         sbcl_os="hpux"
58         ;;
59     *)
60         echo unsupported OS type: `uname`
61         exit 1
62         ;;
63 esac
64
65 link_or_copy() {
66    if [ "$sbcl_os" = "win32" ] ; then
67        cp -r "$1" "$2"
68    else
69        ln -s "$1" "$2"
70    fi
71 }
72
73 remove_dir_safely() {
74    if [ "$sbcl_os" = "win32" ] ; then
75         if [ -d "$1" ] ; then
76             rm -rf "$1"
77         elif [ -e "$1" ] ; then
78             echo "I'm afraid to remove non-directory $1."
79             exit 1
80         fi
81     else
82         if [ -h "$1" ] ; then
83             rm "$1"
84         elif [ -w "$1" ] ; then
85             echo "I'm afraid to replace non-symlink $1 with a symlink."
86             exit 1
87         fi
88     fi
89 }
90
91 echo //entering make-config.sh
92
93 echo //ensuring the existence of output/ directory
94 if [ ! -d output ] ; then mkdir output; fi
95
96 ltf=`pwd`/local-target-features.lisp-expr
97 echo //initializing $ltf
98 echo ';;;; This is a machine-generated file.' > $ltf
99 echo ';;;; Please do not edit it by hand.' >> $ltf
100 echo ';;;; See make-config.sh.' >> $ltf
101 printf '(' >> $ltf
102
103 echo //guessing default target CPU architecture from host architecture
104 case `uname -m` in
105     *86) guessed_sbcl_arch=x86 ;;
106     i86pc) guessed_sbcl_arch=x86 ;;
107     *x86_64) guessed_sbcl_arch=x86-64 ;;
108     amd64) guessed_sbcl_arch=x86-64 ;;
109     [Aa]lpha) guessed_sbcl_arch=alpha ;;
110     sparc*) guessed_sbcl_arch=sparc ;;
111     sun*) guessed_sbcl_arch=sparc ;;
112     *ppc) guessed_sbcl_arch=ppc ;;
113     ppc64) guessed_sbcl_arch=ppc ;;
114     Power*Macintosh) guessed_sbcl_arch=ppc ;;
115     parisc) guessed_sbcl_arch=hppa ;;
116     9000/800) guessed_sbcl_arch=hppa ;;
117     mips*) guessed_sbcl_arch=mips ;;
118     *)
119         # If we're not building on a supported target architecture, we
120         # we have no guess, but it's not an error yet, since maybe
121         # target architecture will be specified explicitly below.
122         guessed_sbcl_arch=''
123         ;;
124 esac
125
126 # Under Solaris, uname -m returns "i86pc" even if CPU is amd64.
127 if [ "$sbcl_os" = "sunos" ] && [ `isainfo -k` = "amd64" ]; then
128     guessed_sbcl_arch=x86-64
129 fi
130
131 # Under Darwin, uname -m returns "i386" even if CPU is x86_64.
132 if [ "$sbcl_os" = "darwin" ] && [ "`sysctl -n hw.optional.x86_64`" = "1" ]; then
133     guessed_sbcl_arch=x86-64
134 fi
135
136 echo //setting up CPU-architecture-dependent information
137 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
138 echo sbcl_arch=\"$sbcl_arch\"
139 if [ "$sbcl_arch" = "" ] ; then
140     echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
141     exit 1
142 fi
143 printf ":%s" "$sbcl_arch" >> $ltf
144
145 echo //setting up OS-dependent information
146 original_dir=`pwd`
147 cd ./src/runtime/
148 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
149 # KLUDGE: these two logically belong in the previous section
150 # ("architecture-dependent"); it seems silly to enforce this in terms
151 # of the shell script, though. -- CSR, 2002-02-03
152 link_or_copy $sbcl_arch-arch.h target-arch.h
153 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
154 case "$sbcl_os" in
155     linux)
156         printf ' :unix' >> $ltf
157         printf ' :elf' >> $ltf
158         printf ' :linux' >> $ltf
159
160         # If you add other platforms here, don't forget to edit
161         # src/runtime/Config.foo-linux too.
162         case "$sbcl_arch" in
163             mips)
164                 printf ' :largefile' >> $ltf
165                 ;;
166             x86 | x86-64)
167                 printf ' :sb-thread :largefile' >> $ltf
168                 ;;
169         esac
170
171         if [ $sbcl_arch = "x86-64" ]; then
172             link_or_copy Config.x86_64-linux Config
173         else
174             link_or_copy Config.$sbcl_arch-linux Config
175         fi
176         link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
177         link_or_copy linux-os.h target-os.h
178         ;;
179     osf1)
180         printf ' :unix' >> $ltf
181         printf ' :elf' >> $ltf
182         printf ' :osf1' >> $ltf
183         link_or_copy Config.$sbcl_arch-osf1 Config
184         link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
185         link_or_copy osf1-os.h target-os.h
186         ;;
187     hpux)
188         printf ' :unix' >> $ltf
189         printf ' :elf' >> $ltf
190         printf ' :hpux' >> $ltf
191         link_or_copy Config.$sbcl_arch-hpux Config
192         link_or_copy $sbcl_arch-hpux-os.h target-arch-os.h
193         link_or_copy hpux-os.h target-os.h
194         ;;
195     *bsd)
196         printf ' :unix' >> $ltf
197         printf ' :bsd' >> $ltf
198         link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
199         link_or_copy bsd-os.h target-os.h
200         case "$sbcl_os" in
201             freebsd)
202                 printf ' :elf' >> $ltf
203                 printf ' :freebsd' >> $ltf
204                 printf ' :gcc-tls' >> $ltf
205                 if [ $sbcl_arch = "x86" ]; then
206                     printf ' :restore-tls-segment-register-from-context' >> $ltf
207                 fi
208                 link_or_copy Config.$sbcl_arch-freebsd Config
209                 ;;
210             openbsd)
211                 printf ' :elf' >> $ltf
212                 printf ' :openbsd' >> $ltf
213                 link_or_copy Config.$sbcl_arch-openbsd Config
214                 ;;
215             netbsd)
216                 printf ' :netbsd' >> $ltf
217                 printf ' :elf' >> $ltf
218                 link_or_copy Config.$sbcl_arch-netbsd Config
219                 ;;
220             *)
221                 echo unsupported BSD variant: `uname`
222                 exit 1
223                 ;;
224         esac
225         ;;
226     darwin)
227         printf ' :unix' >> $ltf
228         printf ' :mach-o' >> $ltf
229         printf ' :bsd' >> $ltf
230         printf ' :darwin' >> $ltf
231         if [ $sbcl_arch = "x86" ]; then
232             printf ' :mach-exception-handler :sb-lutex :restore-fs-segment-register-from-tls' >> $ltf
233         fi
234         if [ $sbcl_arch = "x86-64" ]; then
235             printf ' :mach-exception-handler :sb-lutex' >> $ltf
236         fi
237         link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
238         link_or_copy bsd-os.h target-os.h
239         link_or_copy Config.$sbcl_arch-darwin Config
240         ;;
241     sunos)
242         printf ' :unix' >> $ltf
243         printf ' :elf' >> $ltf
244         printf ' :sunos' >> $ltf
245         if [ $sbcl_arch = "x86" ] || [ $sbcl_arch = "amd64" ]; then
246             printf ' :sb-lutex' >> $ltf
247         fi
248         link_or_copy Config.$sbcl_arch-sunos Config
249         link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
250         link_or_copy sunos-os.h target-os.h
251         ;;
252     win32)
253         printf ' :win32' >> $ltf
254         link_or_copy Config.$sbcl_arch-win32 Config
255         link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
256         link_or_copy win32-os.h target-os.h
257         ;;
258     *)
259         echo unsupported OS type: `uname`
260         exit 1
261         ;;
262 esac
263 cd "$original_dir"
264
265 # FIXME: Things like :c-stack-grows-..., etc, should be
266 # *derived-target-features* or equivalent, so that there was a nicer
267 # way to specify them then sprinkling them in this file. They should
268 # still be tweakable by advanced users, though, but probably not
269 # appear in *features* of target. #!+/- should be adjusted to take
270 # them in account as well. At minimum the nicer specification stuff,
271 # though:
272 #
273 # (define-feature :dlopen (features)
274 #   (union '(:bsd :linux :darwin :sunos) features))
275 #
276 # (define-feature :c-stack-grows-downwards-not-upwards (features)
277 #   (member :x86 features))
278
279 # KLUDGE: currently the x86 only works with the generational garbage
280 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
281 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
282 # the absence of :GENCGC in *FEATURES*). This isn't a great
283 # separation, but for now, rather than have :GENCGC in
284 # base-target-features.lisp-expr, we add it into local-target-features
285 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
286 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
287 if [ "$sbcl_arch" = "x86" ]; then
288     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
289     printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
290     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
291     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
292     printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
293     case "$sbcl_os" in
294     linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
295         printf ' :linkage-table' >> $ltf
296     esac
297     if [ "$sbcl_os" = "win32" ]; then
298         # of course it doesn't provide dlopen, but there is
299         # roughly-equivalent magic nevertheless.
300         printf ' :os-provides-dlopen' >> $ltf
301     fi
302 elif [ "$sbcl_arch" = "x86-64" ]; then
303     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
304     printf ' :compare-and-swap-vops :unwind-to-frame-and-call-vop :raw-instance-init-vops' >> $ltf
305     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
306     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
307     printf ' :alien-callbacks :cycle-counter :complex-float-vops' >> $ltf
308     printf ' :float-eql-vops :inline-constants ' >> $ltf
309 elif [ "$sbcl_arch" = "mips" ]; then
310     printf ' :linkage-table' >> $ltf
311     printf ' :stack-allocatable-closures :stack-allocatable-vectors' >> $ltf
312     printf ' :stack-allocatable-lists :stack-allocatable-fixed-objects' >> $ltf
313     printf ' :alien-callbacks' >> $ltf
314     # Use a little C program to try to guess the endianness.  Ware
315     # cross-compilers!
316     #
317     # FIXME: integrate to grovel-features, mayhaps
318     $GNUMAKE -C tools-for-build determine-endianness -I ../src/runtime
319     tools-for-build/determine-endianness >> $ltf
320 elif [ "$sbcl_arch" = "ppc" ]; then
321     printf ' :gencgc :stack-allocatable-closures :stacka-allocatable-lists' >> $ltf
322     printf ' :linkage-table' >> $ltf
323     if [ "$sbcl_os" = "linux" ]; then
324         # Use a C program to detect which kind of glibc we're building on,
325         # to bandage across the break in source compatibility between
326         # versions 2.3.1 and 2.3.2
327         #
328         # FIXME: integrate to grovel-features, mayhaps
329         $GNUMAKE -C tools-for-build where-is-mcontext -I ../src/runtime
330         tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h || (echo "error running where-is-mcontext"; exit 1)
331     elif [ "$sbcl_os" = "darwin" ]; then
332         # We provide a dlopen shim, so a little lie won't hurt
333         printf " :os-provides-dlopen :alien-callbacks" >> $ltf
334         # The default stack ulimit under darwin is too small to run PURIFY.
335         # Best we can do is complain and exit at this stage
336         if [ "`ulimit -s`" = "512" ]; then
337             echo "Your stack size limit is too small to build SBCL."
338             echo "See the limit(1) or ulimit(1) commands and the README file."
339             exit 1
340         fi
341     fi
342 elif [ "$sbcl_arch" = "sparc" ]; then
343     # Test the compiler in order to see if we are building on Sun
344     # toolchain as opposed to GNU binutils, and write the appropriate
345     # FUNCDEF macro for assembler. No harm in running this on sparc-linux
346     # as well.
347     sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
348     if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
349         printf ' :linkage-table' >> $ltf
350     fi
351     printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
352 elif [ "$sbcl_arch" = "alpha" ]; then
353     printf ' :stack-allocatable-closures :stack-allocatable-lists' >> $ltf
354 elif [ "$sbcl_arch" = "hppa" ]; then
355     printf ' :stack-allocatable-vectors :stack-allocatable-fixed-objects' >> $ltf
356     printf ' :stack-allocatable-lists' >> $ltf
357 else
358     # Nothing need be done in this case, but sh syntax wants a placeholder.
359     echo > /dev/null
360 fi
361
362 export sbcl_os sbcl_arch
363 sh tools-for-build/grovel-features.sh >> $ltf
364
365 echo //finishing $ltf
366 echo ')' >> $ltf
367
368 # FIXME: The version system should probably be redone along these lines:
369 #
370 # echo //setting up version information.
371 # versionfile=version.txt
372 # cp base-version.txt $versionfile
373 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
374 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
375
376 # Make a unique ID for this build (to discourage people from
377 # mismatching sbcl and *.core files).
378 if [ `uname` = "SunOS" ] ; then
379   # use /usr/xpg4/bin/id instead of /usr/bin/id
380   PATH=/usr/xpg4/bin:$PATH
381 fi
382 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp