7664551dc5b5c4ef669ee72e9f8a27281e92b436
[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 //checking that we are not root
22 if [ `id -u` -eq 0 ] ; then echo 'Argh! we are (fake)root!'; exit 1; fi;
23
24 echo //ensuring the existence of output/ directory
25 if [ ! -d output ] ; then mkdir output; fi
26
27 ltf=`pwd`/local-target-features.lisp-expr
28 echo //initializing $ltf
29 echo ';;;; This is a machine-generated file.' > $ltf
30 echo ';;;; Please do not edit it by hand.' >> $ltf
31 echo ';;;; See make-config.sh.' >> $ltf
32 printf '(' >> $ltf
33
34 echo //guessing default target CPU architecture from host architecture
35 case `uname -m` in 
36     *86|x86_64) guessed_sbcl_arch=x86 ;; 
37     [Aa]lpha) guessed_sbcl_arch=alpha ;;
38     sparc*) guessed_sbcl_arch=sparc ;;
39     sun*) guessed_sbcl_arch=sparc ;;
40     ppc) guessed_sbcl_arch=ppc ;;
41     Power*Macintosh) guessed_sbcl_arch=ppc ;;
42     parisc) guessed_sbcl_arch=hppa ;;
43     mips) guessed_sbcl_arch=mips ;;
44     *)
45         # If we're not building on a supported target architecture, we
46         # we have no guess, but it's not an error yet, since maybe
47         # target architecture will be specified explicitly below.
48         guessed_sbcl_arch=''
49         ;;
50 esac
51
52 echo //setting up CPU-architecture-dependent information
53 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
54 echo sbcl_arch=\"$sbcl_arch\"
55 if [ "$sbcl_arch" = "" ] ; then
56     echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
57     exit 1
58 fi
59 printf ":%s" "$sbcl_arch" >> $ltf 
60
61 for d in src/compiler src/assembly; do
62     echo //setting up symlink $d/target
63     original_dir=`pwd`
64     cd $d
65     if [ -h target ] ; then
66         rm target
67     elif [ -w target ] ; then
68         echo "I'm afraid to replace non-symlink $d/target with a symlink."
69         exit 1
70     fi
71     if [ -d $sbcl_arch ] ; then
72         ln -s $sbcl_arch target
73     else
74         echo "missing sbcl_arch directory $PWD/$sbcl_arch"
75         exit 1
76     fi
77     cd $original_dir
78 done
79
80 echo //setting up symlink src/compiler/assembly
81 if [ -h src/compiler/assembly ] ; then
82     rm src/compiler/assembly
83 elif [ -w src/compiler/assembly ] ; then
84     echo "I'm afraid to replace non-symlink compiler/assembly with a symlink."
85     exit 1
86 fi
87 ln -s ../assembly src/compiler/assembly
88
89 echo //setting up OS-dependent information
90 original_dir=`pwd`
91 cd src/runtime/
92 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
93 # KLUDGE: these two logically belong in the previous section
94 # ("architecture-dependent"); it seems silly to enforce this in terms
95 # of the shell script, though. -- CSR, 2002-02-03
96 ln -s $sbcl_arch-arch.h target-arch.h
97 ln -s $sbcl_arch-lispregs.h target-lispregs.h
98 case `uname` in 
99     Linux)
100         printf ' :linux' >> $ltf
101         sbcl_os="linux"
102         if [ "`uname -m`" = "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 ' :osf1' >> $ltf
115         sbcl_os="osf1"
116         ln -s Config.$sbcl_arch-osf1 Config
117         ln -s $sbcl_arch-osf1-os.h target-arch-os.h
118         ln -s osf1-os.h target-os.h
119         ;;
120     *BSD)
121         printf ' :bsd' >> $ltf
122         ln -s $sbcl_arch-bsd-os.h target-arch-os.h
123         ln -s bsd-os.h target-os.h
124         case `uname` in
125             FreeBSD)
126                 printf ' :freebsd' >> $ltf
127                 sbcl_os="freebsd"
128                 ln -s Config.$sbcl_arch-freebsd Config
129                 ;;
130             OpenBSD)
131                 printf ' :openbsd' >> $ltf
132                 sbcl_os="openbsd"
133                 ln -s Config.$sbcl_arch-openbsd Config
134                 ;;
135             *)
136                 echo unsupported BSD variant: `uname`
137                 exit 1
138                 ;;
139         esac
140         ;;
141     Darwin)
142         printf ' :bsd' >> $ltf
143         sbcl_os="darwin"
144         ln -s $sbcl_arch-darwin-os.h target-arch-os.h
145         ln -s bsd-os.h target-os.h
146         printf ' :darwin' >> $ltf
147         ln -s Config.$sbcl_arch-darwin Config
148         ;;
149     SunOS)
150         printf ' :sunos' >> $ltf
151         sbcl_os="sunos"
152         ln -s Config.$sbcl_arch-sunos Config
153         ln -s $sbcl_arch-sunos-os.h target-arch-os.h
154         ln -s sunos-os.h target-os.h
155         ;;
156     *)
157         echo unsupported OS type: `uname`
158         exit 1
159         ;;
160 esac
161 cd $original_dir
162
163 # KLUDGE: currently the x86 only works with the generational garbage
164 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
165 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
166 # the absence of :GENCGC in *FEATURES*). This isn't a great
167 # separation, but for now, rather than have :GENCGC in
168 # base-target-features.lisp-expr, we add it into local-target-features
169 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
170 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
171 if [ "$sbcl_arch" = "x86" ] ; then
172     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
173 elif [ "$sbcl_arch" = "mips" ] ; then
174     # Use a little C program to try to guess the endianness.  Ware
175     # cross-compilers!
176     $GNUMAKE -C tools-for-build determine-endianness
177     tools-for-build/determine-endianness >> $ltf
178 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "linux" ]; then
179     # Use a C program to detect which kind of glibc we're building on,
180     # to bandage across the break in source compatibility between
181     # versions 2.3.1 and 2.3.2
182     $GNUMAKE -C tools-for-build where-is-mcontext
183     tools-for-build/where-is-mcontext > src/runtime/ppc-linux-mcontext.h
184 elif [ "$sbcl_arch" = "ppc" -a "$sbcl_os" = "darwin" ]; then
185     # The default stack ulimit under darwin is too small to run PURIFY.
186     # Best we can do is complain and exit at this stage
187     if [ "`ulimit -s`" = "512" ]; then
188         echo "Your stack size limit is too small to build SBCL."
189         echo "See the limit(1) or ulimit(1) commands and the README file."
190         exit 1
191     fi
192 elif [ "$sbcl_arch" = "sparc" ]; then
193     # Test the compiler in order to see if we are building on Sun 
194     # toolchain as opposed to GNU binutils, and write the appropriate
195     # FUNCDEF macro for assembler. No harm in running this on sparc-linux 
196     # as well.
197     sh tools-for-build/sparc-funcdef.sh > src/runtime/sparc-funcdef.h
198 else
199     # Nothing need be done in this case, but sh syntax wants a placeholder.
200     echo > /dev/null
201 fi
202
203 echo //finishing $ltf
204 echo ')' >> $ltf
205
206 # FIXME: The version system should probably be redone along these lines:
207 #
208 # echo //setting up version information.
209 # versionfile=version.txt
210 # cp base-version.txt $versionfile
211 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
212 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
213
214 # Make a unique ID for this build (to discourage people from
215 # mismatching sbcl and *.core files).
216 echo '"'`hostname`-`whoami`-`date +%F-%H-%M-%S`'"' > output/build-id.tmp
217