buildgcc: Add option to use ccache
[coreboot.git] / util / crossgcc / buildgcc
index b0918c0c602fe69e84cdc26955b697348e271e11..d13e65d161452bd529fcc9ee1bf17ea335d27b70 100755 (executable)
@@ -21,7 +21,7 @@
 #
 
 CROSSGCC_DATE="November 1st, 2011"
-CROSSGCC_VERSION="1.06"
+CROSSGCC_VERSION="1.07"
 
 # default settings
 TARGETDIR=`pwd`/xgcc
@@ -33,7 +33,7 @@ GMP_VERSION=5.0.2
 MPFR_VERSION=3.1.0
 MPC_VERSION=0.9
 LIBELF_VERSION=0.8.13
-GCC_VERSION=4.6.1
+GCC_VERSION=4.6.2
 GCC_AUTOCONF_VERSION=2.64
 BINUTILS_VERSION=2.21.1
 GDB_VERSION=7.3.1
@@ -126,6 +126,7 @@ myhelp()
        printf "    [-h|--help]                   print this help and exit\n"
        printf "    [-c|--clean]                  remove temporary files before build\n"
        printf "    [-t|--savetemps]              don't remove temporary files after build\n"
+       printf "    [-y|--ccache]                 Use ccache when building cross compiler\n"
        printf "    [-j|--jobs <num>]             run <num> jobs in parallel in make\n"
        printf "    [-p|--platform <platform>]    target platform to build cross compiler for\n"
        printf "                                  (defaults to $TARGETARCH)\n"
@@ -167,11 +168,11 @@ getopt - > /dev/null 2>/dev/null || gcc -o getopt getopt.c
 getoptbrand="`getopt -V | sed -e '1!d' -e 's,^\(......\).*,\1,'`"
 if [ "${getoptbrand}" = "getopt" ]; then
        # Detected GNU getopt that supports long options.
-       args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb Vhcd:p:j:D:tG -- "$@"`
+       args=`getopt -l version,help,clean,directory:,platform:,jobs:,destdir:,savetemps,skip-gdb,ccache Vhcd:p:j:D:tGy -- "$@"`
        eval set "$args"
 else
        # Detected non-GNU getopt
-       args=`getopt Vhcd:p:j:D:tG $*`
+       args=`getopt Vhcd:p:j:D:tGy $*`
        set -- $args
 fi
 
@@ -192,6 +193,7 @@ while true ; do
                -j|--jobs)      shift; JOBS="-j $1"; shift;;
                -G|--gdb)       shift; SKIPGDB=0;;
                -S|--scripting) shift; SKIPPYTHON=0;;
+               -y|--ccache)    shift; USECCACHE=1;;
                --)             shift; break;;
                -*)             printf "Invalid option\n\n"; myhelp; exit 1;;
                *)              break;;
@@ -211,7 +213,9 @@ if [ $SKIPGDB -eq 1 ]; then
        fi
 fi
 if [ $SKIPPYTHON -eq 1 ]; then
+       PYTHON_ARCHIVE=""
        PYTHON_PACKAGE=""
+       EXPAT_ARCHIVE=""
        EXPAT_PACKAGE=""
 fi
 
@@ -225,7 +229,7 @@ fi
 USE_GOLD=""
 GCC_OPTIONS="--enable-lto"
 
-if [ ${GCC_VERSION} = "4.6.2" ]; then
+if [ ${GCC_VERSION} = "trunk" ]; then
   if [ ! -r tarballs/gcc-core-${GCC_VERSION}.tar.bz2 ]; then
     printf "Pre-Release GCC ${GCC_VERSION}, checking out subversion trunk\n"
     mkdir -p tarballs/.tmp
@@ -323,6 +327,10 @@ if [ `uname` = "Darwin" ]; then
        fi
 fi
 
+if [ "$USECCACHE" = 1 ]; then
+       CC="ccache $CC"
+fi
+
 mkdir -p build-gmp build-mpfr build-mpc build-libelf build-binutils \
                build-gcc build-python build-expat
 if [ $SKIPGDB -eq 0 ]; then
@@ -335,7 +343,7 @@ printf "Building GMP ${GMP_VERSION} ... "
 (
        cd build-gmp
        rm -f .failed
-       ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
+       CC="$CC" ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
                || touch .failed
        $MAKE $JOBS || touch .failed
        $MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -364,7 +372,7 @@ printf "Building MPFR ${MPFR_VERSION} ... "
        test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
        cd build-mpfr
        rm -f .failed
-       ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
+       CC="$CC" ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
                --infodir=$TARGETDIR/info \
                --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
                touch .failed
@@ -391,7 +399,7 @@ printf "Building MPC ${MPC_VERSION} ... "
        #test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
        cd build-mpc
        rm -f .failed
-       ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
+       CC="$CC" ../${MPC_DIR}/configure --disable-shared --prefix=$TARGETDIR \
                --infodir=$TARGETDIR/info --with-mpfr=$DESTDIR$TARGETDIR \
                --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || \
                touch .failed
@@ -413,7 +421,7 @@ printf "Building libelf ${LIBELF_VERSION} ... "
        cd build-libelf
        rm -f .failed
        echo "$HOSTCFLAGS"
-       CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
+       CC="$CC" CFLAGS="$HOSTCFLAGS" libelf_cv_elf_h_works=no \
        ../${LIBELF_DIR}/configure --disable-shared --prefix=$TARGETDIR \
                --infodir=$TARGETDIR/info CFLAGS="$HOSTCFLAGS" || touch .failed
        $MAKE $JOBS || touch .failed
@@ -439,7 +447,7 @@ printf "Building binutils ${BINUTILS_VERSION} ... "
        # Now build binutils
        cd build-binutils
        rm -f .failed
-       ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
+       CC="$CC" ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR \
                --target=${TARGETARCH} --disable-werror --disable-nls \
                $USE_GOLD CFLAGS="$HOSTCFLAGS" || touch .failed
        $MAKE $JOBS || touch .failed
@@ -499,15 +507,15 @@ fi
 
 if [ -f build-expat/.success ]; then
        printf "Skipping Expat as it is already built\n"
-elif [ $SKIPGDB -eq 1 ]; then
-       printf "Skipping Expat as requested by command line (skip GDB)\n"
+elif [ $SKIPPYTHON -eq 1 ]; then
+       printf "Skipping Expat (Python scripting not enabled)\n"
 else
 printf "Building Expat ${EXPAT_VERSION} ... "
 (
        cd build-expat
        export PATH=$PATH:$DESTDIR$TARGETDIR/bin
        rm -f .failed
-       CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
+       CC="$CC" CFLAGS="$HOSTCFLAGS" ../${EXPAT_DIR}/configure --disable-shared \
                --prefix=$TARGETDIR --target=${TARGETARCH} || touch .failed
        $MAKE || touch .failed
        $MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -521,15 +529,15 @@ fi
 
 if [ -f build-python/.success ]; then
        printf "Skipping Python as it is already built\n"
-elif [ $SKIPGDB -eq 1 ]; then
-       printf "Skipping Python as requested by command line (skip GDB)\n"
+elif [ $SKIPPYTHON -eq 1 ]; then
+       printf "Skipping Python (Python scripting not enabled)\n"
 else
 printf "Building Python ${PYTHON_VERSION} ... "
 (
        cd build-python
        export PATH=$PATH:$DESTDIR$TARGETDIR/bin
        rm -f .failed
-       CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
+       CC="$CC" CFLAGS="$HOSTCFLAGS" ../${PYTHON_DIR}/configure --prefix=$TARGETDIR \
                --target=${TARGETARCH} || touch .failed
        $MAKE $JOBS || touch .failed
        $MAKE install DESTDIR=$DESTDIR || touch .failed
@@ -544,7 +552,7 @@ fi
 if [ -f build-gdb/.success ]; then
        printf "Skipping GDB as it is already built\n"
 elif [ $SKIPGDB -eq 1 ]; then
-       printf "Skipping GDB as requested by command line\n"
+       printf "Skipping GDB (GDB support not enabled)\n"
 else
 printf "Building GDB ${GDB_VERSION} ... "
 (
@@ -554,7 +562,7 @@ printf "Building GDB ${GDB_VERSION} ... "
        rm -f .failed
        LDFLAGS="-Wl,-rpath,\$\$ORIGIN/../lib/ -L$DESTDIR$TARGETDIR/lib \
                 -lpthread -ldl -lutil" \
-       CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
+       CC="$CC" CFLAGS="$HOSTCFLAGS -I$DESTDIR$TARGETDIR/include" \
        ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR \
                --target=${TARGETARCH} --disable-werror --disable-nls
        $MAKE $JOBS || touch .failed
@@ -575,7 +583,7 @@ printf "Building IASL ${IASL_VERSION} ... "
        export PATH=$PATH:$DESTDIR$TARGETDIR/bin
        rm -f .failed
        CFLAGS="$HOSTCFLAGS"
-       $MAKE || touch .failed
+       $MAKE CC="$CC" || touch .failed
        rm -f $DESTDIR$TARGETDIR/bin/iasl || touch .failed
        cp iasl $DESTDIR$TARGETDIR/bin || touch .failed
        if [ ! -f .failed ]; then touch .success; fi