OSDN Git Service

Move common functions from build tool scripts to ndk-common.sh
authorDavid 'Digit' Turner <digit@google.com>
Fri, 2 Apr 2010 22:42:37 +0000 (15:42 -0700)
committerDavid 'Digit' Turner <digit@google.com>
Sat, 3 Apr 2010 00:12:23 +0000 (17:12 -0700)
Also add build/tools/build-ccache.sh to rebuild ccache prebuilt binary
(for future use in the NDK to speedup rebuilds).

Change-Id: I10373c0d3f0e42b768c7e28d45e73e182fd6a299

build/core/ndk-common.sh
build/tools/build-ccache.sh [new file with mode: 0755]
build/tools/build-toolchain.sh
build/tools/download-toolchain-sources.sh

index 38ab6df..1a0161f 100644 (file)
@@ -63,17 +63,67 @@ fi
 VERBOSE=${VERBOSE-yes}
 VERBOSE2=${VERBOSE2-no}
 
+TMPLOG=
+
+# Setup a log file where all log() and log2() output will be sent
+#
+# $1: log file path  (optional)
+#
+setup_log_file ()
+{
+    if [ -n "$1" ] ; then
+        TMPLOG="$1"
+    else
+        TMPLOG=/tmp/ndk-log-$$.log
+    fi
+    rm -f $TMPLOG && touch $TMPLOG
+    echo "To follow build in another terminal, please use: tail -F $TMPLOG"
+}
+
+dump ()
+{
+    if [ -n "$TMPLOG" ] ; then
+        echo "$@" >> $TMPLOG
+    fi
+    echo "$@"
+}
+
 log ()
 {
     if [ "$VERBOSE" = "yes" ] ; then
-        echo "$1"
+        echo "$@"
+    else
+        if [ "$TMPLOG" ] ; then
+            echo "$@" >> $TMPLOG
+        fi
     fi
 }
 
 log2 ()
 {
     if [ "$VERBOSE2" = "yes" ] ; then
-        echo "$1"
+        echo "$@"
+    else
+        if [ -n "$TMPLOG" ] ; then
+            echo "$@" >> $TMPLOG
+        fi
+    fi
+}
+
+run ()
+{
+    if [ "$VERBOSE" = "yes" ] ; then
+        echo "##### NEW COMMAND"
+        echo "$@"
+        $@ 2>&1
+    else
+        if [ -n "$TMPLOG" ] ; then
+            echo "##### NEW COMMAND" >> $TMPLOG
+            echo "$@" >> $TMPLOG
+            $@ >>$TMPLOG 2>&1
+        else
+            $@ > /dev/null 2>&1
+        fi
     fi
 }
 
@@ -408,3 +458,79 @@ compile_exec_run()
     fi
     $TMPE
 }
+
+# Let's check that we have a working md5sum here
+check_md5sum ()
+{
+    A_MD5=`echo "A" | md5sum | cut -d' ' -f1`
+    if [ "$A_MD5" != "bf072e9119077b4e76437a93986787ef" ] ; then
+        echo "Please install md5sum on this machine"
+        exit 2
+    fi
+}
+
+# Find if a given shell program is available.
+# We need to take care of the fact that the 'which <foo>' command
+# may return either an empty string (Linux) or something like
+# "no <foo> in ..." (Darwin). Also, we need to redirect stderr
+# to /dev/null for Cygwin
+#
+# $1: variable name
+# $2: program name
+#
+# Result: set $1 to the full path of the corresponding command
+#         or to the empty/undefined string if not available
+#
+find_program ()
+{
+    local PROG
+    PROG=`which $2 2>/dev/null`
+    if [ -n "$PROG" ] ; then
+        echo "$PROG" | grep -q -e '^no '
+        if [ $? = 0 ] ; then
+            PROG=
+        fi
+    fi
+    eval $1="$PROG"
+}
+
+
+# Download a file with either 'curl', 'wget' or 'scp'
+#
+# $1: source URL (e.g. http://foo.com, ssh://blah, /some/path)
+# $2: target file
+download_file ()
+{
+    # is this HTTP, HTTPS or FTP ?
+    echo $1 | grep -q -e "^\(http\|https\):.*"
+    if [ $? = 0 ] ; then
+        if [ -n "$WGET" ] ; then
+            run $WGET -O $2 $1 
+        elif [ -n "$CURL" ] ; then
+            run $CURL -o $2 $1
+        else
+            echo "Please install wget or curl on this machine"
+            exit 1
+        fi
+        return
+    fi
+
+    # is this SSH ?
+    echo $1 | grep -q -e "^ssh:.*"
+    if [ $? = 0 ] ; then
+        if [ -n "$SCP" ] ; then
+            scp_src=`echo $1 | sed -e s%ssh://%%g`
+            run $SCP $scp_src $2
+        else
+            echo "Please install scp on this machine"
+            exit 1
+        fi
+        return
+    fi
+
+    echo $1 | grep -q -e "^/.*"
+    if [ $? = 0 ] ; then
+        run cp -f $1 $2
+    fi
+}
+
diff --git a/build/tools/build-ccache.sh b/build/tools/build-ccache.sh
new file mode 100755 (executable)
index 0000000..e4b586f
--- /dev/null
@@ -0,0 +1,189 @@
+#!/bin/sh
+#
+# Copyright (C) 2010 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#  This shell script is used to download the sources of the ccache
+#  tool that can be used to speed-up rebuilds of NDK binaries.
+#
+#  We use a special patched version of ccache 2.4 that works
+#  well on Win32 and handles the dependency generation compiler
+#  flags (-MMD -MP -MF) properly.
+#
+#  Beta versions of ccache 3.0 are supposed to do that as well but
+#  have not been checked yet.
+#
+
+# include common function and variable definitions
+. `dirname $0`/../core/ndk-common.sh
+
+print_help() {
+    echo "Rebuild the prebuilt ccache binary for the Android NDK toolchain."
+    echo ""
+    echo "This script will automatically download the sources from the"
+    echo "Internet, unless you use the --package=<file> option to specify"
+    echo "the exact source package to use."
+    echo ""
+    echo "options (defaults are within brackets):"
+    echo ""
+    echo "  --help                   print this message"
+    echo "  --package=<file>         specify download source package"
+    echo "  --build-out=<path>       set temporary build out directory [/tmp/<random>]"
+    echo "  --out=<file>             set output file for binary tarball"
+    echo "  --install                install into NDK prebuilt directory"
+    echo ""
+}
+
+BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX`
+
+OPTION_PACKAGE=
+OPTION_BUILD_OUT=
+OPTION_OUT=
+OPTION_INSTALL=no
+
+VERBOSE=no
+for opt do
+    optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
+    case "$opt" in
+    --help|-h|-\?) OPTION_HELP=yes
+        ;;
+    --verbose)
+        VERBOSE=yes
+        ;;
+    --package=*)
+        OPTION_PACKAGE="$optarg"
+        ;;
+    --build-out=*)
+        OPTION_BUILD_OUT="$optarg"
+        ;;
+    --out=*)
+        OPTION_OUT="$optarg"
+        ;;
+    --install)
+        OPTION_INSTALL=yes
+        ;;
+    *)
+        echo "unknown option '$opt', use --help"
+        exit 1
+    esac
+done
+
+if [ "$OPTION_HELP" = "yes" ] ; then
+    print_help
+    exit 0
+fi
+
+# Force generation of 32-bit binaries on 64-bit systems
+case $HOST_TAG in
+    *-x86_64)
+        HOST_CFLAGS="$HOST_CFLAGS -m32"
+        HOST_LDFLAGS="$HOST_LDFLAGS -m32"
+        force_32bit_binaries  # to modify HOST_TAG and others
+        ;;
+esac
+
+setup_log_file
+
+if [ -n "$OPTION_BUILD_OUT" ] ; then
+    BUILD_OUT=$OPTION_BUILD_OUT
+    log "Using specific build out directory: $BUILD_OUT"
+else
+    log "Using default random build out directory: $BUILD_OUT"
+fi
+
+
+# Where all generated files will be placed
+OUT=$BUILD_OUT
+
+# Check for md5sum
+check_md5sum
+
+# And wget/curl/scp too
+find_program WGET wget
+find_program CURL curl
+find_program SCP scp
+
+run rm -rf $BUILD_OUT
+run mkdir -p $BUILD_OUT
+
+if [ -n "$OPTION_PACKAGE" ] ; then
+    if [ ! -f "$OPTION_PACKAGE" ] ; then
+        dump "Your --package does not point to a valid file !"
+        exit 1
+    fi
+    tar tzf $OPTION_PACKAGE > /dev/null 2>&1
+    if [ $? != 0 ] ; then
+        dump "It looks like your --package does not point to well-formed .tar.gz archive !"
+        exit 1
+    fi
+    CCACHE_PACKAGE=$OPTION_PACKAGE
+    CCACHE_VERSION=`echo $CCACHE_PACKAGE | sed s/\.tar\.gz//g`
+    CCACHE_VERSION=`basename $CCACHE_VERSION`
+else
+    CCACHE_VERSION=ccache-2.4-android-20070905
+    CCACHE_PACKAGE=$CCACHE_VERSION.tar.gz
+    DOWNLOAD_ROOT=http://android.git.kernel.org/pub
+fi
+
+dump "Getting sources from $DOWNLOAD_ROOT/$CCACHE_PACKAGE"
+
+download_file $DOWNLOAD_ROOT/$CCACHE_PACKAGE $BUILD_OUT/$CCACHE_PACKAGE
+if [ $? != 0 ] ; then
+    dump "Could not download $DOWNLOAD_ROOT/$CCACHE_PACKAGE"
+    dump "Aborting."
+    exit 1
+fi
+
+cd $BUILD_OUT && tar xzf $BUILD_OUT/$CCACHE_PACKAGE
+if [ $? != 0 ] ; then
+    dump "Could not unpack $CCACHE_PACKAGE in $BUILD_OUT"
+    exit 1
+fi
+
+echo "Building ccache from sources..."
+cd $BUILD_OUT/$CCACHE_VERSION && run make clean && run make unpack && run make build
+if [ $? != 0 ] ; then
+    dump "Could not build ccache in $BUILD_OUT"
+fi
+
+PREBUILT_DIR=prebuilt/$HOST_TAG/ccache
+
+dump "Packaging ccache binary tarball..."
+if [ -n "$OPTION_OUT" ] ; then
+    CCACHE_TARBALL="$OPTION_OUT"
+else
+    CCACHE_TARBALL=/tmp/ccache-$HOST_TAG.tar.bz2
+fi
+cd $BUILD_OUT && run mkdir -p $PREBUILT_DIR && mv $CCACHE_VERSION/ccache $PREBUILT_DIR && run chmod a+x $PREBUILT_DIR/ccache && run tar cjf $CCACHE_TARBALL $PREBUILT_DIR/ccache
+if [ $? != 0 ] ; then
+    dump "Could not package ccache binary !"
+    exit 1
+fi
+echo "Ccache binary tarball is ready in $CCACHE_TARBALL"
+
+if [ $OPTION_INSTALL = yes ] ; then
+    dump "Installing directly into $ANDROID_NDK_ROOT/$PREBUILT_DIR/ccache"
+    run mkdir -p $ANDROID_NDK_ROOT/$PREBUILT_DIR
+    if [ $? != 0 ] ; then
+        dump "Could not install ccache binary to $PREBUILT_DIR"
+        exit 1
+    fi
+    run cp -f $BUILD_OUT/$CCACHE_VERSION/ccache $ANDROID_NDK_ROOT/$PREBUILT_DIR/ccache
+    # cleanup if needed
+    if [ -n "$OPTION_BUILD_OUT" ] ; then
+        rm -rf $BUILD_OUT
+    fi
+fi
+
+dump "Done"
index f025c3a..bdb210f 100755 (executable)
@@ -159,34 +159,7 @@ x86 )
     ;;
 esac
 
-TMPLOG=/tmp/android-toolchain-build-$$.log
-rm -rf $TMPLOG
-
-if [ $VERBOSE = yes ] ; then
-    run ()
-    {
-        echo "##### NEW COMMAND"
-        echo "$@"
-        $@ 2>&1
-    }
-    log ()
-    {
-        echo "LOG: $@"
-    }
-else
-    echo "To follow build, please use in another terminal: tail -F $TMPLOG"
-    run ()
-    {
-        echo "##### NEW COMMAND" >> $TMPLOG
-        echo "$@" >> $TMPLOG
-        $@ >>$TMPLOG 2>&1
-    }
-    log ()
-    {
-        echo "$@" > /dev/null
-    }
-fi
-
+setup_log_file
 
 if [ -n "$OPTION_GCC_VERSION" ] ; then
     GCC_VERSION="$OPTION_GCC_VERSION"
@@ -236,82 +209,14 @@ TIMESTAMP_OUT=$OUT/timestamps
 ANDROID_TOOLCHAIN_SRC=$OUT/src
 ANDROID_SYSROOT=$ANDROID_NDK_ROOT/build/platforms/$PLATFORM/arch-$ARCH
 
-# Let's check that we have a working md5sum here
-A_MD5=`echo "A" | md5sum | cut -d' ' -f1`
-if [ "$A_MD5" != "bf072e9119077b4e76437a93986787ef" ] ; then
-    echo "Please install md5sum on this machine"
-    exit 2
-fi
-
-# Find if a given shell program is available.
-# We need to take care of the fact that the 'which <foo>' command
-# may return either an empty string (Linux) or something like
-# "no <foo> in ..." (Darwin). Also, we need to redirect stderr
-# to /dev/null for Cygwin
-#
-# $1: variable name
-# $2: program name
-#
-# Result: set $1 to the full path of the corresponding command
-#         or to the empty/undefined string if not available
-#
-find_program ()
-{
-    local PROG
-    PROG=`which $2 2>/dev/null`
-    if [ -n "$PROG" ] ; then
-        echo "$PROG" | grep -q -e '^no '
-        if [ $? = 0 ] ; then
-            PROG=
-        fi
-    fi
-    eval $1="$PROG"
-}
+# Check that we have md5sum to check downloaded binaries
+check_md5sum
 
-# And wget too
+# Do we have anything to download stuff
 find_program WGET wget
 find_program CURL curl
 find_program SCP scp
 
-# download a file with either 'curl', 'wget' or 'scp'
-# $1: source
-# $2: target
-download_file ()
-{
-    # is this HTTP, HTTPS or FTP ?
-    echo $1 | grep -q -e "^\(http\|https\):.*"
-    if [ $? = 0 ] ; then
-        if [ -n "$WGET" ] ; then
-            $WGET -O $2 $1 
-        elif [ -n "$CURL" ] ; then
-            $CURL -o $2 $1
-        else
-            echo "Please install wget or curl on this machine"
-            exit 1
-        fi
-        return
-    fi
-
-    # is this SSH ?
-    echo $1 | grep -q -e "^ssh:.*"
-    if [ $? = 0 ] ; then
-        if [ -n "$SCP" ] ; then
-            scp_src=`echo $1 | sed -e s%ssh://%%g`
-            $SCP $scp_src $2
-        else
-            echo "Please install scp on this machine"
-            exit 1
-        fi
-        return
-    fi
-
-    echo $1 | grep -q -e "^/.*"
-    if [ $? = 0 ] ; then
-        cp -f $1 $2
-    fi
-}
-
-
 timestamp_check ()
 {
     [ -f $TIMESTAMP_OUT/$1/timestamp-$2 ]
@@ -342,12 +247,12 @@ download_package ()
 {
     WORKSPACE=$ANDROID_NDK_ARCHIVE/$1
     if [ ! -d $WORKSPACE ] ; then
-        echo "No directory named $1 under $ANDROID_NDK_ARCHIVE"
+        dump "No directory named $1 under $ANDROID_NDK_ARCHIVE"
         exit 2
     fi
     SOURCES=$WORKSPACE/sources.txt
     if [ ! -f $SOURCES ] ; then
-        echo "Missing sources.txt in $WORKSPACE"
+        dump "Missing sources.txt in $WORKSPACE"
         exit 2
     fi
     # First line must be file name
@@ -355,7 +260,7 @@ download_package ()
     # Second line must be md5sum
     PKGSUM=`cat $SOURCES | sed 1d | sed 1q`
     if [ -z "$PKGNAME" -o -z "$PKGSUM" ] ; then
-        echo "Corrupted file: $SOURCES"
+        dump "Corrupted file: $SOURCES"
         exit 2
     fi
 
@@ -368,36 +273,36 @@ download_package ()
             echo $src | grep -q -e "^/.*"
             if [ $? = 0 ] ; then
                 if [ -f $src ] ; then
-                    echo "Copy    : $PKGNAME"
-                    echo "          from `dirname $src`"
-                    echo "          into $PACKAGE_TARBALL"
+                    dump "Copy    : $PKGNAME"
+                    dump "          from `dirname $src`"
+                    dump "          into $PACKAGE_TARBALL"
                     run cp -f $src $PACKAGE_TARBALL
                     if [ $? = 0 ] ; then
                         break
                     fi
-                    echo "Copy    : Problem copying from $src"
+                    dump "Copy    : Problem copying from $src"
                 else
-                    echo "Copy    : Can't find $src (skipping)"
+                    dump "Copy    : Can't find $src (skipping)"
                 fi
                 continue
             fi
             echo $src | grep -q -e "^\(http\|https\|ftp\|ssh\):.*"
             if [ $? = 0 ] ; then
-                echo "Download: $PKGNAME"
-                echo "          from $src"
-                echo "          into $PACKAGE_TARBALL"
+                dump "Download: $PKGNAME"
+                dump "          from $src"
+                dump "          into $PACKAGE_TARBALL"
                 download_file $src $PACKAGE_TARBALL
                 if [ $? = 0 ] ; then
                     break
                 fi
                 continue
             else
-                "Copy    : Unknown method in $src"
+                dump "Copy    : Unknown method in $src"
             fi
         done
         if [ ! -f $PACKAGE_TARBALL ] ; then
-            echo "ERROR: Could not copy or download $PKGNAME !"
-            echo "Your probably need to edit $WORKSPACE/sources.txt"
+            dump "ERROR: Could not copy or download $PKGNAME !"
+            dump "Your probably need to edit $WORKSPACE/sources.txt"
             exit 1
         fi
     fi
@@ -405,14 +310,14 @@ download_package ()
     if ! timestamp_check $1 verify ; then
         SUM=`md5sum $PACKAGE_TARBALL | cut -d " " -f 1`
         if [ "$SUM" != "$PKGSUM" ] ; then
-            echo "ERROR: Invalid MD5 Sum for $PACKAGE_TARBALL"
-            echo "    Expected $PKGSUM"
-            echo "    Computed $SUM"
-            echo "You might want to use the --force-download option."
+            dump "ERROR: Invalid MD5 Sum for $PACKAGE_TARBALL"
+            dump "    Expected $PKGSUM"
+            dump "    Computed $SUM"
+            dump "You might want to use the --force-download option."
             exit 2
         fi
 
-        echo "Verified: $PACKAGE_TARBALL"
+        dump "Verified: $PACKAGE_TARBALL"
         timestamp_set   $1 verify
         timestamp_force $1 unpack
     fi
@@ -428,9 +333,9 @@ unpack_package ()
     SRCPKG=`var_value PKG_$1`
     SRCDIR=$2
     if ! timestamp_check $1 unpack; then
-        echo "Unpack  : $1 sources"
-        echo "          from $SRCPKG"
-        echo "          into $SRCDIR"
+        dump "Unpack  : $1 sources"
+        dump "          from $SRCPKG"
+        dump "          into $SRCDIR"
         run rm -rf $SRCDIR
         run mkdir -p $SRCDIR
         TARFLAGS=xjf
@@ -439,7 +344,7 @@ unpack_package ()
         fi
         run tar $TARFLAGS $SRCPKG -C $SRCDIR
         if [ $? != 0 ] ; then
-            echo "ERROR: Could not unpack $1, See $TMPLOG"
+            dump "ERROR: Could not unpack $1, See $TMPLOG"
             exit 1
         fi
         timestamp_set   $1 unpack
@@ -466,18 +371,18 @@ patch_package ()
     if ! timestamp_check $1 patch; then
         PATCH_FILES=`(cd $3 && find . -name "*.patch") 2> /dev/null`
         if [ -z "$PATCH_FILES" ] ; then
-            echo "Patch   : none provided"
+            dump "Patch   : none provided"
             return
         fi
         for PATCH in $PATCH_FILES; do
-            echo "Patch   : $1 sources"
-            echo "          from $PATCH"
-            echo "          into $SRCDIR"
+            dump "Patch   : $1 sources"
+            dump "          from $PATCH"
+            dump "          into $SRCDIR"
             PATCHDIR=`dirname $PATCH`
             PATCHNAME=`basename $PATCH`
             cd $SRCDIR/$PATCHDIR && patch -p1 < $3/$PATCH
             if [ $? != 0 ] ; then
-                echo "Patch failure !! Please check toolchain package !"
+                dump "Patch failure !! Please check toolchain package !"
                 exit 1
             fi
         done
@@ -487,19 +392,19 @@ patch_package ()
 }
 
 if [ $OPTION_FORCE_DOWNLOAD ] ; then
-    rm -rf $PACKAGE_OUT $ANDROID_TOOLCHAIN_SRC
+    run rm -rf $PACKAGE_OUT $ANDROID_TOOLCHAIN_SRC
     timestamp_force toolchain unpack
     timestamp_force toolchain verify
 fi
 
 if [ $OPTION_FORCE_BUILD = "yes" ] ; then
-    rm -rf $ANDROID_TOOLCHAIN_BUILD
+    run rm -rf $ANDROID_TOOLCHAIN_BUILD
     timestamp_clear toolchain
     timestamp_clear gdbserver
 fi
 
 # checks, we need more checks..
-mkdir -p $PACKAGE_OUT
+run mkdir -p $PACKAGE_OUT
 if [ $? != 0 ] ; then
     echo "Can't create download/archive directory for toolchain tarballs"
     exit 2
@@ -540,7 +445,7 @@ build_toolchain ()
 
     # configure the toolchain
     if ! timestamp_check $TOOLCHAIN_NAME configure; then
-        echo "Configure: $TOOLCHAIN_NAME toolchain build"
+        dump "Configure: $TOOLCHAIN_NAME toolchain build"
         # Old versions of the toolchain source packages placed the
         # configure script at the top-level. Newer ones place it under
         # the build directory though. Probe the file system to check
@@ -565,7 +470,7 @@ build_toolchain ()
                                 --with-gcc-version=$GCC_VERSION \
                                 --with-gdb-version=$GDB_VERSION
         if [ $? != 0 ] ; then
-            echo "Error while trying to configure toolchain build. See $TMPLOG"
+            dump "Error while trying to configure toolchain build. See $TMPLOG"
             exit 1
         fi
         ABI="$OLD_ABI"
@@ -577,7 +482,7 @@ build_toolchain ()
 
     # build the toolchain
     if ! timestamp_check $TOOLCHAIN_NAME build ; then
-        echo "Building : $TOOLCHAIN_NAME toolchain [this can take a long time]."
+        dump "Building : $TOOLCHAIN_NAME toolchain [this can take a long time]."
         OLD_CFLAGS="$CFLAGS"
         OLD_LDFLAGS="$LDFLAGS"
         OLD_ABI="$ABI"
@@ -599,7 +504,7 @@ build_toolchain ()
 
     # install the toolchain to its final location
     if ! timestamp_check $TOOLCHAIN_NAME install ; then
-        echo "Install  : $TOOLCHAIN_NAME toolchain binaries."
+        dump "Install  : $TOOLCHAIN_NAME toolchain binaries."
         cd $TOOLCHAIN_BUILD &&
         run make install
         if [ $? != 0 ] ; then
@@ -623,7 +528,7 @@ build_toolchain ()
 
     # configure the gdbserver build now
     if ! timestamp_check $TOOLCHAIN_NAME-gdbserver configure; then
-        echo "Configure: $TOOLCHAIN_NAME gdbserver build."
+        dump "Configure: $TOOLCHAIN_NAME gdbserver build."
         # Old toolchain source packages placed the gdb sources at
         # the top-level, while newer ones place them under the 'gdb'
         # directory. Probe the filesystem to check which one is appropriate.
@@ -631,7 +536,7 @@ build_toolchain ()
         if [ ! -d $GDB_SRCDIR ] ; then
             GDB_SRCDIR=$TOOLCHAIN_SRC/gdb-$GDB_VERSION
         fi
-        mkdir -p $GDBSERVER_BUILD
+        run mkdir -p $GDBSERVER_BUILD
         OLD_CC="$CC"
         OLD_CFLAGS="$CFLAGS"
         OLD_LDFLAGS="$LDFLAGS"
@@ -650,7 +555,7 @@ build_toolchain ()
         --host=${ABI_CONFIGURE_HOST} \
         --with-sysroot=$ANDROID_SYSROOT
         if [ $? != 0 ] ; then
-            echo "Could not configure gdbserver build. See $TMPLOG"
+            dump "Could not configure gdbserver build. See $TMPLOG"
             exit 1
         fi
         CC="$OLD_CC"
@@ -662,11 +567,11 @@ build_toolchain ()
 
     # build gdbserver
     if ! timestamp_check $TOOLCHAIN_NAME-gdbserver build; then
-        echo "Building : $TOOLCHAIN_NAME gdbserver."
+        dump "Building : $TOOLCHAIN_NAME gdbserver."
         cd $GDBSERVER_BUILD &&
         run make -j$JOBS
         if [ $? != 0 ] ; then
-            echo "Could not build $TOOLCHAIN_NAME gdbserver. See $TMPLOG"
+            dump "Could not build $TOOLCHAIN_NAME gdbserver. See $TMPLOG"
             exit 1
         fi
         timestamp_set   $TOOLCHAIN_NAME-gdbserver build
@@ -679,13 +584,13 @@ build_toolchain ()
     # not in $SYSROOT/usr/bin
     #
     if ! timestamp_check $TOOLCHAIN_NAME-gdbserver install; then
-        echo "Install  : $TOOLCHAIN_NAME gdbserver."
+        dump "Install  : $TOOLCHAIN_NAME gdbserver."
         DEST=$TOOLCHAIN_PREFIX/bin
         mkdir -p $DEST &&
         $TOOLCHAIN_PREFIX/bin/${ABI_TOOLCHAIN_PREFIX}-strip $GDBSERVER_BUILD/gdbserver &&
         run cp -f $GDBSERVER_BUILD/gdbserver $DEST/gdbserver
         if [ $? != 0 ] ; then
-            echo "Could not install gdbserver. See $TMPLOG"
+            dump "Could not install gdbserver. See $TMPLOG"
             exit 1
         fi
         timestamp_set   $TOOLCHAIN_NAME-gdbserver install
@@ -733,12 +638,12 @@ done
 # package the toolchain
 TOOLCHAIN_TARBALL=/tmp/android-ndk-prebuilt-$RELEASE-$HOST_TAG.tar.bz2
 if ! timestamp_check package toolchain; then
-    echo "Cleanup  : Removing unuseful stuff"
-    rm -rf $OUT/build/prebuilt/$HOST_TAG/*/share
-    find $OUT/build/prebuilt/$HOST_TAG -name "libiberty.a" | xargs rm -f
-    find $OUT/build/prebuilt/$HOST_TAG -name "lib${ABI}-elf-linux-sim.a" | xargs rm -f
-    echo "Package  : $HOST_ARCH toolchain binaries"
-    echo "           into $TOOLCHAIN_TARBALL"
+    dump "Cleanup  : Removing unuseful stuff"
+    run rm -rf $OUT/build/prebuilt/$HOST_TAG/*/share
+    run find $OUT/build/prebuilt/$HOST_TAG -name "libiberty.a" | xargs rm -f
+    run find $OUT/build/prebuilt/$HOST_TAG -name "lib${ABI}-elf-linux-sim.a" | xargs rm -f
+    dump "Package  : $HOST_ARCH toolchain binaries"
+    dump "           into $TOOLCHAIN_TARBALL"
     cd $ANDROID_NDK_ROOT &&
     TARFLAGS="cjf"
     if [ $VERBOSE = yes ] ; then
@@ -750,21 +655,21 @@ if ! timestamp_check package toolchain; then
     done
     run tar $TARFLAGS $TOOLCHAIN_TARBALL -C $OUT $TOOLCHAIN_SRC_DIRS
     if [ $? != 0 ] ; then
-        echo "ERROR: Cannot package prebuilt toolchain binaries. See $TMPLOG"
+        dump "ERROR: Cannot package prebuilt toolchain binaries. See $TMPLOG"
         exit 1
     fi
     timestamp_set package toolchain
-    echo "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
+    dump "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
 else
-    echo "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
+    dump "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
 fi
 
 if [ -z "$OPTION_BUILD_OUT" ] ; then
-    echo "Cleaning temporary directory $OUT"
+    dump "Cleaning temporary directory $OUT"
     rm -rf $OUT
 else
-    echo "Don't forget to clean build directory $OUT"
+    dump "Don't forget to clean build directory $OUT"
 fi
 
-echo "Done."
+dump "Done."
 rm -f $TMPLOG
index ffbc065..420ef67 100755 (executable)
@@ -81,33 +81,7 @@ if [ $OPTION_HELP = "yes" ] ; then
     exit 0
 fi
 
-TMPLOG=/tmp/android-ndk-download-toolchain-$$.log
-rm -rf $TMPLOG
-
-if [ $VERBOSE = yes ] ; then
-    run ()
-    {
-        echo "##### NEW COMMAND"
-        echo $@
-        $@ 2>&1 | tee $TMPLOG
-    }
-    log ()
-    {
-        echo "LOG: $@"
-    }
-else
-    echo "To follow download, please use in another terminal: tail -F $TMPLOG"
-    run ()
-    {
-        echo "##### NEW COMMAND" >> $TMPLOG
-        echo "$@" >> $TMPLOG
-        $@ 1>$TMPLOG 2>&1
-    }
-    log ()
-    {
-        echo "$@" > /dev/null
-    }
-fi
+setup_log_file ()
 
 if [ -n "$OPTION_RELEASE" ] ; then
     RELEASE="$OPTION_RELEASE"
@@ -152,11 +126,11 @@ GITPREFIX=git://android.git.kernel.org/toolchain
 
 toolchain_clone ()
 {
-    echo "downloading sources for toolchain/$1"
+    dump "downloading sources for toolchain/$1"
     log "cloning $GITPREFIX/$1.git"
     run git clone $GITPREFIX/$1.git $1
     if [ $? != 0 ] ; then
-        echo "Could not clone $GITPREFIX/$1.git ?"
+        dump "Could not clone $GITPREFIX/$1.git ?"
         exit 1
     fi
     log "checking out $BRANCH branch of $1.git"
@@ -164,7 +138,7 @@ toolchain_clone ()
     if [ "$BRANCH" != "master" ] ; then
         run git checkout -b $BRANCH origin/$BRANCH
         if [ $? != 0 ] ; then
-            echo "Could not checkout $1 ?"
+            dump "Could not checkout $1 ?"
             exit 1
         fi
     fi
@@ -193,13 +167,13 @@ rm -rf $TMPDIR/gcc/gdb-6.8
 
 # create the package
 PACKAGE=/tmp/$PKGNAME.tar.bz2
-echo "Creating package archive $PACKAGE"
+dump "Creating package archive $PACKAGE"
 cd `dirname $TMPDIR`
 run tar cjvf $PACKAGE -C /tmp/$PKGNAME .
 if [ $? != 0 ] ; then
-    echo "Could not package toolchain source archive ?. See $TMPLOG"
+    dump "Could not package toolchain source archive ?. See $TMPLOG"
     exit 1
 fi
 
-echo "Toolchain sources downloaded and packaged succesfully at $PACKAGE"
+dump "Toolchain sources downloaded and packaged succesfully at $PACKAGE"
 rm -f $TMPLOG