crossgcc: Unify tool tests, add check for g++ or clang
[coreboot.git] / util / crossgcc / buildgcc
blob7221b8326ad5dfb1487db4c5351bdb7954010393
1 #!/bin/sh
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>
7 # Copyright (C) 2011 by Sage Electronic Engineering
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.
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.
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
23 CROSSGCC_DATE="March 8th, 2015"
24 CROSSGCC_VERSION="1.27"
26 # default settings
27 TARGETDIR=`pwd`/xgcc
28 TARGETARCH=i386-elf
29 DESTDIR=
31 # version numbers
32 GMP_VERSION=6.0.0
33 MPFR_VERSION=3.1.2
34 MPC_VERSION=1.0.3
35 LIBELF_VERSION=0.8.13
36 GCC_VERSION=4.9.2
37 GCC_AUTOCONF_VERSION=2.69
38 BINUTILS_VERSION=2.25
39 GDB_VERSION=7.9
40 IASL_VERSION=20150204
41 PYTHON_VERSION=3.4.3
42 EXPAT_VERSION=2.1.0
44 # archive locations
45 GMP_ARCHIVE="http://ftpmirror.gnu.org/gmp/gmp-${GMP_VERSION}a.tar.bz2"
46 MPFR_ARCHIVE="http://ftpmirror.gnu.org/mpfr/mpfr-${MPFR_VERSION}.tar.bz2"
47 MPC_ARCHIVE="http://ftpmirror.gnu.org/mpc/mpc-${MPC_VERSION}.tar.gz"
48 LIBELF_ARCHIVE="http://www.mr511.de/software/libelf-${LIBELF_VERSION}.tar.gz"
49 GCC_ARCHIVE="http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2"
50 BINUTILS_ARCHIVE="http://ftpmirror.gnu.org/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
51 GDB_ARCHIVE="http://ftpmirror.gnu.org/gdb/gdb-${GDB_VERSION}.tar.xz"
52 IASL_ARCHIVE="https://acpica.org/sites/acpica/files/acpica-unix-${IASL_VERSION}.tar.gz"
53 PYTHON_ARCHIVE="http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz"
54 EXPAT_ARCHIVE="http://downloads.sourceforge.net/sourceforge/expat/expat-${EXPAT_VERSION}.tar.gz"
56 GMP_DIR="gmp-${GMP_VERSION}"
57 MPFR_DIR="mpfr-${MPFR_VERSION}"
58 MPC_DIR="mpc-${MPC_VERSION}"
59 LIBELF_DIR="libelf-${LIBELF_VERSION}"
60 GCC_DIR="gcc-${GCC_VERSION}"
61 BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
62 GDB_DIR="gdb-${GDB_VERSION}"
63 IASL_DIR="acpica-unix-${IASL_VERSION}"
64 PYTHON_DIR="Python-${PYTHON_VERSION}"
65 EXPAT_DIR="expat-${EXPAT_VERSION}"
67 unset MAKELEVEL MAKEFLAGS
69 SAVETEMPS=0
70 SKIPGDB=1
71 SKIPPYTHON=1
73 red='\033[0;31m'
74 RED='\033[1;31m'
75 green='\033[0;32m'
76 GREEN='\033[1;32m'
77 blue='\033[0;34m'
78 BLUE='\033[1;34m'
79 cyan='\033[0;36m'
80 CYAN='\033[1;36m'
81 NC='\033[0m' # No Color
83 UNAME=`uname`
85 normalize_dirs()
87 mkdir -p $DESTDIR$TARGETDIR/lib
88 test -d $DESTDIR$TARGETDIR/lib32 && mv $DESTDIR$TARGETDIR/lib32/* $DESTDIR$TARGETDIR/lib
89 test -d $DESTDIR$TARGETDIR/lib64 && mv $DESTDIR$TARGETDIR/lib64/* $DESTDIR$TARGETDIR/lib
90 rmdir -p $DESTDIR$TARGETDIR/lib32 $DESTDIR$TARGETDIR/lib64
92 perl -pi -e "s,/lib32,/lib," $DESTDIR$TARGETDIR/lib/*.la
93 perl -pi -e "s,/lib64,/lib," $DESTDIR$TARGETDIR/lib/*.la
96 searchtool()
98 # $1 short name
99 # $2 search string
100 # $3 soft fail if set
101 # result: file name of that tool on stdout
102 # or no output if nothing suitable was found
103 search=GNU
104 if [ -n "$2" ]; then
105 search="$2"
107 for i in "$1" "g$1" "gnu$1"; do
108 if test -x "`which $i 2>/dev/null`"; then
109 if test `$i --version 2>/dev/null |grep -c "$search"` \
110 -gt 0; then
111 echo $i
112 return
115 done
116 # A workaround for OSX 10.9 and some BSDs, whose nongnu
117 # patch and tar also work.
118 if [ $UNAME = "Darwin" -o $UNAME = "FreeBSD" -o $UNAME = "NetBSD" ]; then
119 if [ "$1" = "patch" -o "$1" = "tar" ]; then
120 if test -x "`which $1 2>/dev/null`"; then
121 echo $1
122 return
126 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
127 [ -z "$3" ] && exit 1
128 false
131 TAR=`searchtool tar` || exit $?
132 PATCH=`searchtool patch` || exit $?
133 MAKE=`searchtool make` || exit $?
135 searchtool m4 > /dev/null
136 searchtool bison > /dev/null
137 searchtool flex flex > /dev/null
138 searchtool g++ "Free Software Foundation" nofail > /dev/null || \
139 searchtool clang "clang version"
141 cleanup()
143 printf "Cleaning up temporary files... "
144 rm -rf ${BUILDDIRPREFIX}-* combined gcc-* gmp-* mpfr-* mpc-* libelf-* binutils-*
145 rm -rf gdb-* acpica-* python-* expat-*
146 printf "${green}ok${NC}\n"
149 myhelp()
151 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-G] [-S]\n"
152 printf " $0 [-V|--version]\n"
153 printf " $0 [-h|--help]\n\n"
155 printf "Options:\n"
156 printf " [-V|--version] print version number and exit\n"
157 printf " [-h|--help] print this help and exit\n"
158 printf " [-c|--clean] remove temporary files before build\n"
159 printf " [-t|--savetemps] don't remove temporary files after build\n"
160 printf " [-y|--ccache] Use ccache when building cross compiler\n"
161 printf " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
162 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
163 printf " (defaults to $TARGETARCH)\n"
164 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
165 printf " (defaults to $TARGETDIR)\n\n"
166 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
167 printf " (for RPM builds, default unset)\n"
168 printf " [-G|--gdb] build GNU debugger\n"
169 printf " [-S|--scripting] build scripting support for GDB\n\n"
172 myversion()
174 # version tag is always printed, so just print the license here
176 cat << EOF
177 Copyright (C) 2008-2010 by coresystems GmbH
178 Copyright (C) 2011 by Sage Electronic Engineering
180 This program is free software; you can redistribute it and/or modify
181 it under the terms of the GNU General Public License as published by
182 the Free Software Foundation; version 2 of the License.
184 This program is distributed in the hope that it will be useful,
185 but WITHOUT ANY WARRANTY; without even the implied warranty of
186 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
187 GNU General Public License for more details.
192 printf "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
194 # Look if we have getopt. If not, build it.
195 export PATH=$PATH:.
196 getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
198 # parse parameters.. try to find out whether we're running GNU getopt
199 getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
200 if [ "${getoptbrand}" = "getopt" ]; then
201 # Detected GNU getopt that supports long options.
202 args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache Vhcd:p:j:D:tGy -- "$@"`
203 eval set "$args"
204 else
205 # Detected non-GNU getopt
206 args=`getopt Vhcd:p:j:D:tGy $*`
207 set -- $args
210 if [ $? != 0 ]; then
211 myhelp
212 exit 1
215 while true ; do
216 case "$1" in
217 -V|--version) shift; myversion; exit 0;;
218 -h|--help) shift; myhelp; exit 0;;
219 -c|--clean) shift; clean=1;;
220 -t|--savetemps) shift; SAVETEMPS=1;;
221 -d|--directory) shift; TARGETDIR="$1"; shift;;
222 -p|--platform) shift; TARGETARCH="$1"; shift;;
223 -D|--destdir) shift; DESTDIR="$1"; shift;;
224 -j|--jobs) shift; JOBS="-j $1"; shift;;
225 -G|--gdb) shift; SKIPGDB=0;;
226 -S|--scripting) shift; SKIPPYTHON=0;;
227 -y|--ccache) shift; USECCACHE=1;;
228 --) shift; break;;
229 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
230 *) break;;
231 esac
232 done
234 case "$TARGETARCH" in
235 i386-elf) ;;
236 i386-mingw32) ;;
237 mipsel-elf) ;;
238 riscv-elf) ;;
239 i386*) TARGETARCH=i386-elf;;
240 arm*) TARGETARCH=armv7-a-eabi;;
241 aarch64*) TARGETARCH=aarch64-elf;;
242 *) printf "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
243 esac
245 echo "Target arch is now $TARGETARCH"
246 BUILDDIRPREFIX=build-${TARGETARCH}
248 if [ "$clean" = "1" ]; then
249 cleanup
252 GDB_PACKAGE="GDB"
253 PYTHON_PACKAGE="PYTHON"
254 EXPAT_PACKAGE="EXPAT"
255 if [ $SKIPGDB -eq 1 ]; then
256 printf "Will skip GDB ... ${green}ok${NC}\n"
257 GDB_ARCHIVE=""
258 GDB_PACKAGE=""
259 if [ $SKIPPYTHON -eq 0 ]; then
260 printf "Python scripting needs GDB ... disabling ... ${green}ok${NC}\n"
261 SKIPPYTHON=1
264 if [ $SKIPPYTHON -eq 1 ]; then
265 PYTHON_ARCHIVE=""
266 PYTHON_PACKAGE=""
267 EXPAT_ARCHIVE=""
268 EXPAT_PACKAGE=""
271 # coreboot does not like the GOLD linker
272 # USE_GOLD="--enable-gold"
273 USE_GOLD=""
274 GCC_OPTIONS="--enable-lto"
276 printf "Downloading tar balls ... \n"
277 mkdir -p tarballs
278 for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $MPC_ARCHIVE $LIBELF_ARCHIVE \
279 $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE \
280 $IASL_ARCHIVE $PYTHON_ARCHIVE $EXPAT_ARCHIVE; do
281 FILE=`basename $ARCHIVE`
282 printf " * $FILE "
283 test -f tarballs/$FILE && printf "(cached)" || (
284 printf "(downloading)"
285 cd tarballs
286 wget --no-check-certificate -q $ARCHIVE
288 test -f tarballs/$FILE || \
289 printf "\n${RED}Failed to download $FILE.${NC}\n"
290 test -f tarballs/$FILE || exit 1
291 printf "\n"
292 done
293 printf "Downloaded tar balls ... "
294 printf "${green}ok${NC}\n"
296 printf "Unpacking and patching ... \n"
297 for PACKAGE in GMP MPFR MPC LIBELF GCC BINUTILS $PYTHON_PACKAGE \
298 $EXPAT_PACKAGE $GDB_PACKAGE IASL; do
299 archive=$PACKAGE"_ARCHIVE"
300 archive="`eval echo '$'$archive`"
301 dir=$PACKAGE"_DIR"
302 dir="`eval echo '$'${dir}`"
303 test -d ${dir} && test -f ${dir}/.unpack_success || (
304 printf " * `basename $archive`\n"
305 FLAGS=zxf
306 suffix=`echo $archive | sed 's,.*\.,,'`
307 test "$suffix" = "gz" && FLAGS=zxf
308 test "$suffix" = "bz2" && FLAGS=jxf
309 test "$suffix" = "xz" && FLAGS="--xz -xf"
310 test "$suffix" = "lzma" && FLAGS="--lzma -xf"
311 $TAR $FLAGS tarballs/`basename $archive`
312 for patch in patches/${dir}_*.patch; do
313 test -r $patch || continue
314 printf " o `basename $patch`\n"
315 $PATCH -s -N -p0 < `echo $patch` || \
316 printf "\n${RED}Failed $patch.${NC}\n"
317 done
318 touch ${dir}/.unpack_success
320 done
321 printf "Unpacked and patched ... "
322 printf "${green}ok${NC}\n"
324 CC=cc
325 if [ $UNAME = "Darwin" ]; then
326 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
328 # generally the OS X compiler can create x64 binaries.
329 # Per default it generated i386 binaries in 10.5 and x64
330 # binaries in 10.6 (even if the kernel is 32bit)
331 # For some weird reason, 10.5 autodetects an ABI=64 though
332 # so we're setting the ABI explicitly here.
333 if [ `sysctl -n hw.optional.x86_64 2>/dev/null` -eq 1 ] 2>/dev/null; then
334 OPTIONS="ABI=64"
335 else
336 OPTIONS="ABI=32"
339 # In Xcode 4.5.2 the default compiler is clang.
340 # However, this compiler fails to compile gcc 4.7.x. As a
341 # workaround it's possible to compile gcc with llvm-gcc.
342 if $CC -v 2>&1 | grep -q LLVM; then
343 CC=llvm-gcc
347 if [ "$USECCACHE" = 1 ]; then
348 CC="ccache $CC"
351 mkdir -p ${BUILDDIRPREFIX}-gmp ${BUILDDIRPREFIX}-mpfr ${BUILDDIRPREFIX}-mpc ${BUILDDIRPREFIX}-libelf ${BUILDDIRPREFIX}-binutils \
352 ${BUILDDIRPREFIX}-gcc ${BUILDDIRPREFIX}-python ${BUILDDIRPREFIX}-expat
354 mkdir -p $DESTDIR$TARGETDIR/bin
355 export PATH=$DESTDIR$TARGETDIR/bin:$PATH
357 if [ $SKIPGDB -eq 0 ]; then
358 mkdir -p ${BUILDDIRPREFIX}-gdb
360 if [ -f ${BUILDDIRPREFIX}-gmp/.success ]; then
361 printf "Skipping GMP as it is already built\n"
362 else
363 printf "Building GMP ${GMP_VERSION} ... "
365 cd ${BUILDDIRPREFIX}-gmp
366 rm -f .failed
367 CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
368 || touch .failed
369 $MAKE $JOBS || touch .failed
370 $MAKE install DESTDIR=$DESTDIR || touch .failed
372 normalize_dirs
374 if [ ! -f .failed ]; then touch .success; fi
375 ) > ${BUILDDIRPREFIX}-gmp/crossgcc-build.log 2>&1
376 test -r ${BUILDDIRPREFIX}-gmp/.failed && printf "${RED}failed${NC}\n" || \
377 printf "${green}ok${NC}\n"
378 test -r ${BUILDDIRPREFIX}-gmp/.failed && exit 1
381 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
382 # as GCC 4.6.x fails if it's there.
383 HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2 |\
384 sed s,-pedantic,,`
386 if [ -f ${BUILDDIRPREFIX}-mpfr/.success ]; then
387 printf "Skipping MPFR as it is already built\n"
388 else
389 printf "Building MPFR ${MPFR_VERSION} ... "
391 test $UNAME = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
392 cd ${BUILDDIRPREFIX}-mpfr
393 rm -f .failed
394 CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
395 --infodir=$TARGETDIR/info \
396 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
397 touch .failed
398 $MAKE $JOBS || touch .failed
399 $MAKE install DESTDIR=$DESTDIR || touch .failed
401 normalize_dirs
403 # work around build problem of libgmp.la
404 if [ "$DESTDIR" != "" ]; then
405 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
408 if [ ! -f .failed ]; then touch .success; fi
409 ) > ${BUILDDIRPREFIX}-mpfr/crossgcc-build.log 2>&1
410 test -r ${BUILDDIRPREFIX}-mpfr/.failed && printf "${RED}failed${NC}\n" || \
411 printf "${green}ok${NC}\n"
412 test -r ${BUILDDIRPREFIX}-mpfr/.failed && exit 1
415 if [ -f ${BUILDDIRPREFIX}-mpc/.success ]; then
416 printf "Skipping MPC as it is already built\n"
417 else
418 printf "Building MPC ${MPC_VERSION} ... "
420 cd ${BUILDDIRPREFIX}-mpc
421 rm -f .failed
422 CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
423 --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
424 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
425 touch .failed
426 $MAKE $JOBS || touch .failed
427 $MAKE install DESTDIR=$DESTDIR || touch .failed
429 normalize_dirs
431 if [ ! -f .failed ]; then touch .success; fi
432 ) > ${BUILDDIRPREFIX}-mpc/crossgcc-build.log 2>&1
433 test -r ${BUILDDIRPREFIX}-mpc/.failed && printf "${RED}failed${NC}\n" || \
434 printf "${green}ok${NC}\n"
435 test -r ${BUILDDIRPREFIX}-mpc/.failed && exit 1
438 if [ -f ${BUILDDIRPREFIX}-libelf/.success ]; then
439 printf "Skipping libelf as it is already built\n"
440 else
441 printf "Building libelf ${LIBELF_VERSION} ... "
443 cd ${BUILDDIRPREFIX}-libelf
444 rm -f .failed
445 echo "$HOSTCFLAGS"
446 CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
447 ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
448 --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
449 $MAKE $JOBS || touch .failed
450 $MAKE install prefix=$DESTDIR$TARGETDIR || touch .failed
452 normalize_dirs
454 if [ ! -f .failed ]; then touch .success; fi
455 ) > ${BUILDDIRPREFIX}-libelf/crossgcc-build.log 2>&1
456 test -r ${BUILDDIRPREFIX}-libelf/.failed && printf "${RED}failed${NC}\n" || \
457 printf "${green}ok${NC}\n"
458 test -r ${BUILDDIRPREFIX}-libelf/.failed && exit 1
461 if [ -f ${BUILDDIRPREFIX}-binutils/.success ]; then
462 printf "Skipping binutils as it is already built\n"
463 else
464 printf "Building binutils ${BINUTILS_VERSION} ... "
466 # What a pain: binutils don't come with configure
467 # script anymore. Create it:
468 cd binutils-${BINUTILS_VERSION}/
469 autoconf
470 cd ..
471 # Now build binutils
472 cd ${BUILDDIRPREFIX}-binutils
473 rm -f .failed
474 CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
475 --target=${TARGETARCH} --disable-werror --disable-nls \
476 $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
477 $MAKE $JOBS || touch .failed
478 $MAKE install DESTDIR=$DESTDIR || touch .failed
479 if [ ! -f .failed ]; then touch .success; fi
480 ) > ${BUILDDIRPREFIX}-binutils/crossgcc-build.log 2>&1
481 test -r ${BUILDDIRPREFIX}-binutils/.failed && printf "${RED}failed${NC}\n" || \
482 printf "${green}ok${NC}\n"
483 test -r ${BUILDDIRPREFIX}-binutils/.failed && exit 1
486 if [ -f ${BUILDDIRPREFIX}-gcc/.success ]; then
487 printf "Skipping GCC as it is already built\n"
488 else
489 printf "Building GCC ${GCC_VERSION} ... "
491 # Even worse than binutils: GCC does not come with configure
492 # script anymore, but also enforces an obsolete autoconf version
493 # to create it. This is a poster child of how autotools help make
494 # software portable.
495 cd gcc-${GCC_VERSION}
496 sed '/dnl Ensure exactly this Autoconf version is used/d' \
497 config/override.m4 > config/override.m4.new
498 autoconf_version=`autoconf -V | grep "autoconf" | tr ' ' '\n' | tail -1`
499 sed "s/${GCC_AUTOCONF_VERSION}/${autoconf_version}/g" \
500 config/override.m4.new > config/override.m4
501 autoconf
502 cd ..
503 # Now, finally, we can build gcc:
504 cd ${BUILDDIRPREFIX}-gcc
505 rm -f .failed
506 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
507 # both target and host object files. This is pretty misdesigned.
508 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
509 # but it does not seem to work properly. At least the host library
510 # libiberty is not compiled with CFLAGS_FOR_BUILD.
511 CC="$CC" CFLAGS_FOR_TARGET="-O2" CFLAGS="$HOSTCFLAGS" \
512 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
513 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
514 --target=${TARGETARCH} --disable-werror --disable-shared \
515 --disable-libssp --disable-bootstrap --disable-nls \
516 --disable-libquadmath --without-headers \
517 $GCC_OPTIONS --enable-languages="c" $USE_GOLD \
518 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
519 --with-mpc=$DESTDIR$TARGETDIR --with-libelf=$DESTDIR$TARGETDIR \
520 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION $CROSSGCC_DATE" \
521 || touch .failed
522 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc || touch .failed
523 $MAKE install-gcc DESTDIR=$DESTDIR || touch .failed
525 if [ "`echo $TARGETARCH | grep -c -- -mingw32`" -eq 0 ]; then
526 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc || touch .failed
527 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touch .failed
530 if [ ! -f .failed ]; then touch .success; fi
531 ) > ${BUILDDIRPREFIX}-gcc/crossgcc-build.log 2>&1
532 test -r ${BUILDDIRPREFIX}-gcc/.failed && printf "${RED}failed${NC}\n" || \
533 printf "${green}ok${NC}\n"
534 test -r ${BUILDDIRPREFIX}-gcc/.failed && exit 1
537 if [ -f ${BUILDDIRPREFIX}-expat/.success ]; then
538 printf "Skipping Expat as it is already built\n"
539 elif [ $SKIPPYTHON -eq 1 ]; then
540 printf "Skipping Expat (Python scripting not enabled)\n"
541 else
542 printf "Building Expat ${EXPAT_VERSION} ... "
544 cd ${BUILDDIRPREFIX}-expat
545 rm -f .failed
546 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
547 --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
548 $MAKE || touch .failed
549 $MAKE install DESTDIR=$DESTDIR || touch .failed
551 normalize_dirs
553 if [ ! -f .failed ]; then touch .success; fi
554 ) > ${BUILDDIRPREFIX}-expat/crossgcc-build.log 2>&1
555 test -r ${BUILDDIRPREFIX}-expat/.failed && printf "${RED}failed${NC}\n" || \
556 printf "${green}ok${NC}\n"
557 test -r ${BUILDDIRPREFIX}-expat/.failed && exit 1
561 if [ -f ${BUILDDIRPREFIX}-python/.success ]; then
562 printf "Skipping Python as it is already built\n"
563 elif [ $SKIPPYTHON -eq 1 ]; then
564 printf "Skipping Python (Python scripting not enabled)\n"
565 else
566 printf "Building Python ${PYTHON_VERSION} ... "
568 cd ${BUILDDIRPREFIX}-python
569 rm -f .failed
570 CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
571 --target=${TARGETARCH} || touch .failed
572 $MAKE $JOBS || touch .failed
573 $MAKE install DESTDIR=$DESTDIR || touch .failed
575 normalize_dirs
577 if [ ! -f .failed ]; then touch .success; fi
578 ) > ${BUILDDIRPREFIX}-python/crossgcc-build.log 2>&1
579 test -r ${BUILDDIRPREFIX}-python/.failed && printf "${RED}failed${NC}\n" || \
580 printf "${green}ok${NC}\n"
581 test -r ${BUILDDIRPREFIX}-python/.failed && exit 1
585 if [ -f ${BUILDDIRPREFIX}-gdb/.success ]; then
586 printf "Skipping GDB as it is already built\n"
587 elif [ $SKIPGDB -eq 1 ]; then
588 printf "Skipping GDB (GDB support not enabled)\n"
589 else
590 printf "Building GDB ${GDB_VERSION} ... "
592 cd ${BUILDDIRPREFIX}-gdb
593 export PYTHONHOME=$DESTDIR$TARGETDIR
594 rm -f .failed
595 LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
596 -lpthread -ldl -lutil" \
597 CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
598 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
599 --target=${TARGETARCH} --disable-werror --disable-nls
600 $MAKE $JOBS || touch .failed
601 $MAKE install DESTDIR=$DESTDIR || touch .failed
602 if [ ! -f .failed ]; then touch .success; fi
603 ) > ${BUILDDIRPREFIX}-gdb/crossgcc-build.log 2>&1
604 test -r ${BUILDDIRPREFIX}-gdb/.failed && printf "${RED}failed${NC}\n" || \
605 printf "${green}ok${NC}\n"
606 test -r ${BUILDDIRPREFIX}-gdb/.failed && exit 1
609 if [ -f $IASL_DIR/source/compiler/.success ]; then
610 printf "Skipping IASL as it is already built\n"
611 else
612 printf "Building IASL ${IASL_VERSION} ... "
614 cd $IASL_DIR/generate/unix
615 rm -f .failed
616 CFLAGS="$HOSTCFLAGS"
617 HOST="_LINUX"
618 test $UNAME = "Darwin" && HOST="_APPLE"
619 test $UNAME = "FreeBSD" && HOST="_FreeBSD"
620 test $UNAME = "Cygwin" && HOST="_CYGWIN"
621 HOST="$HOST" OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2" CFLAGS="$CFLAGS" $MAKE CC="$CC" iasl || touch .failed
622 rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
623 cp bin/iasl $DESTDIR$TARGETDIR/bin || touch .failed
624 if [ ! -f .failed ]; then touch .success; fi
625 ) > $IASL_DIR/source/compiler/crossgcc-build.log 2>&1
626 test -r $IASL_DIR/generate/unix/.failed && printf "${RED}failed${NC}\n" || \
627 printf "${green}ok${NC}\n"
628 test -r $IASL_DIR/generate/unix/.failed && exit 1
631 rm -f $DESTDIR$TARGETDIR/$0.commit.*
632 cp $0 $DESTDIR$TARGETDIR/"$0.commit.`git describe`"
634 if [ $SAVETEMPS -eq 0 ]; then
635 printf "Cleaning up... "
636 rm -rf ${GMP_DIR} ${BUILDDIRPREFIX}-gmp
637 rm -rf ${MPFR_DIR} ${BUILDDIRPREFIX}-mpfr
638 rm -rf ${MPC_DIR} ${BUILDDIRPREFIX}-mpc
639 rm -rf ${LIBELF_DIR} ${BUILDDIRPREFIX}-libelf
640 rm -rf ${BINUTILS_DIR} ${BUILDDIRPREFIX}-binutils
641 rm -rf ${GCC_DIR} ${BUILDDIRPREFIX}-gcc
642 rm -rf ${GDB_DIR} ${BUILDDIRPREFIX}-gdb
643 rm -rf ${EXPAT_DIR} ${BUILDDIRPREFIX}-expat
644 rm -rf ${PYTHON_DIR} ${BUILDDIRPREFIX}-python
645 rm -rf ${IASL_DIR}
646 printf "${green}ok${NC}\n"
647 else
648 printf "Leaving temporary files around... ${green}ok${NC}\n"
651 printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"