buildgcc: don't download python and expat if disabled
[coreboot.git] / util / crossgcc / buildgcc
1 #!/bin/sh
2 #
3 # Copyright (C) 2008-2010 by coresystems GmbH
4 # written by Patrick Georgi <patrick.georgi@coresystems.de> and
5 #            Stefan Reinauer <stefan.reinauer@coresystems.de>
6 #
7 # Copyright (C) 2011 by Sage Electronic Engineering
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA
21 #
22
23 CROSSGCC_DATE="November 1st, 2011"
24 CROSSGCC_VERSION="1.07"
25
26 # default settings
27 TARGETDIR=`pwd`/xgcc
28 TARGETARCH=i386-elf
29 DESTDIR=
30
31 # version numbers
32 GMP_VERSION=5.0.2
33 MPFR_VERSION=3.1.0
34 MPC_VERSION=0.9
35 LIBELF_VERSION=0.8.13
36 GCC_VERSION=4.6.2
37 GCC_AUTOCONF_VERSION=2.64
38 BINUTILS_VERSION=2.21.1
39 GDB_VERSION=7.3.1
40 W32API_VERSION=3.17-2
41 W32API_VERSION_SHORT=3.17
42 MINGWRT_VERSION=3.18
43 IASL_VERSION=20110922
44 PYTHON_VERSION=2.7.2
45 EXPAT_VERSION=2.0.1
46
47 # archive locations
48 GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2"
49 MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2"
50 MPC_ARCHIVE="http://www.multiprecision.org/mpc/download/mpc-${MPC_VERSION}.tar.gz"
51 LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
52 GCC_ARCHIVE="ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2"
53 BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
54 GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2"
55 W32API_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-${W32API_VERSION_SHORT}/w32api-${W32API_VERSION}-mingw32-src.tar.lzma"
56 MINGWRT_ARCHIVE="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-${MINGWRT_VERSION}/mingwrt-${MINGWRT_VERSION}-mingw32-src.tar.gz"
57 IASL_ARCHIVE="http://www.acpica.org/download/acpica-unix-${IASL_VERSION}.tar.gz"
58 PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.bz2"
59 EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
60
61 GMP_DIR="gmp-${GMP_VERSION}"
62 MPFR_DIR="mpfr-${MPFR_VERSION}"
63 MPC_DIR="mpc-${MPC_VERSION}"
64 LIBELF_DIR="libelf-${LIBELF_VERSION}"
65 GCC_DIR="gcc-${GCC_VERSION}"
66 BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
67 GDB_DIR="gdb-${GDB_VERSION}"
68 W32API_DIR="w32api-${W32API_VERSION}-mingw32"
69 MINGWRT_DIR="mingwrt-${MINGWRT_VERSION}-mingw32"
70 IASL_DIR="acpica-unix-${IASL_VERSION}"
71 PYTHON_DIR="Python-${PYTHON_VERSION}"
72 EXPAT_DIR="expat-${EXPAT_VERSION}"
73
74 SAVETEMPS=0
75 SKIPGDB=1
76 SKIPPYTHON=1
77
78 red='\033[0;31m'
79 RED='\033[1;31m'
80 green='\033[0;32m'
81 GREEN='\033[1;32m'
82 blue='\033[0;34m'
83 BLUE='\033[1;34m'
84 cyan='\033[0;36m'
85 CYAN='\033[1;36m'
86 NC='\033[0m' # No Color
87
88 searchgnu()
89 {
90         # $1 short name
91         # result: GNU version of that tool on stdout
92         #         or no output if no GNU version was found
93         for i in "$1" "g$1" "gnu$1"; do
94                 if test -x "`which $i 2>/dev/null`"; then
95                         if test `$i --version 2>/dev/null |grep -c GNU` \
96                             -gt 0; then
97                                 echo $i
98                                 return
99                         fi
100                 fi
101         done
102         printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
103         exit 1
104 }
105
106 TAR=`searchgnu tar` || exit $?
107 PATCH=`searchgnu patch` || exit $?
108 MAKE=`searchgnu make` || exit $?
109
110 cleanup()
111 {
112         printf "Cleaning up temporary files... "
113         rm -rf build-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
114         rm -rf gdb-* w32api-* mingwrt-* acpica-* python-* expat-*
115         printf "${green}ok${NC}\n"
116 }
117
118 myhelp()
119 {
120         printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
121         printf "       $0 [-V|--version]\n"
122         printf "       $0 [-h|--help]\n\n"
123
124         printf "Options:\n"
125         printf "    [-V|--version]                print version number and exit\n"
126         printf "    [-h|--help]                   print this help and exit\n"
127         printf "    [-c|--clean]                  remove temporary files before build\n"
128         printf "    [-t|--savetemps]              don't remove temporary files after build\n"
129         printf "    [-j|--jobs <num>]             run <num> jobs in parallel in make\n"
130         printf "    [-p|--platform <platform>]    target platform to build cross compiler for\n"
131         printf "                                  (defaults to $TARGETARCH)\n"
132         printf "    [-d|--directory <target dir>] target directory to install cross compiler to\n"
133         printf "                                  (defaults to $TARGETDIR)\n\n"
134         printf "    [-D|--destdir <dest dir>]     destination directory to install cross compiler to\n"
135         printf "                                  (for RPM builds, default unset)\n"
136         printf "    [-G|--gdb]                    build GNU debugger\n"
137         printf "    [-S|--scripting]              build scripting support for GDB\n\n"
138 }
139
140 myversion()
141 {
142         # version tag is always printed, so just print the license here
143
144         cat << EOF
145 Copyright (C) 2008-2010 by coresystems GmbH
146 Copyright (C) 2011 by Sage Electronic Engineering
147
148 This program is free software; you can redistribute it and/or modify
149 it under the terms of the GNU General Public License as published by
150 the Free Software Foundation; version 2 of the License.
151
152 This program is distributed in the hope that it will be useful,
153 but WITHOUT ANY WARRANTY; without even the implied warranty of
154 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155 GNU General Public License for more details.
156
157 EOF
158 }
159
160 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
161
162 # Look if we have getopt. If not, build it.
163 export PATH=$PATH:.
164 getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
165
166 # parse parameters.. try to find out whether we're running GNU getopt
167 getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
168 if [ "${getoptbrand}" = "getopt" ]; then
169         # Detected GNU getopt that supports long options.
170         args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb Vhcd:p:j:D:tG -- "$@"`
171         eval set "$args"
172 else
173         # Detected non-GNU getopt
174         args=`getopt Vhcd:p:j:D:tG $*`
175         set -- $args
176 fi
177
178 if [ $? != 0 ]; then
179         myhelp
180         exit 1
181 fi
182
183 while true ; do
184         case "$1" in
185                 -V|--version)   shift; myversion; exit 0;;
186                 -h|--help)      shift; myhelp; exit 0;;
187                 -c|--clean)     shift; cleanup;;
188                 -t|--savetemps) shift; SAVETEMPS=1;;
189                 -d|--directory) shift; TARGETDIR="$1"; shift;;
190                 -p|--platform)  shift; TARGETARCH="$1"; shift;;
191                 -D|--destdir)   shift; DESTDIR="$1"; shift;;
192                 -j|--jobs)      shift; JOBS="-j $1"; shift;;
193                 -G|--gdb)       shift; SKIPGDB=0;;
194                 -S|--scripting) shift; SKIPPYTHON=0;;
195                 --)             shift; break;;
196                 -*)             printf "Invalid option\n\n"; myhelp; exit 1;;
197                 *)              break;;
198         esac
199 done
200
201 GDB_PACKAGE="GDB"
202 PYTHON_PACKAGE="PYTHON"
203 EXPAT_PACKAGE="EXPAT"
204 if [ $SKIPGDB -eq 1 ]; then
205         printf "Will skip GDB ... ${green}ok${NC}\n"
206         GDB_ARCHIVE=""
207         GDB_PACKAGE=""
208         if [ $SKIPPYTHON -eq 0 ]; then
209                 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
210                 SKIPPYTHON=1
211         fi
212 fi
213 if [ $SKIPPYTHON -eq 1 ]; then
214         PYTHON_ARCHIVE=""
215         PYTHON_PACKAGE=""
216         EXPAT_ARCHIVE=""
217         EXPAT_PACKAGE=""
218 fi
219
220 MINGW_ARCHIVES=""
221 if [ "$TARGETARCH" = "i386-mingw32" ]; then
222         MINGW_ARCHIVES="$W32API_ARCHIVE $MINGWRT_ARCHIVE"
223 fi
224
225 # coreboot does not like the GOLD linker
226 # USE_GOLD="--enable-gold"
227 USE_GOLD=""
228 GCC_OPTIONS="--enable-lto"
229
230 if [ ${GCC_VERSION} = "trunk" ]; then
231   if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
232     printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
233     mkdir -p tarballs/.tmp
234     cd tarballs/.tmp
235     rm -rf gcc-${GCC_VERSION}
236     svn export -q svn://gcc.gnu.org/svn/gcc/trunk gcc-${GCC_VERSION}
237     printf "done. Now creating tar ball...\n"
238     tar cjf ../gcc-core-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}
239     printf "done. Now cleaning up...\n"
240     cd ..
241     rm -rf .tmp
242     cd ..
243     printf "done.\n"
244   fi
245 fi
246
247 printf "Downloading tar balls ... \n"
248 mkdir -p tarballs
249 for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE  \
250             $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE $MINGW_ARCHIVES \
251             $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
252         FILE=`basename $ARCHIVE`
253         printf " * $FILE "
254         test -f tarballs/$FILE && printf "(cached)" || (
255                 printf "(downloading)"
256                 cd tarballs
257                 wget -q $ARCHIVE
258         )
259         test -f tarballs/$FILE || \
260                 printf "\n${RED}Failed to download $FILE.${red}\n"
261         test -f tarballs/$FILE || exit 1
262         printf "\n"
263 done
264 printf "Downloaded tar balls ... "
265 printf "${green}ok${NC}\n"
266
267 MINGW_PACKAGES=""
268 if [ "$TARGETARCH" = "i386-mingw32" ]; then
269         MINGW_PACKAGES="W32API MINGWRT"
270 fi
271
272 printf "Unpacking and patching ... \n"
273 for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
274             $EXPAT_PACKAGE $GDB_PACKAGE $MINGW_PACKAGES IASL; do
275         archive=$PACKAGE"_ARCHIVE"
276         archive="`eval echo '$'$archive`"
277         dir=$PACKAGE"_DIR"
278         dir="`eval echo '$'${dir}`"
279         test -d ${dir} || (
280                 printf " * `basename $archive`\n"
281                 FLAGS=zxf
282                 suffix=`echo $archive | sed 's,.*\.,,'`
283                 test "$suffix" = "gz" && FLAGS=zxf
284                 test "$suffix" = "bz2" && FLAGS=jxf
285                 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
286                 $TAR $FLAGS tarballs/`basename $archive`
287                 for patch in patches/${dir}_*.patch; do
288                         test -r $patch || continue
289                         printf "   o `basename $patch`\n"
290                         $PATCH -s -N -p0 < `echo $patch` || \
291                                 printf "\n${RED}Failed $patch.${red}\n"
292                 done
293         )
294 done
295 printf "Unpacked and patched ... "
296 printf "${green}ok${NC}\n"
297
298 if [ "$TARGETARCH" = "i386-mingw32" ]; then
299         mkdir -p $TARGETDIR/i386-mingw32/sys-include
300         mv $MINGWRT_DIR/include/* $W32API_DIR/include/* \
301                                   $TARGETDIR/i386-mingw32/sys-include
302 fi
303
304 CC=cc
305 if [ `uname` = "Darwin" ]; then
306         #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
307
308         # generally the OS X compiler can create x64 binaries.
309         # Per default it generated i386 binaries in 10.5 and x64
310         # binaries in 10.6 (even if the kernel is 32bit)
311         # For some weird reason, 10.5 autodetects an ABI=64 though
312         # so we're setting the ABI explicitly here.
313         if [ `sysctl -n hw.optional.x86_64` -eq 1 ]; then
314                 OPTIONS="ABI=64"
315         else
316                 OPTIONS="ABI=32"
317         fi
318
319         # In Xcode 4 the default compiler was switched to gcc-llvm.
320         # However, this compiler fails to compile gcc 4.6.x. As a
321         # workaround it's possible to compile gcc with gcc-4.2 or
322         # clang.
323         if $CC -v 2>&1 | grep -q LLVM; then
324                 CC=clang
325         fi
326 fi
327
328 mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
329                 build-gcc build-python build-expat
330 if [ $SKIPGDB -eq 0 ]; then
331         mkdir -p build-gdb
332 fi
333 if [ -f build-gmp/.success ]; then
334         printf "Skipping GMP as it is already built\n"
335 else
336 printf "Building GMP ${GMP_VERSION} ... "
337 (
338         cd build-gmp
339         rm -f .failed
340         CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
341                 || touch .failed
342         $MAKE $JOBS || touch .failed
343         $MAKE install DESTDIR=$DESTDIR || touch .failed
344         if [ ! -f .failed ]; then touch .success; fi
345 ) > build-gmp/crossgcc-build.log 2>&1
346 test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || \
347         printf "${green}ok${NC}\n"
348 test -r build-gmp/.failed && exit 1
349 fi
350
351 #if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
352 #       # create compat link
353 #       ln -s $DESTDIR$TARGETDIR $TARGETDIR
354 #fi
355
356 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
357 # as GCC 4.6.x fails if it's there.
358 HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
359             sed s,-pedantic,,`
360
361 if [ -f build-mpfr/.success ]; then
362         printf "Skipping MPFR as it is already built\n"
363 else
364 printf "Building MPFR ${MPFR_VERSION} ... "
365 (
366         test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
367         cd build-mpfr
368         rm -f .failed
369         CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
370                 --infodir=$TARGETDIR/info \
371                 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
372                 touch .failed
373         $MAKE $JOBS || touch .failed
374         $MAKE install DESTDIR=$DESTDIR || touch .failed
375
376         # work around build problem of libgmp.la
377         if [ "$DESTDIR" != "" ]; then
378             perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
379         fi
380
381         if [ ! -f .failed ]; then touch .success; fi
382 ) > build-mpfr/crossgcc-build.log 2>&1
383 test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || \
384              printf "${green}ok${NC}\n"
385 test -r build-mpfr/.failed && exit 1
386 fi
387
388 if [ -f build-mpc/.success ]; then
389         printf "Skipping MPC as it is already built\n"
390 else
391 printf "Building MPC ${MPC_VERSION} ... "
392 (
393         #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
394         cd build-mpc
395         rm -f .failed
396         CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
397                 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
398                 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
399                 touch .failed
400         $MAKE $JOBS || touch .failed
401         $MAKE install DESTDIR=$DESTDIR || touch .failed
402
403         if [ ! -f .failed ]; then touch .success; fi
404 ) > build-mpc/crossgcc-build.log 2>&1
405 test -r build-mpc/.failed && printf "${RED}failed${NC}\n" || \
406              printf "${green}ok${NC}\n"
407 test -r build-mpc/.failed && exit 1
408 fi
409
410 if [ -f build-libelf/.success ]; then
411         printf "Skipping libelf as it is already built\n"
412 else
413 printf "Building libelf ${LIBELF_VERSION} ... "
414 (
415         cd build-libelf
416         rm -f .failed
417         echo "$HOSTCFLAGS"
418         CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
419         ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
420                 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
421         $MAKE $JOBS || touch .failed
422         $MAKE install DESTDIR=$DESTDIR || touch .failed
423
424         if [ ! -f .failed ]; then touch .success; fi
425 ) > build-libelf/crossgcc-build.log 2>&1
426 test -r build-libelf/.failed && printf "${RED}failed${NC}\n" || \
427              printf "${green}ok${NC}\n"
428 test -r build-libelf/.failed && exit 1
429 fi
430
431 if [ -f build-binutils/.success ]; then
432         printf "Skipping binutils as it is already built\n"
433 else
434 printf "Building binutils ${BINUTILS_VERSION} ... "
435 (
436         # What a pain: binutils don't come with configure
437         # script anymore. Create it:
438         cd binutils-${BINUTILS_VERSION}/
439         autoconf
440         cd ..
441         # Now build binutils
442         cd build-binutils
443         rm -f .failed
444         CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
445                 --target=${TARGETARCH} --disable-werror --disable-nls \
446                 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
447         $MAKE $JOBS || touch .failed
448         $MAKE install DESTDIR=$DESTDIR || touch .failed
449         if [ ! -f .failed ]; then touch .success; fi
450 ) > build-binutils/crossgcc-build.log 2>&1
451 test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || \
452              printf "${green}ok${NC}\n"
453 test -r build-binutils/.failed && exit 1
454 fi
455
456 if [ -f build-gcc/.success ]; then
457         printf "Skipping GCC as it is already built\n"
458 else
459 printf "Building GCC ${GCC_VERSION} ... "
460 (
461         # Even worse than binutils: GCC does not come with configure
462         # script anymore, but also enforces an obsolete autoconf version
463         # to create it. This is a poster child of how autotools help make
464         # software portable.
465         cd gcc-${GCC_VERSION}
466         sed '/dnl Ensure exactly this Autoconf version is used/d' \
467                 config/override.m4 > config/override.m4.new
468         autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
469         sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
470                 config/override.m4.new > config/override.m4
471         autoconf
472         cd ..
473         # Now, finally, we can build gcc:
474         cd build-gcc
475         export PATH=$PATH:$DESTDIR$TARGETDIR/bin
476         rm -f .failed
477         # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
478         # both target and host object files. This is pretty misdesigned.
479         # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
480         # but it does not seem to work properly. At least the host library
481         # libiberty is not compiled with CFLAGS_FOR_BUILD.
482         CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
483                 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
484                 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
485                 --target=${TARGETARCH} --disable-werror --disable-shared \
486                 --disable-libssp --disable-bootstrap --disable-nls \
487                 --disable-libquadmath \
488                 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
489                 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
490                 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
491                 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
492                 || touch .failed
493         $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
494         $MAKE install DESTDIR=$DESTDIR || touch .failed
495         if [ ! -f .failed ]; then touch .success; fi
496 ) > build-gcc/crossgcc-build.log 2>&1
497 test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || \
498              printf "${green}ok${NC}\n"
499 test -r build-gcc/.failed && exit 1
500 fi
501
502 if [ -f build-expat/.success ]; then
503         printf "Skipping Expat as it is already built\n"
504 elif [ $SKIPPYTHON -eq 1 ]; then
505         printf "Skipping Expat (Python scripting not enabled)\n"
506 else
507 printf "Building Expat ${EXPAT_VERSION} ... "
508 (
509         cd build-expat
510         export PATH=$PATH:$DESTDIR$TARGETDIR/bin
511         rm -f .failed
512         CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
513                 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
514         $MAKE || touch .failed
515         $MAKE install DESTDIR=$DESTDIR || touch .failed
516         if [ ! -f .failed ]; then touch .success; fi
517 ) &> build-expat/crossgcc-build.log
518 test -r build-expat/.failed && printf "${RED}failed${NC}\n" || \
519              printf "${green}ok${NC}\n"
520 test -r build-expat/.failed && exit 1
521 fi
522
523
524 if [ -f build-python/.success ]; then
525         printf "Skipping Python as it is already built\n"
526 elif [ $SKIPPYTHON -eq 1 ]; then
527         printf "Skipping Python (Python scripting not enabled)\n"
528 else
529 printf "Building Python ${PYTHON_VERSION} ... "
530 (
531         cd build-python
532         export PATH=$PATH:$DESTDIR$TARGETDIR/bin
533         rm -f .failed
534         CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
535                 --target=${TARGETARCH} || touch .failed
536         $MAKE $JOBS || touch .failed
537         $MAKE install DESTDIR=$DESTDIR || touch .failed
538         if [ ! -f .failed ]; then touch .success; fi
539 ) &> build-gdb/crossgcc-build.log
540 test -r build-python/.failed && printf "${RED}failed${NC}\n" || \
541              printf "${green}ok${NC}\n"
542 test -r build-python/.failed && exit 1
543 fi
544
545
546 if [ -f build-gdb/.success ]; then
547         printf "Skipping GDB as it is already built\n"
548 elif [ $SKIPGDB -eq 1 ]; then
549         printf "Skipping GDB (GDB support not enabled)\n"
550 else
551 printf "Building GDB ${GDB_VERSION} ... "
552 (
553         cd build-gdb
554         export PATH=$PATH:$DESTDIR$TARGETDIR/bin
555         export PYTHONHOME=$DESTDIR$TARGETDIR
556         rm -f .failed
557         LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
558                  -lpthread -ldl -lutil" \
559         CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
560         ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
561                 --target=${TARGETARCH} --disable-werror --disable-nls
562         $MAKE $JOBS || touch .failed
563         $MAKE install DESTDIR=$DESTDIR || touch .failed
564         if [ ! -f .failed ]; then touch .success; fi
565 ) > build-gdb/crossgcc-build.log 2>&1
566 test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || \
567              printf "${green}ok${NC}\n"
568 test -r build-gdb/.failed && exit 1
569 fi
570
571 if [ -f $IASL_DIR/compiler/.success ]; then
572         printf "Skipping IASL as it is already built\n"
573 else
574 printf "Building IASL ${IASL_VERSION} ... "
575 (
576         cd $IASL_DIR/compiler
577         export PATH=$PATH:$DESTDIR$TARGETDIR/bin
578         rm -f .failed
579         CFLAGS="$HOSTCFLAGS"
580         $MAKE CC="$CC" || touch .failed
581         rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
582         cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
583         if [ ! -f .failed ]; then touch .success; fi
584 ) > $IASL_DIR/compiler/crossgcc-build.log 2>&1
585 test -r $IASL_DIR/compiler/.failed && printf "${RED}failed${NC}\n" || \
586              printf "${green}ok${NC}\n"
587 test -r $IASL_DIR/compiler/.failed && exit 1
588 fi
589
590 if [ $SAVETEMPS -eq 0 ]; then
591         printf "Cleaning up... "
592         rm -rf ${GMP_DIR} build-gmp
593         rm -rf ${MPFR_DIR} build-mpfr
594         rm -rf ${MPC_DIR} build-mpc
595         rm -rf ${LIBELF_DIR} build-libelf
596         rm -rf ${BINUTILS_DIR} build-binutils
597         rm -rf ${GCC_DIR} build-gcc
598         rm -rf ${GDB_DIR} build-gdb
599         rm -rf ${EXPAT_DIR} build-expat
600         rm -rf ${PYTHON_DIR} build-python
601         rm -rf ${IASL_DIR}
602         printf "${green}ok${NC}\n"
603 else
604         printf "Leaving temporary files around... ${green}ok${NC}\n"
605 fi
606
607 printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"
608
609