ppc64: Don't set Kp bit on SLB
[openbios/afaerber.git] / config / scripts / switch-arch
blob1e630dad2c8756a6e74f1689e1b6f821a352a76f
1 #!/bin/sh
4 # MOLPATH is needed if you want to build openbios-mol.elf
6 MOLPATH=$HOME/mol-0.9.71
8 if [ x"$1" = x -o "$1" = "-help" ]; then
9 printf "Usage:\n $0 [arch-config]...\n"
10 printf "arch-config values supported for native or cross compiled builds:\n"
11 printf " amd64, ppc, sparc32, sparc64, x86\n\n"
12 printf "Add \"unix-\" prefix to compile openbios-unix executable (native only)\n"
13 printf "Add \"builtin-\" prefix to compile openbios-builtin executables\n\n"
14 printf "Without prefixes, builtin and unix targets are selected\n\n"
15 printf "Special targets: mol-ppc briq-ppc pearpc-ppc qemu-ppc qemu-ppc64 xbox-x86\n\n"
16 printf "Example: $0 builtin-sparc32 unix-amd64 builtin-amd64\n"
17 exit 0
20 crosscflags()
22 host=$1
23 target=$2
25 if test "$host" = "powerpc" -o "$host" = "ppc" \
26 -o "$host" = "mips" -o "$host" = "s390" \
27 -o "$host" = "sparc32" -o "$host" = "sparc64" \
28 -o "$host" = "m68k" -o "$host" = "armv4b"; then
29 hostbigendian="yes"
30 else
31 hostbigendian="no"
34 # host long bits test
35 if test "$host" = "sparc64" -o "$host" = "ia64" \
36 -o "$host" = "amd64" -o "$host" = "x86_64" \
37 -o "$host" = "alpha"; then
38 hostlongbits="64"
39 else
40 hostlongbits="32"
43 if test "$target" = "powerpc" -o "$target" = "ppc" \
44 -o "$target" = "powerpc64" -o "$target" = "ppc64" \
45 -o "$target" = "mips" -o "$target" = "s390" \
46 -o "$target" = "sparc32" -o "$target" = "sparc64" \
47 -o "$target" = "m68k" -o "$target" = "armv4b"; then
48 targetbigendian="yes"
49 else
50 targetbigendian="no"
53 # target long bits test
54 if test "$target" = "sparc64" -o "$target" = "ia64" \
55 -o "$target" = "amd64" -o "$target" = "x86_64" \
56 -o "$target" = "powerpc64" -o "$target" = "ppc64" \
57 -o "$target" = "alpha"; then
58 targetlongbits="64"
59 else
60 targetlongbits="32"
63 if test "$targetbigendian" = "$hostbigendian"; then
64 cflags="-USWAP_ENDIANNESS"
65 else
66 cflags="-DSWAP_ENDIANNESS"
69 if test "$targetlongbits" = "$hostlongbits"; then
70 cflags="$cflags -DNATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH"
71 elif test "$targetlongbits" -lt "$hostlongbits"; then
72 cflags="$cflags -DNATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH"
73 else
74 cflags="$cflags -DNATIVE_BITWIDTH_LARGER_THAN_HOST_BITWIDTH"
77 if test "$target" = "sparc64" -o "$target" = "ia64" \
78 -o "$target" = "amd64" -o "$target" = "x86_64" \
79 -o "$target" = "alpha"; then
80 if test "$host" = "x86"; then
81 cflags="$cflags -DNEED_FAKE_INT128_T"
82 elif test "$host" = "ppc" -a `uname -s` = "Darwin"; then
83 cflags="$cflags -DNEED_FAKE_INT128_T"
87 CROSSCFLAGS=$cflags
90 archname()
92 HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
93 -e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
94 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
95 -e "s/Power Macintosh/ppc/"`
98 select_prefix()
100 for TARGET in ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-
102 if type ${TARGET}gcc > /dev/null 2>&1
103 then
104 return
106 done
107 if [ "$ARCH" = "$HOSTARCH" ]; then
108 return
110 echo "ERROR: no ${1} cross-compiler found !" 1>&2
111 exit 1
114 config_set_boolean()
116 option=`echo $1 | tr a-z A-Z`
117 echo "<option name=\"$option\" type=\"boolean\" value=\"true\" />"
120 if ! test -f utils/dist/debian/rules; then
121 echo "switch-arch must be run from the top-level source directory" >&2
122 exit 1
125 # This is needed because viewvc messes with the permissions of executables:
126 chmod 755 utils/dist/debian/rules
127 chmod 755 config/scripts/switch-arch
128 chmod 755 config/scripts/reldir
130 if test "x$HOSTARCH" = "x"; then
131 archname
134 VERSION=`head VERSION`
136 echo "Configuring OpenBIOS on $HOSTARCH for $*"
138 target_list=""
139 for target in $*; do
140 case $target in
141 unix-*|builtin-*|plain-*|mol-ppc|briq-ppc|pearpc-ppc|qemu-ppc|qemu-ppc64|xbox-x86)
142 target_list="$target_list $target"
144 cross-*)
145 echo "\"cross-\" prefix is no longer needed"
146 target=`echo $target | sed s/cross-//g`
147 target_list="$target_list builtin-$target"
150 #default: build builtin and if possible, unix target
151 target_list="$target_list builtin-$target unix-$target"
153 esac
154 done
156 arch_list=""
157 for target in $target_list; do
158 arch=`echo $target | sed s/.*-//g`
159 if ! test -f config/examples/${arch}_config.xml; then
160 echo "Cannot find config/examples/${arch}_config.xml" >&2
161 exit 1
163 if ! echo $arch_list | grep -q "$arch"; then
164 arch_list="$arch_list $arch"
166 done
168 for ARCH in $arch_list; do
169 unix="no"
170 builtin="no"
171 plain="no"
172 mol="no"
173 briq="no"
174 pearpc="no"
175 qemu="no"
176 xbox="no"
177 cross="no"
179 for target in $target_list; do
180 case $target in
181 *-$ARCH)
185 continue
187 esac
188 case $target in
189 mol-ppc)
190 mol="yes"
192 briq-ppc)
193 briq="yes"
195 pearpc-ppc)
196 pearpc="yes"
198 builtin-ppc|qemu-ppc|builtin-ppc64|qemu-ppc64)
199 qemu="yes"
201 xbox-x86)
202 xbox="yes"
204 builtin-sparc64)
205 builtin="yes"
206 qemu="yes"
208 unix-*)
209 if [ "$ARCH" != "$HOSTARCH" ]; then
210 # Can't cross compile Unix target
211 continue
213 unix="yes"
215 builtin-*)
216 builtin="yes"
218 plain-*)
219 plain="yes"
221 esac
222 done
224 BASEARCH=$ARCH
225 case $ARCH in
226 amd64)
227 select_prefix x86_64
228 CFLAGS="-fno-builtin"
229 AS_FLAGS=
232 ppc)
233 select_prefix powerpc
234 if [ "$unix" = "no" ]; then
235 CFLAGS="-msoft-float -fno-builtin-bcopy -fno-builtin-log2"
236 else
237 CFLAGS="-fno-builtin"
239 AS_FLAGS=
242 ppc64)
243 select_prefix powerpc64
244 CFLAGS="-Wa,-a64 -m64 -msoft-float -fno-builtin"
245 AS_FLAGS="-Wa,-a64"
246 BASEARCH=ppc
249 sparc32)
250 select_prefix sparc
251 CFLAGS="-Wa,-xarch=v8 -Wa,-32 -m32 -mcpu=supersparc -fno-builtin"
252 AS_FLAGS="-Wa,-xarch=v8 -Wa,-32"
255 sparc64)
256 select_prefix sparc64
257 CFLAGS="-Wa,-xarch=v9b -Wa,-64 -m64 -mcpu=ultrasparc -mcmodel=medany -fno-builtin"
258 AS_FLAGS="-Wa,-xarch=v9b -Wa,-64"
261 x86)
262 select_prefix i486
263 CFLAGS="-fno-builtin -m32"
264 AS_FLAGS="-Wa,-32"
266 esac
267 if [ "$ARCH" != "$HOSTARCH" -o `uname -s` = "Darwin" ]; then
268 cross="yes"
270 crosscflags $HOSTARCH $ARCH
271 OBJDIR=obj-$ARCH
273 printf "Initializing build tree $OBJDIR..."
274 rm -rf "$OBJDIR"
275 mkdir "$OBJDIR"
276 mkdir -p $OBJDIR/target
277 mkdir -p $OBJDIR/target/include
278 mkdir -p $OBJDIR/target/arch
279 mkdir -p $OBJDIR/target/arch/unix
280 mkdir -p $OBJDIR/target/arch/$ARCH
281 mkdir -p $OBJDIR/target/libgcc
282 mkdir -p $OBJDIR/target/kernel
283 mkdir -p $OBJDIR/target/libopenbios
284 mkdir -p $OBJDIR/target/packages
285 mkdir -p $OBJDIR/target/fs
286 mkdir -p $OBJDIR/target/fs/grubfs
287 mkdir -p $OBJDIR/target/fs/hfs
288 mkdir -p $OBJDIR/target/fs/hfsplus
289 mkdir -p $OBJDIR/target/fs/iso9660
290 mkdir -p $OBJDIR/target/fs/ext2
291 mkdir -p $OBJDIR/target/drivers
292 mkdir -p $OBJDIR/target/libc
293 mkdir -p $OBJDIR/host/include
294 mkdir -p $OBJDIR/host/kernel
295 mkdir -p $OBJDIR/forth
296 ln -s ../../../include/arch/$BASEARCH $OBJDIR/target/include/asm
297 #compile the host binary with target settings instead
298 #ln -s ../../../include/arch/$HOSTARCH $OBJDIR/host/include/asm
299 if [ "$mol" = "yes" ]; then
300 printf "\nUsing MOL path $MOLPATH...\n"
301 mkdir -p $OBJDIR/target/arch/ppc/mol
302 ln -s $MOLPATH/src/shared/osi_calls.h $OBJDIR/target/include/
303 ln -s $MOLPATH/src/shared/osi.h $OBJDIR/target/include/
304 ln -s $MOLPATH/src/shared/prom.h $OBJDIR/target/include/
305 ln -s $MOLPATH/src/include/boothelper_sh.h $OBJDIR/target/include/
306 ln -s $MOLPATH/src/include/video_sh.h $OBJDIR/target/include/
307 ln -s $MOLPATH/src/include/pseudofs_sh.h $OBJDIR/target/include/
308 ln -s $MOLPATH/src/include/kbd_sh.h $OBJDIR/target/include/
309 ln -s $MOLPATH/src/drivers/disk/include/scsi_sh.h $OBJDIR/target/include/
310 ln -s $MOLPATH/src/drivers/disk/include/ablk_sh.h $OBJDIR/target/include/
312 if [ "$briq" = "yes" ]; then
313 mkdir -p $OBJDIR/target/arch/ppc/briq
315 if [ "$pearpc" = "yes" ]; then
316 mkdir -p $OBJDIR/target/arch/ppc/pearpc
318 if [ "$qemu" = "yes" ]; then
319 mkdir -p $OBJDIR/target/arch/ppc/qemu
321 if [ "$xbox" = "yes" ]; then
322 mkdir -p $OBJDIR/target/arch/x86/xbox
324 echo "ok."
326 cd $OBJDIR
327 SRCDIR=..
328 ODIR=.
330 printf "Creating target Makefile..."
331 echo "ARCH=$ARCH" > $ODIR/config.mak
332 if [ "$cross" = "yes" ]; then
333 echo "TARGET=$TARGET" >> $ODIR/config.mak
335 echo "CFLAGS=$CFLAGS" >> $ODIR/config.mak
336 echo "AS_FLAGS=$AS_FLAGS" >> $ODIR/config.mak
337 echo "HOSTARCH?=$HOSTARCH" >> $ODIR/config.mak
338 echo "CROSSCFLAGS=$CROSSCFLAGS" >> $ODIR/config.mak
339 echo "VERSION=\"$VERSION\"" >> $ODIR/config.mak
341 ln -s $SRCDIR/config/xml/rules.xml $ODIR/rules.xml
342 echo "<?xml version=\"1.0\"?><config>" > $ODIR/config.xml
343 # Generic
344 config_set_boolean CONFIG_$ARCH >> $ODIR/config.xml
345 if [ "$BASEARCH" != "$ARCH" ]; then
346 config_set_boolean CONFIG_$BASEARCH >> $ODIR/config.xml
348 if [ "$mol" = "yes" ]; then
349 config_set_boolean CONFIG_MOL >> $ODIR/config.xml
351 if [ "$briq" = "yes" ]; then
352 config_set_boolean CONFIG_BRIQ >> $ODIR/config.xml
354 if [ "$pearpc" = "yes" ]; then
355 config_set_boolean CONFIG_PEARPC >> $ODIR/config.xml
357 if [ "$qemu" = "yes" ]; then
358 config_set_boolean CONFIG_QEMU >> $ODIR/config.xml
360 if [ "$xbox" = "yes" ]; then
361 config_set_boolean CONFIG_XBOX >> $ODIR/config.xml
363 if [ "$targetbigendian" = "yes" ]; then
364 config_set_boolean CONFIG_BIG_ENDIAN >> $ODIR/config.xml
365 else
366 config_set_boolean CONFIG_LITTLE_ENDIAN >> $ODIR/config.xml
368 # Kernel binaries
369 if [ "$plain" = "yes" ]; then
370 config_set_boolean CONFIG_IMAGE_ELF >> $ODIR/config.xml
372 if [ "$builtin" = "yes" ]; then
373 config_set_boolean CONFIG_IMAGE_ELF_EMBEDDED >> $ODIR/config.xml
375 # Build hosted Unix binary?
376 if [ "$unix" = "yes" ]; then
377 config_set_boolean CONFIG_HOST_UNIX >> $ODIR/config.xml
378 #config_set_boolean CONFIG_UNIX_QT >> $ODIR/config.xml
379 #config_set_boolean CONFIG_PLUGINS >> $ODIR/config.xml
381 cat $SRCDIR/config/examples/${ARCH}_config.xml >> $ODIR/config.xml
383 echo "</config>" >> $ODIR/config.xml
384 ln -s ../Makefile.target $ODIR/Makefile
385 xsltproc $SRCDIR/config/xml/xinclude.xsl $SRCDIR/build.xml > $ODIR/build-full.xml
386 xsltproc $SRCDIR/config/xml/makefile.xsl $ODIR/build-full.xml > $ODIR/rules.mak
387 echo "ok."
388 printf "Creating config files..."
389 xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml > $ODIR/host/include/autoconf.h
390 xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml > $ODIR/target/include/autoconf.h
391 xsltproc $SRCDIR/config/xml/config-forth.xsl $ODIR/config.xml > $ODIR/forth/config.fs
392 echo "ok."
394 cd $SRCDIR
395 done