0.9.9.12:
[sbcl.git] / make-config.sh
blob92102606885dec7efbcc85831d9976f7dc0e4839
1 #!/bin/sh
2 set -e
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.
11 # This software is part of the SBCL system. See the README file for
12 # more information.
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.
20 case `uname` in
21 Linux)
22 sbcl_os="linux"
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"
30 *BSD)
31 case `uname` in
32 FreeBSD)
33 sbcl_os="freebsd"
35 OpenBSD)
36 sbcl_os="openbsd"
38 NetBSD)
39 sbcl_os="netbsd"
42 echo unsupported BSD variant: `uname`
43 exit 1
45 esac
47 Darwin)
48 sbcl_os="darwin"
50 SunOS)
51 sbcl_os="sunos"
53 CYGWIN* | WindowsNT | MINGW*)
54 sbcl_os="win32"
57 echo unsupported OS type: `uname`
58 exit 1
60 esac
62 link_or_copy() {
63 if [ "$sbcl_os" = "win32" ] ; then
64 cp -r "$1" "$2"
65 else
66 ln -s "$1" "$2"
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
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
88 echo //entering make-config.sh
90 echo //ensuring the existence of output/ directory
91 if [ ! -d output ] ; then mkdir output; fi
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
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 Power*Macintosh) guessed_sbcl_arch=ppc ;;
110 parisc) guessed_sbcl_arch=hppa ;;
111 mips*) guessed_sbcl_arch=mips ;;
113 # If we're not building on a supported target architecture, we
114 # we have no guess, but it's not an error yet, since maybe
115 # target architecture will be specified explicitly below.
116 guessed_sbcl_arch=''
118 esac
120 echo //setting up CPU-architecture-dependent information
121 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
122 echo sbcl_arch=\"$sbcl_arch\"
123 if [ "$sbcl_arch" = "" ] ; then
124 echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
125 exit 1
127 printf ":%s" "$sbcl_arch" >> $ltf
129 for d in src/compiler src/assembly; do
130 echo //setting up symlink $d/target
131 original_dir=`pwd`
132 remove_dir_safely "$d/target"
133 cd ./$d
134 if [ -d $sbcl_arch ] ; then
135 link_or_copy $sbcl_arch target
136 else
137 echo "missing sbcl_arch directory $PWD/$sbcl_arch"
138 exit 1
140 cd $original_dir
141 done
143 echo //setting up symlink src/compiler/assembly
144 remove_dir_safely src/compiler/assembly
145 original_dir=`pwd`
146 cd src/compiler
147 link_or_copy ../assembly assembly
148 cd $original_dir
150 echo //setting up OS-dependent information
151 original_dir=`pwd`
152 cd ./src/runtime/
153 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
154 # KLUDGE: these two logically belong in the previous section
155 # ("architecture-dependent"); it seems silly to enforce this in terms
156 # of the shell script, though. -- CSR, 2002-02-03
157 link_or_copy $sbcl_arch-arch.h target-arch.h
158 link_or_copy $sbcl_arch-lispregs.h target-lispregs.h
159 case "$sbcl_os" in
160 linux)
161 printf ' :elf' >> $ltf
162 printf ' :linux' >> $ltf
163 if [ $sbcl_arch = "x86-64" ]; then
164 link_or_copy Config.x86_64-linux Config
165 else
166 link_or_copy Config.$sbcl_arch-linux Config
168 link_or_copy $sbcl_arch-linux-os.h target-arch-os.h
169 link_or_copy linux-os.h target-os.h
171 osf1)
172 printf ' :elf' >> $ltf
173 printf ' :osf1' >> $ltf
174 link_or_copy Config.$sbcl_arch-osf1 Config
175 link_or_copy $sbcl_arch-osf1-os.h target-arch-os.h
176 link_or_copy osf1-os.h target-os.h
178 *bsd)
179 printf ' :bsd' >> $ltf
180 link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
181 link_or_copy bsd-os.h target-os.h
182 case "$sbcl_os" in
183 freebsd)
184 printf ' :elf' >> $ltf
185 printf ' :freebsd' >> $ltf
186 link_or_copy Config.$sbcl_arch-freebsd Config
188 openbsd)
189 printf ' :elf' >> $ltf
190 printf ' :openbsd' >> $ltf
191 link_or_copy Config.$sbcl_arch-openbsd Config
193 netbsd)
194 printf ' :netbsd' >> $ltf
195 printf ' :elf' >> $ltf
196 link_or_copy Config.$sbcl_arch-netbsd Config
199 echo unsupported BSD variant: `uname`
200 exit 1
202 esac
204 darwin)
205 printf ' :mach-o' >> $ltf
206 printf ' :bsd' >> $ltf
207 link_or_copy $sbcl_arch-darwin-os.h target-arch-os.h
208 link_or_copy bsd-os.h target-os.h
209 printf ' :darwin' >> $ltf
210 link_or_copy Config.$sbcl_arch-darwin Config
212 sunos)
213 printf ' :elf' >> $ltf
214 printf ' :sunos' >> $ltf
215 link_or_copy Config.$sbcl_arch-sunos Config
216 link_or_copy $sbcl_arch-sunos-os.h target-arch-os.h
217 link_or_copy sunos-os.h target-os.h
219 win32)
220 printf ' :win32' >> $ltf
221 link_or_copy Config.$sbcl_arch-win32 Config
222 link_or_copy $sbcl_arch-win32-os.h target-arch-os.h
223 link_or_copy win32-os.h target-os.h
226 echo unsupported OS type: `uname`
227 exit 1
229 esac
230 cd $original_dir
232 # FIXME: Things like :c-stack-grows-..., etc, should be
233 # *derived-target-features* or equivalent, so that there was a nicer
234 # way to specify them then sprinkling them in this file. They should
235 # still be tweakable by advanced users, though, but probably not
236 # appear in *features* of target. #!+/- should be adjusted to take
237 # them in account as well. At minimum the nicer specification stuff,
238 # though:
240 # (define-feature :dlopen (features)
241 # (union '(:bsd :linux :darwin :sunos) features))
243 # (define-feature :c-stack-grows-downwards-not-upwards (features)
244 # (member :x86 features))
246 # KLUDGE: currently the x86 only works with the generational garbage
247 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
248 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
249 # the absence of :GENCGC in *FEATURES*). This isn't a great
250 # separation, but for now, rather than have :GENCGC in
251 # base-target-features.lisp-expr, we add it into local-target-features
252 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
253 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
254 if [ "$sbcl_arch" = "x86" ]; then
255 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
256 printf ' :stack-allocatable-closures :alien-callbacks' >> $ltf
257 if [ "$sbcl_os" = "linux" ] || [ "$sbcl_os" = "freebsd" ] || [ "$sbcl_os" = "netbsd" ] || [ "$sbcl_os" = "sunos" ]; then
258 printf ' :linkage-table' >> $ltf
260 if [ "$sbcl_os" = "win32" ]; then
261 # of course it doesn't provide dlopen, but there is
262 # roughly-equivalent magic nevertheless.
263 printf ' :os-provides-dlopen' >> $ltf
265 elif [ "$sbcl_arch" = "x86-64" ]; then
266 printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
267 printf ' :stack-allocatable-closures :alien-callbacks' >> $ltf
268 elif [ "$sbcl_arch" = "mips" ]; then
269 printf ' :linkage-table' >> $ltf
270 printf ' :stack-allocatable-closures' >> $ltf
271 # Use a little C program to try to guess the endianness. Ware
272 # cross-compilers!
274 # FIXME: integrate to grovel-features, mayhaps
275 $GNUMAKE -C tools-for-build determine-endianness -I src/runtime
276 tools-for-build/determine-endianness >> $ltf
277 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "linux" ]; then
278 # Use a C program to detect which kind of glibc we're building on,
279 # to bandage across the break in source compatibility between
280 # versions 2.3.1 and 2.3.2
282 # FIXME: integrate to grovel-features., maypahps
283 printf ' :stack-allocatable-closures' >> $ltf
284 $GNUMAKE -C tools-for-build where-is-mcontext -I src/runtime
285 tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h
286 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "darwin" ]; then
287 printf ' :stack-allocatable-closures' >> $ltf
288 # We provide a dlopen shim, so a little lie won't hurt
289 printf " :os-provides-dlopen :linkage-table :alien-callbacks" >> $ltf
290 # The default stack ulimit under darwin is too small to run PURIFY.
291 # Best we can do is complain and exit at this stage
292 if [ "`ulimit -s`" = "512" ]; then
293 echo "Your stack size limit is too small to build SBCL."
294 echo "See the limit(1) or ulimit(1) commands and the README file."
295 exit 1
297 elif [ "$sbcl_arch" = "sparc" ]; then
298 # Test the compiler in order to see if we are building on Sun
299 # toolchain as opposed to GNU binutils, and write the appropriate
300 # FUNCDEF macro for assembler. No harm in running this on sparc-linux
301 # as well.
302 sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
303 if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
304 printf ' :linkage-table' >> $ltf
306 printf ' :stack-allocatable-closures' >> $ltf
307 elif [ "$sbcl_arch" = "alpha" ]; then
308 printf ' :stack-allocatable-closures' >> $ltf
309 else
310 # Nothing need be done in this case, but sh syntax wants a placeholder.
311 echo > /dev/null
314 export sbcl_os sbcl_arch
315 sh tools-for-build/grovel-features.sh >> $ltf
317 echo //finishing $ltf
318 echo ')' >> $ltf
320 # FIXME: The version system should probably be redone along these lines:
322 # echo //setting up version information.
323 # versionfile=version.txt
324 # cp base-version.txt $versionfile
325 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
326 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
328 # Make a unique ID for this build (to discourage people from
329 # mismatching sbcl and *.core files).
330 if [ `uname` = "SunOS" ] ; then
331 # use /usr/xpg4/bin/id instead of /usr/bin/id
332 PATH=/usr/xpg4/bin:$PATH
334 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp