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