These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / openbios / config / scripts / switch-arch
1 #!/bin/sh
2
3 #
4 # MOLPATH is needed if you want to build openbios-mol.elf
5 #
6 MOLPATH=$HOME/mol-0.9.71
7
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
18 fi
19
20 is_bigendian()
21 {
22     cpu=$1
23
24     if test "$cpu" = "powerpc" -o "$cpu" = "ppc" \
25         -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \
26         -o "$cpu" = "mips" -o "$cpu" = "s390" \
27         -o "$cpu" = "sparc32" -o "$cpu" = "sparc64" \
28         -o "$cpu" = "m68k" -o "$cpu" = "armv4b"; then
29         echo yes
30     else
31         echo no
32     fi
33 }
34
35 longbits()
36 {
37     cpu=$1
38     if test "$cpu" = "sparc64" -o "$cpu" = "ia64" \
39         -o "$cpu" = "amd64" -o "$cpu" = "x86_64" \
40         -o "$cpu" = "powerpc64" -o "$cpu" = "ppc64" \
41         -o "$cpu" = "alpha"; then
42         echo 64
43     else
44         echo 32
45     fi
46 }
47
48 basearch()
49 {
50     arch=$1
51     case $arch in
52     powerpc|ppc64|powerpc64)
53         echo ppc
54         ;;
55     *)
56         echo $arch
57         ;;
58     esac
59 }
60
61 crosscflags()
62 {
63     host=$1
64     target=$2
65
66     hostbigendian=$(is_bigendian $host)
67     hostlongbits=$(longbits $host)
68
69     targetbigendian=$(is_bigendian $target)
70     targetlongbits=$(longbits $target)
71
72     if test "$targetbigendian" = "$hostbigendian"; then
73         cflags="-USWAP_ENDIANNESS"
74     else
75         cflags="-DSWAP_ENDIANNESS"
76     fi
77
78     if test "$targetlongbits" = "$hostlongbits"; then
79         cflags="$cflags -DNATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH"
80     elif test "$targetlongbits" -lt "$hostlongbits"; then
81         cflags="$cflags -DNATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH"
82     else
83         cflags="$cflags -DNATIVE_BITWIDTH_LARGER_THAN_HOST_BITWIDTH"
84     fi
85
86     if test "$target" = "sparc64" -o "$target" = "ia64" \
87          -o "$target" = "amd64" -o "$target" = "x86_64" \
88          -o "$target" = "alpha"; then
89         if test "$host" = "x86"; then
90             cflags="$cflags -DNEED_FAKE_INT128_T"
91         elif test "$host" = "arm"; then
92             cflags="$cflags -DNEED_FAKE_INT128_T"
93         elif test "$host" = "ppc" -a `uname -s` = "Darwin"; then
94             cflags="$cflags -DNEED_FAKE_INT128_T"
95         fi
96     fi
97
98     CROSSCFLAGS=$cflags
99 }
100
101 archname()
102 {
103     HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
104         -e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
105         -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
106         -e "s/Power Macintosh/ppc/"`
107 }
108
109 select_prefix()
110 {
111     BASEARCH=$(basearch $ARCH)
112     for target_arch ; do
113         TARGETS="${target_arch}-unknown-linux-gnu- ${target_arch}-linux-gnu- ${target_arch}-linux- ${target_arch}-elf- ${target_arch}-eabi-"
114
115         if [ x"$CROSS_COMPILE" != "x" ]; then
116             TARGETS=$CROSS_COMPILE
117         fi
118
119         for TARGET in $TARGETS
120         do
121             if type ${TARGET}gcc > /dev/null 2>&1
122             then
123                 return
124             fi
125         done
126         if [ "$BASEARCH" = "$(basearch $HOSTARCH)" ]; then
127             TARGET=""
128             return
129         fi
130     done
131     echo "ERROR: no $* cross-compiler found !" 1>&2
132     exit 1
133 }
134
135 config_set_boolean()
136 {
137     option=`echo $1 | tr a-z A-Z`
138     echo "<option name=\"$option\" type=\"boolean\" value=\"true\" />"
139 }
140
141 exists()
142 {
143     type "$1" >/dev/null 2>&1
144 }
145
146
147 SRCDIR=`dirname "$0"`/../..
148 BUILDDIR=`pwd`
149
150 # make source path absolute
151 SRCDIR=`cd "$SRCDIR"; pwd`
152
153 if test "x$HOSTARCH" = "x"; then
154     archname
155 fi
156
157 VERSION=`head $SRCDIR/VERSION`
158
159 echo "Configuring OpenBIOS on $HOSTARCH for $*"
160
161 if exists toke; then
162     :
163 else
164     echo "Unable to locate toke executable from the fcode-utils package - aborting"
165     exit 1
166 fi
167
168 target_list=""
169 for target in $*; do
170     case $target in
171         unix-*|builtin-*|plain-*|mol-ppc|briq-ppc|pearpc-ppc|qemu-ppc|qemu-ppc64|xbox-x86)
172         target_list="$target_list $target"
173         ;;
174         cross-*)
175         echo "\"cross-\" prefix is no longer needed"
176         target=`echo $target | sed s/cross-//g`
177         target_list="$target_list builtin-$target"
178         ;;
179         *)
180         #default: build builtin and if possible, unix target
181         target_list="$target_list builtin-$target unix-$target"
182         ;;
183     esac
184 done
185
186 arch_list=""
187 for target in $target_list; do
188     arch=`echo $target | sed s/.*-//g`
189     if ! test -f $SRCDIR/config/examples/${arch}_config.xml; then
190         echo "Cannot find $SRCDIR/config/examples/${arch}_config.xml" >&2
191         exit 1
192     fi
193     if ! echo $arch_list | grep -q "$arch"; then
194         arch_list="$arch_list $arch"
195     fi
196 done
197
198 for ARCH in $arch_list; do
199     unix="no"
200     builtin="no"
201     plain="no"
202     mol="no"
203     briq="no"
204     pearpc="no"
205     qemu="no"
206     xbox="no"
207     cross="no"
208
209     for target in $target_list; do
210         case $target in
211             *-$ARCH)
212             :
213             ;;
214             *)
215             continue
216             ;;
217         esac
218         case $target in
219             mol-ppc)
220             mol="yes"
221             ;;
222             briq-ppc)
223             briq="yes"
224             ;;
225             pearpc-ppc)
226             pearpc="yes"
227             ;;
228             builtin-ppc|qemu-ppc|builtin-ppc64|qemu-ppc64)
229             qemu="yes"
230             ;;
231             xbox-x86)
232             xbox="yes"
233             ;;
234             builtin-sparc32)
235             builtin="yes"
236             qemu="yes"
237             ;;
238             builtin-sparc64)
239             builtin="yes"
240             qemu="yes"
241             ;;
242             unix-*)
243             if [ "$ARCH" != "$HOSTARCH" ]; then
244                 # Can't cross compile Unix target
245                 continue
246             fi
247             unix="yes"
248             ;;
249             builtin-*)
250             builtin="yes"
251             ;;
252             plain-*)
253             plain="yes"
254             ;;
255         esac
256     done
257
258     case $ARCH in
259         amd64)
260         select_prefix x86_64
261         CFLAGS="-fno-builtin"
262         AS_FLAGS=
263         ;;
264
265         ppc)
266         select_prefix powerpc powerpc64
267         if [ "$unix" = "no" ]; then
268             # 604 cpu includes support for PReP as well as Mac
269             CFLAGS="-m32 -mcpu=604 -msoft-float -fno-builtin-bcopy -fno-builtin-log2"
270             AS_FLAGS="-m32"
271         else
272             CFLAGS="-fno-builtin"
273             AS_FLAGS=
274         fi
275         ;;
276
277         ppc64)
278         select_prefix powerpc64
279
280         # 970 cpu is used in all 64-bit Macs but disable altivec
281         CFLAGS="-mcpu=970 -mno-altivec -Wa,-a64 -m64 -msoft-float -fno-builtin"
282         AS_FLAGS="-Wa,-a64"
283         ;;
284
285         sparc32)
286         select_prefix sparc sparc64
287         CFLAGS="-Wa,-xarch=v8 -Wa,-32 -m32 -mcpu=supersparc -fno-builtin"
288         AS_FLAGS="-Wa,-xarch=v8 -Wa,-32"
289         ;;
290
291         sparc64)
292         select_prefix sparc64
293         CFLAGS="-Wa,-xarch=v9b -Wa,-64 -m64 -mcpu=ultrasparc -mcmodel=medany -fno-builtin"
294         AS_FLAGS="-Wa,-xarch=v9b -Wa,-64"
295         ;;
296
297         x86)
298         select_prefix i486
299         CFLAGS="-fno-builtin -m32"
300         AS_FLAGS="-Wa,-32"
301         ;;
302     esac
303     if [ "$ARCH" != "$HOSTARCH" -o `uname -s` = "Darwin" ]; then
304         cross="yes"
305     fi
306     crosscflags $HOSTARCH $ARCH
307     OBJDIR=$BUILDDIR/obj-$ARCH
308     ODIRS="$ODIRS $OBJDIR"
309
310     printf "Initializing build tree $OBJDIR..."
311     rm -rf "$OBJDIR"
312     mkdir "$OBJDIR"
313     mkdir -p $OBJDIR/target
314     mkdir -p $OBJDIR/target/include
315     mkdir -p $OBJDIR/target/arch
316     mkdir -p $OBJDIR/target/arch/unix
317     mkdir -p $OBJDIR/target/arch/$ARCH
318     mkdir -p $OBJDIR/target/libgcc
319     mkdir -p $OBJDIR/target/kernel
320     mkdir -p $OBJDIR/target/libopenbios
321     mkdir -p $OBJDIR/target/packages
322     mkdir -p $OBJDIR/target/fs
323     mkdir -p $OBJDIR/target/fs/grubfs
324     mkdir -p $OBJDIR/target/fs/hfs
325     mkdir -p $OBJDIR/target/fs/hfsplus
326     mkdir -p $OBJDIR/target/fs/iso9660
327     mkdir -p $OBJDIR/target/fs/ext2
328     mkdir -p $OBJDIR/target/drivers
329     mkdir -p $OBJDIR/target/libc
330     mkdir -p $OBJDIR/host/include
331     mkdir -p $OBJDIR/host/kernel
332     mkdir -p $OBJDIR/forth
333     ln -s  $SRCDIR/include/arch/$BASEARCH $OBJDIR/target/include/asm
334     #compile the host binary with target settings instead
335     #ln -s $SRCDIR/include/arch/$HOSTARCH $OBJDIR/host/include/asm
336     if [ "$mol" = "yes" ]; then
337         printf "\nUsing MOL path $MOLPATH...\n"
338         mkdir -p $OBJDIR/target/arch/ppc/mol
339         ln -s $MOLPATH/src/shared/osi_calls.h $OBJDIR/target/include/
340         ln -s $MOLPATH/src/shared/osi.h $OBJDIR/target/include/
341         ln -s $MOLPATH/src/shared/prom.h $OBJDIR/target/include/
342         ln -s $MOLPATH/src/include/boothelper_sh.h $OBJDIR/target/include/
343         ln -s $MOLPATH/src/include/video_sh.h $OBJDIR/target/include/
344         ln -s $MOLPATH/src/include/pseudofs_sh.h $OBJDIR/target/include/
345         ln -s $MOLPATH/src/include/kbd_sh.h $OBJDIR/target/include/
346         ln -s $MOLPATH/src/drivers/disk/include/scsi_sh.h $OBJDIR/target/include/
347         ln -s $MOLPATH/src/drivers/disk/include/ablk_sh.h $OBJDIR/target/include/
348     fi
349     if [ "$briq" = "yes" ]; then
350         mkdir -p $OBJDIR/target/arch/ppc/briq
351     fi
352     if [ "$pearpc" = "yes" ]; then
353         mkdir -p $OBJDIR/target/arch/ppc/pearpc
354     fi
355     if [ "$qemu" = "yes" ]; then
356         mkdir -p $OBJDIR/target/arch/ppc/qemu
357     fi
358     if [ "$xbox" = "yes" ]; then
359         mkdir -p $OBJDIR/target/arch/x86/xbox
360     fi
361     echo "ok."
362
363     ODIR=$OBJDIR
364
365     printf "Creating target config.mak..."
366     echo "ARCH=$ARCH" > $ODIR/config.mak
367     if [ "$cross" = "yes" ]; then
368         echo "TARGET=$TARGET" >> $ODIR/config.mak
369     fi
370     echo "CFLAGS=$CFLAGS" >> $ODIR/config.mak
371     echo "AS_FLAGS=$AS_FLAGS" >> $ODIR/config.mak
372     echo "HOSTARCH?=$HOSTARCH" >> $ODIR/config.mak
373     echo "CROSSCFLAGS=$CROSSCFLAGS" >> $ODIR/config.mak
374     echo "VERSION=\"$VERSION\"" >> $ODIR/config.mak
375     echo "SRCDIR=$SRCDIR" >> $ODIR/config.mak
376     echo "ok."
377
378     printf "Creating target rules.mak..."
379     ln -s $SRCDIR/config/xml/rules.xml $ODIR/rules.xml
380     echo "<?xml version=\"1.0\"?><config>" > $ODIR/config.xml
381     # Generic
382     config_set_boolean CONFIG_$ARCH >> $ODIR/config.xml
383     if [ "$BASEARCH" != "$ARCH" ]; then
384         config_set_boolean CONFIG_$BASEARCH >> $ODIR/config.xml
385     fi
386     if [ "$mol" = "yes" ]; then
387         config_set_boolean CONFIG_MOL >> $ODIR/config.xml
388     fi
389     if [ "$briq" = "yes" ]; then
390         config_set_boolean CONFIG_BRIQ >> $ODIR/config.xml
391     fi
392     if [ "$pearpc" = "yes" ]; then
393         config_set_boolean CONFIG_PEARPC >> $ODIR/config.xml
394     fi
395     if [ "$qemu" = "yes" ]; then
396         config_set_boolean CONFIG_QEMU >> $ODIR/config.xml
397     fi
398     if [ "$xbox" = "yes" ]; then
399         config_set_boolean CONFIG_XBOX >> $ODIR/config.xml
400     fi
401     if [ "$targetbigendian" = "yes" ]; then
402         config_set_boolean CONFIG_BIG_ENDIAN >> $ODIR/config.xml
403     else
404         config_set_boolean CONFIG_LITTLE_ENDIAN >> $ODIR/config.xml
405     fi
406     # Kernel binaries
407     if [ "$plain" = "yes" ]; then
408         config_set_boolean CONFIG_IMAGE_ELF >> $ODIR/config.xml
409     fi
410     if [ "$builtin" = "yes" ]; then
411         config_set_boolean CONFIG_IMAGE_ELF_EMBEDDED >> $ODIR/config.xml
412     fi
413     # Build hosted Unix binary?
414     if [ "$unix" = "yes" ]; then
415         config_set_boolean CONFIG_HOST_UNIX >> $ODIR/config.xml
416         #config_set_boolean CONFIG_UNIX_QT >> $ODIR/config.xml
417         #config_set_boolean CONFIG_PLUGINS >> $ODIR/config.xml
418     fi
419     cat $SRCDIR/config/examples/${ARCH}_config.xml >> $ODIR/config.xml
420
421     cd $ODIR
422     echo "</config>" >> $ODIR/config.xml
423     ln -s $SRCDIR/Makefile.target $ODIR/Makefile
424     xsltproc $SRCDIR/config/xml/xinclude.xsl $SRCDIR/build.xml > $ODIR/build-full.xml
425     xsltproc $SRCDIR/config/xml/makefile.xsl $ODIR/build-full.xml > $ODIR/rules.mak
426     echo "ok."
427     printf "Creating config files..."
428     xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml > $ODIR/host/include/autoconf.h
429     xsltproc $SRCDIR/config/xml/config-c.xsl $ODIR/config.xml > $ODIR/target/include/autoconf.h
430     xsltproc $SRCDIR/config/xml/config-forth.xsl $ODIR/config.xml > $ODIR/forth/config.fs
431     echo "ok."
432
433     cd $BUILDDIR
434 done
435
436 if [ "$SRCDIR" != "$BUILDDIR" ]; then
437     ln -s $SRCDIR/Makefile $BUILDDIR
438 fi
439
440 echo "ODIRS=$ODIRS" >> $BUILDDIR/config-host.mak
441 echo "TARGETS=$arch_list" >> $BUILDDIR/config-host.mak