0.8.1.15:
[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     [Aa]lpha) guessed_sbcl_arch=alpha ;;
35     sparc*) guessed_sbcl_arch=sparc ;;
36     sun*) guessed_sbcl_arch=sparc ;;
37     ppc) guessed_sbcl_arch=ppc ;;
38     parisc) guessed_sbcl_arch=hppa ;;
39     mips) guessed_sbcl_arch=mips ;;
40     *)
41         # If we're not building on a supported target architecture, we
42         # we have no guess, but it's not an error yet, since maybe
43         # target architecture will be specified explicitly below.
44         guessed_sbcl_arch=''
45         ;;
46 esac
47
48 echo //setting up CPU-architecture-dependent information
49 sbcl_arch=${SBCL_ARCH:-$guessed_sbcl_arch}
50 echo sbcl_arch=\"$sbcl_arch\"
51 if [ "$sbcl_arch" = "" ] ; then
52     echo "can't guess target SBCL architecture, need SBCL_ARCH environment var"
53     exit 1
54 fi
55 printf ":%s" "$sbcl_arch" >> $ltf 
56
57 for d in src/compiler src/assembly; do
58     echo //setting up symlink $d/target
59     original_dir=`pwd`
60     cd $d
61     if [ -h target ] ; then
62         rm target
63     elif [ -w target ] ; then
64         echo "I'm afraid to replace non-symlink $d/target with a symlink."
65         exit 1
66     fi
67     if [ -d $sbcl_arch ] ; then
68         ln -s $sbcl_arch target
69     else
70         echo "missing sbcl_arch directory $PWD/$sbcl_arch"
71         exit 1
72     fi
73     cd $original_dir
74 done
75
76 echo //setting up symlink src/compiler/assembly
77 if [ -h src/compiler/assembly ] ; then
78     rm src/compiler/assembly
79 elif [ -w src/compiler/assembly ] ; then
80     echo "I'm afraid to replace non-symlink compiler/assembly with a symlink."
81     exit 1
82 fi
83 ln -s ../assembly src/compiler/assembly
84
85 echo //setting up OS-dependent information
86 original_dir=`pwd`
87 cd src/runtime/
88 rm -f Config target-arch-os.h target-arch.h target-os.h target-lispregs.h
89 # KLUDGE: these two logically belong in the previous section
90 # ("architecture-dependent"); it seems silly to enforce this in terms
91 # of the shell script, though. -- CSR, 2002-02-03
92 ln -s $sbcl_arch-arch.h target-arch.h
93 ln -s $sbcl_arch-lispregs.h target-lispregs.h
94 case `uname` in 
95     Linux)
96         printf ' :linux' >> $ltf
97         ln -s Config.$sbcl_arch-linux Config
98         ln -s $sbcl_arch-linux-os.h target-arch-os.h
99         ln -s linux-os.h target-os.h
100         ;;
101     OSF1)                       
102         # it's changed name twice since it was called OSF/1: clearly
103         # the marketers forgot to tell the engineers about Digital Unix
104         # _or_ OSF/1 ...
105         printf ' :osf1' >> $ltf
106         ln -s Config.$sbcl_arch-osf1 Config
107         ln -s $sbcl_arch-osf1-os.h target-arch-os.h
108         ln -s osf1-os.h target-os.h
109         ;;
110     *BSD)
111         printf ' :bsd' >> $ltf
112         ln -s $sbcl_arch-bsd-os.h target-arch-os.h
113         ln -s bsd-os.h target-os.h
114         case `uname` in
115             FreeBSD)
116                 printf ' :freebsd' >> $ltf
117                 ln -s Config.$sbcl_arch-freebsd Config
118                 ;;
119             OpenBSD)
120                 printf ' :openbsd' >> $ltf
121                 ln -s Config.$sbcl_arch-openbsd Config
122                 ;;
123             *)
124                 echo unsupported BSD variant: `uname`
125                 exit 1
126                 ;;
127         esac
128         ;;
129     SunOS)
130         printf ' :sunos' >> $ltf
131         ln -s Config.$sbcl_arch-sunos Config
132         ln -s $sbcl_arch-sunos-os.h target-arch-os.h
133         ln -s sunos-os.h target-os.h
134         ;;
135     *)
136         echo unsupported OS type: `uname`
137         exit 1
138         ;;
139 esac
140 cd $original_dir
141
142 # KLUDGE: currently the x86 only works with the generational garbage
143 # collector (indicated by the presence of :GENCGC in *FEATURES*) and
144 # alpha, sparc and ppc with the stop'n'copy collector (indicated by
145 # the absence of :GENCGC in *FEATURES*). This isn't a great
146 # separation, but for now, rather than have :GENCGC in
147 # base-target-features.lisp-expr, we add it into local-target-features
148 # if we're building for x86. -- CSR, 2002-02-21 Then we do something
149 # similar with :STACK-GROWS-FOOWARD, too. -- WHN 2002-03-03
150 if [ "$sbcl_arch" = "x86" ] ; then
151     printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf
152 elif [ "$sbcl_arch" = "mips" ] ; then
153     # Use a little C program to try to guess the endianness.  Ware
154     # cross-compilers!
155     $GNUMAKE -C tools-for-build determine-endianness
156     tools-for-build/determine-endianness >> $ltf
157 else
158     # Nothing need be done in this case, but sh syntax wants a placeholder.
159     echo > /dev/null
160 fi
161                             
162 echo //finishing $ltf
163 echo ')' >> $ltf
164
165 # FIXME: The version system should probably be redone along these lines:
166 #
167 # echo //setting up version information.
168 # versionfile=version.txt
169 # cp base-version.txt $versionfile
170 # echo " (built `date -u` by `whoami`@`hostname`)" >> $versionfile
171 # echo 'This is a machine-generated file and should not be edited by hand.' >> $versionfile
172
173 # Make a unique ID for this build (to discourage people from
174 # mismatching sbcl and *.core files).
175 echo '"'`hostname`-`whoami`-`date +%F-%H-%M-%S`'"' > output/build-id.tmp
176