0.8.20.30:
[sbcl.git] / make-config.sh
1 #!/bin/sh
2
3 # The make-config.sh script uses information about the target machine
4 # to set things up for compilation. It's vaguely like a stripped-down
5 # version of autoconf. It's intended to be run as part of make.sh. The
6 # only time you'd want to run it by itself is if you're trying to
7 # cross-compile the system or if you're doing some kind of
8 # troubleshooting.
9
10 # This software is part of the SBCL system. See the README file for
11 # more information.
12 #
13 # This software is derived from the CMU CL system, which was
14 # written at Carnegie Mellon University and released into the
15 # public domain. The software is in the public domain and is
16 # provided with absolutely no warranty. See the COPYING and CREDITS
17 # files for more information.
18
19 echo //entering make-config.sh
20
21 echo //ensuring the existence of output/ directory
22 if [ ! -d output ] ; then mkdir output; fi
23
24 ltf=`pwd`/local-target-features.lisp-expr
25 echo //initializing $ltf
26 echo ';;;; This is a machine-generated file.' > $ltf
27 echo ';;;; Please do not edit it by hand.' >> $ltf
28 echo ';;;; See make-config.sh.' >> $ltf
29 printf '(' >> $ltf
30
31 echo //guessing default target CPU architecture from host architecture
32 case `uname -m` in 
33     *86) guessed_sbcl_arch=x86 ;; 
34     *x86_64) guessed_sbcl_arch=x86-64 ;; 
35     [Aa]lpha) guessed_sbcl_arch=alpha ;;
36     sparc*) guessed_sbcl_arch=sparc ;;
37     sun*) guessed_sbcl_arch=sparc ;;
38     ppc) guessed_sbcl_arch=ppc ;;
39     Power*Macintosh) guessed_sbcl_arch=ppc ;;
40     parisc) guessed_sbcl_arch=hppa ;;
41     mips) guessed_sbcl_arch=mips ;;
42     *)
43         # If we're not building on a supported target architecture, we
44         # we have no guess, but it's not an error yet, since maybe
45         # target architecture will be specified explicitly below.
46         guessed_sbcl_arch=''
47         ;;
48 esac
49
50 echo //setting up CPU-architecture-dependent information
51 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
52 echo sbcl_arch=\"$sbcl_arch\"
53 if [ "$sbcl_arch" = "" ] ; then
54     echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
55     exit 1
56 fi
57 printf ":%s" "$sbcl_arch" >> $ltf 
58
59 for d in src/compiler src/assembly; do
60     echo //setting up symlink $d/target
61     original_dir=`pwd`
62     cd ./$d
63     if [ -h target ] ; then
64         rm target
65     elif [ -w target ] ; then
66         echo "I'm afraid to replace non-symlink $d/target with a symlink."
67         exit 1
68     fi
69     if [ -d $sbcl_arch ] ; then
70         ln -s $sbcl_arch target
71     else
72         echo "missing sbcl_arch directory $PWD/$sbcl_arch"
73         exit 1
74     fi
75     cd $original_dir
76 done
77
78 echo //setting up symlink src/compiler/assembly
79 if [ -h src/compiler/assembly ] ; then
80     rm src/compiler/assembly
81 elif [ -w src/compiler/assembly ] ; then
82     echo "I'm afraid to replace non-symlink compiler/assembly with a symlink."
83     exit 1
84 fi
85 ln -s ../assembly src/compiler/assembly
86
87 echo //setting up OS-dependent information
88 original_dir=`pwd`
89 cd ./src/runtime/
90 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
91 # KLUDGE: these two logically belong in the previous section
92 # ("architecture-dependent"); it seems silly to enforce this in terms
93 # of the shell script, though. -- CSR, 2002-02-03
94 ln -s $sbcl_arch-arch.h target-arch.h
95 ln -s $sbcl_arch-lispregs.h target-lispregs.h
96 case `uname` in 
97     Linux)
98         printf ' :linux' >> $ltf
99         sbcl_os="linux"
100         ln -s Config.$sbcl_arch-linux Config
101         ln -s $sbcl_arch-linux-os.h target-arch-os.h
102         ln -s linux-os.h target-os.h
103         ;;
104     OSF1)                       
105         # it's changed name twice since it was called OSF/1: clearly
106         # the marketers forgot to tell the engineers about Digital Unix
107         # _or_ OSF/1 ...
108         printf ' :osf1' >> $ltf
109         sbcl_os="osf1"
110         ln -s Config.$sbcl_arch-osf1 Config
111         ln -s $sbcl_arch-osf1-os.h target-arch-os.h
112         ln -s osf1-os.h target-os.h
113         ;;
114     *BSD)
115         printf ' :bsd' >> $ltf
116         ln -s $sbcl_arch-bsd-os.h target-arch-os.h
117         ln -s bsd-os.h target-os.h
118         case `uname` in
119             FreeBSD)
120                 printf ' :freebsd' >> $ltf
121                 sbcl_os="freebsd"
122                 ln -s Config.$sbcl_arch-freebsd Config
123                 ;;
124             OpenBSD)
125                 printf ' :openbsd' >> $ltf
126                 sbcl_os="openbsd"
127                 ln -s Config.$sbcl_arch-openbsd Config
128                 ;;
129             NetBSD)
130                 printf ' :netbsd' >> $ltf
131                 sbcl_os="netbsd"
132                 ln -s Config.$sbcl_arch-netbsd Config
133                 ;;
134             *)
135                 echo unsupported BSD variant: `uname`
136                 exit 1
137                 ;;
138         esac
139         ;;
140     Darwin)
141         printf ' :bsd' >> $ltf
142         sbcl_os="darwin"
143         ln -s $sbcl_arch-darwin-os.h target-arch-os.h
144         ln -s bsd-os.h target-os.h
145         printf ' :darwin' >> $ltf
146         ln -s Config.$sbcl_arch-darwin Config
147         ;;
148     SunOS)
149         printf ' :sunos' >> $ltf
150         sbcl_os="sunos"
151         ln -s Config.$sbcl_arch-sunos Config
152         ln -s $sbcl_arch-sunos-os.h target-arch-os.h
153         ln -s sunos-os.h target-os.h
154         ;;
155     *)
156         echo unsupported OS type: `uname`
157         exit 1
158         ;;
159 esac
160 cd $original_dir
161
162 # FIXME: Things like :c-stack-grows-..., etc, should be
163 # *derived-target-features* or equivalent, so that there was a nicer
164 # way to specify them then sprinkling them in this file. They should
165 # still be tweakable by advanced users, though, but probably not
166 # appear in *features* of target. #!+/- should be adjusted to take
167 # them in account as well. At minimum the nicer specification stuff,
168 # though:
169 #
170 # (define-feature :dlopen (features)
171 #   (union '(:bsd :linux :darwin :sunos) features))
172 #
173 # (define-feature :c-stack-grows-downwards-not-upwards (features)
174 #   (member :x86 features))
175
176 # KLUDGE: currently the x86 only works with the generational garbage
177 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
178 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
179 # the absence of :GENCGC in *FEATURES*). This isn't a great
180 # separation, but for now, rather than have :GENCGC in
181 # base-target-features.lisp-expr, we add it into local-target-features
182 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
183 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
184 if [ "$sbcl_arch" = "x86" ]; then
185     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
186     printf ' :stack-allocatable-closures' >> $ltf
187     if [ "$sbcl_os" = "linux" ] || [ "$sbcl_os" = "freebsd" ] || [ "$sbcl_os" = "netbsd" ]; then
188         printf ' :linkage-table' >> $ltf
189     fi
190 elif [ "$sbcl_arch" = "x86-64" ]; then
191     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack :linkage-table' >> $ltf
192 elif [ "$sbcl_arch" = "mips" ]; then
193     # Use a little C program to try to guess the endianness.  Ware
194     # cross-compilers!
195     #
196     # FIXME: integrate to grovel-features, mayhaps
197     $GNUMAKE -C tools-for-build determine-endianness -I src/runtime
198     tools-for-build/determine-endianness >> $ltf
199 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "linux" ]; then
200     # Use a C program to detect which kind of glibc we're building on,
201     # to bandage across the break in source compatibility between
202     # versions 2.3.1 and 2.3.2
203     #
204     # FIXME: integrate to grovel-features., maypahps
205     $GNUMAKE -C tools-for-build where-is-mcontext -I src/runtime
206     tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h
207 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "darwin" ]; then
208     # We provide a dlopen shim, so a little lie won't hurt
209     printf " :os-provides-dlopen :linkage-table" >> $ltf
210     # The default stack ulimit under darwin is too small to run PURIFY.
211     # Best we can do is complain and exit at this stage
212     if [ "`ulimit -s`" = "512" ]; then
213         echo "Your stack size limit is too small to build SBCL."
214         echo "See the limit(1) or ulimit(1) commands and the README file."
215         exit 1
216     fi
217 elif [ "$sbcl_arch" = "sparc" ]; then
218     # Test the compiler in order to see if we are building on Sun 
219     # toolchain as opposed to GNU binutils, and write the appropriate
220     # FUNCDEF macro for assembler. No harm in running this on sparc-linux 
221     # as well.
222     sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
223     if [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "linux" ]; then
224         printf ' :linkage-table' >> $ltf
225     fi
226 else
227     # Nothing need be done in this case, but sh syntax wants a placeholder.
228     echo > /dev/null
229 fi
230
231 export sbcl_os sbcl_arch
232 sh tools-for-build/grovel-features.sh >> $ltf
233
234 echo //finishing $ltf
235 echo ')' >> $ltf
236
237 # FIXME: The version system should probably be redone along these lines:
238 #
239 # echo //setting up version information.
240 # versionfile=version.txt
241 # cp base-version.txt $versionfile
242 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
243 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
244
245 # Make a unique ID for this build (to discourage people from
246 # mismatching sbcl and *.core files).
247 if [ `uname` = "SunOS" ] ; then
248   # use /usr/xpg4/bin/id instead of /usr/bin/id
249   PATH=/usr/xpg4/bin:$PATH
250 fi
251 echo '"'`hostname`-`id -un`-`date +%Y-%m-%d-%H-%M-%S`'"' > output/build-id.tmp
252