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