diff options
author | David 'Digit' Turner <digit@google.com> | 2010-04-16 11:58:02 -0700 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2010-04-26 16:33:57 -0700 |
commit | f051ab722edb8c443e73dea83724e50f6c858970 (patch) | |
tree | 9b212218834c3e87b3c72f861c8002a49ab6a9fa /build/tools | |
parent | a08d605794902f5c7ed79b3d894adb722e1b6cac (diff) | |
download | ndk-f051ab722edb8c443e73dea83724e50f6c858970.tar.gz |
Rework toolchain binaries build scripts.
Remove build-toolchain.sh and now provide rebuild-all-prebuilts.sh
Change-Id: I558c95d1667d1283be9b3a075ad0565e05da0dc5
Diffstat (limited to 'build/tools')
-rwxr-xr-x | build/tools/build-ccache.sh | 173 | ||||
-rwxr-xr-x | build/tools/build-gcc.sh | 232 | ||||
-rwxr-xr-x | build/tools/build-gdbserver.sh | 167 | ||||
-rwxr-xr-x | build/tools/build-toolchain.sh | 675 | ||||
-rwxr-xr-x | build/tools/download-toolchain-sources.sh | 146 | ||||
-rwxr-xr-x | build/tools/make-release.sh | 2 | ||||
-rwxr-xr-x | build/tools/patch-sources.sh | 77 | ||||
-rw-r--r-- | build/tools/prebuilt-common.sh | 426 | ||||
-rwxr-xr-x | build/tools/rebuild-all-prebuilt.sh | 199 |
9 files changed, 1223 insertions, 874 deletions
diff --git a/build/tools/build-ccache.sh b/build/tools/build-ccache.sh index e4b586ff5..51fe5e5d4 100755 --- a/build/tools/build-ccache.sh +++ b/build/tools/build-ccache.sh @@ -26,121 +26,72 @@ # # 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 "" -} +. `dirname $0`/prebuilt-common.sh -BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX` +PROGRAM_PARAMETERS="<ndk-dir>" +PROGRAM_DESCRIPTION="Rebuild the prebuilt ccache binary for the Android NDK toolchain." -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 +CCACHE_VERSION=ccache-2.4-android-20070905 +CCACHE_PACKAGE=$CCACHE_VERSION.tar.gz +DOWNLOAD_ROOT=http://android.git.kernel.org/pub +CCACHE_URL=$DOWNLOAD_ROOT/$CCACHE_PACKAGE -if [ "$OPTION_HELP" = "yes" ] ; then - print_help - exit 0 -fi +OPTION_PACKAGE=no -# 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 +BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX` +OPTION_BUILD_OUT= +OPTION_FROM= +register_option "--from=<url>" do_from "Specify source package" "$PACKAGE" +register_option "--build-out=<path>" do_build_out "Set temporary build directory" "/tmp/<random>" -# Where all generated files will be placed -OUT=$BUILD_OUT +do_from () { CCACHE_URL=$1; CCACHE_PACKAGE=`basename $1`; } +do_build_out () { OPTION_BUILD_OUT=$1; } -# Check for md5sum -check_md5sum - -# And wget/curl/scp too -find_program WGET wget -find_program CURL curl -find_program SCP scp +extract_parameters $@ -run rm -rf $BUILD_OUT -run mkdir -p $BUILD_OUT +set_parameters () +{ + if [ -n "$2" ] ; then + echo "ERROR: Too many parameters. See --help for usage." + exit 1 + fi -if [ -n "$OPTION_PACKAGE" ] ; then - if [ ! -f "$OPTION_PACKAGE" ] ; then - dump "Your --package does not point to a valid file !" + NDK_DIR=$1 + if [ -z "$NDK_DIR" ] ; then + echo "ERROR: Missing required ndk directory. See --help for usage." exit 1 fi - tar tzf $OPTION_PACKAGE > /dev/null 2>&1 + + mkdir -p $NDK_DIR if [ $? != 0 ] ; then - dump "It looks like your --package does not point to well-formed .tar.gz archive !" + echo "ERROR: Could not create NDK target directory: $NDK_DIR" 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 +} + +set_parameters $PARAMETERS + +prepare_host_flags + +fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory" + +# Check for md5sum +check_md5sum + +prepare_download + +run rm -rf $BUILD_OUT && run mkdir -p $BUILD_OUT +if [ $? != 0 ] ; then + echo "ERROR: Could not create build directory: $BUILD_OUT" + exit 1 fi -dump "Getting sources from $DOWNLOAD_ROOT/$CCACHE_PACKAGE" +dump "Getting sources from $CCACHE_URL" -download_file $DOWNLOAD_ROOT/$CCACHE_PACKAGE $BUILD_OUT/$CCACHE_PACKAGE +download_file $CCACHE_URL $BUILD_OUT/$CCACHE_PACKAGE if [ $? != 0 ] ; then - dump "Could not download $DOWNLOAD_ROOT/$CCACHE_PACKAGE" + dump "Could not download $CCACHE_URL" dump "Aborting." exit 1 fi @@ -157,33 +108,11 @@ 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 +PREBUILT_DIR=$NDK_DIR/build/prebuilt/$HOST_TAG/ccache +mkdir -p $PREBUILT_DIR && cp -p $BUILD_OUT/$CCACHE_VERSION/ccache $PREBUILT_DIR if [ $? != 0 ] ; then - dump "Could not package ccache binary !" + dump "Could not copy 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" diff --git a/build/tools/build-gcc.sh b/build/tools/build-gcc.sh new file mode 100755 index 000000000..2ac0d2efc --- /dev/null +++ b/build/tools/build-gcc.sh @@ -0,0 +1,232 @@ +#!/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 rebuild the gcc and toolchain binaries +# for the Android NDK. +# + +# include common function and variable definitions +. `dirname $0`/prebuilt-common.sh + +PROGRAM_PARAMETERS="<src-dir> <ndk-dir> <toolchain>" + +PROGRAM_DESCRIPTION=\ +"Rebuild the gcc toolchain prebuilt binaries for the Android NDK. + +Where <src-dir> is the location of toolchain sources, <ndk-dir> is +the top-level NDK installation path and <toolchain> is the name of +the toolchain to use (e.g. arm-eabi-4.4.0)." + +JOBS=$HOST_NUM_CPUS +RELEASE=`date +%Y%m%d` +BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX` +PLATFORM=android-3 +GDB_VERSION=6.6 +BINUTILS_VERSION=2.19 + +OPTION_BUILD_OUT= +OPTION_PLATFORM= +OPTION_SYSROOT= +OPTION_BINUTILS_VERSION= + +register_option "--build-out=<path>" do_build_out "Set temporary build directory" "/tmp/<random>" +register_option "--sysroot=<path>" do_sysroot "Specify sysroot directory directly" +register_option "--platform=<name>" do_platform "Specify platform name" "$PLATFORM" +register_option "--gdb-version=<version>" do_gdb_version "Specify gdb version" "$GDB_VERSION" +register_option "--binutils-version=<version>" do_binutils_version "Specify binutils version" "$BINUTILS_VERSION" +register_option "-j<number>" do_jobs "Use <number> parallel build jobs" "$JOBS" + +do_build_out () +{ + OPTION_BUILD_OUT=$1 +} + +do_platform () +{ + OPTION_PLATFORM=$1 +} + +do_sysroot () +{ + OPTION_SYSROOT=$1 +} + +do_gdb_version () +{ + OPTION_GDB_VERSION=$1 +} + +do_binutils_version () +{ + OPTION_BINUTILS_VERSION=$1 +} + +do_jobs () +{ + JOBS=$1 +} + +extract_parameters $@ + +set_parameters () +{ + SRC_DIR="$1" + NDK_DIR="$2" + TOOLCHAIN="$3" + + # Check source directory + # + if [ -z "$SRC_DIR" ] ; then + echo "ERROR: Missing source directory parameter. See --help for details." + exit 1 + fi + + if [ ! -d "$SRC_DIR/gcc" ] ; then + echo "ERROR: Source directory does not contain gcc sources: $SRC_DIR" + exit 1 + fi + + log "Using source directory: $SRC_DIR" + + # Check NDK installation directory + # + if [ -z "$NDK_DIR" ] ; then + echo "ERROR: Missing NDK directory parameter. See --help for details." + exit 1 + fi + + if [ ! -d "$NDK_DIR" ] ; then + mkdir -p $NDK_DIR + if [ $? != 0 ] ; then + echo "ERROR: Could not create target NDK installation path: $NDK_DIR" + exit 1 + fi + fi + + log "Using NDK directory: $NDK_DIR" + + # Check toolchain name + # + if [ -z "$TOOLCHAIN" ] ; then + echo "ERROR: Missing toolchain name parameter. See --help for details." + exit 1 + fi +} + +set_parameters $PARAMETERS + +prepare_host_flags + +parse_toolchain_name + +fix_option PLATFORM "$OPTION_PLATFORM" "platform" +fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory" +fix_sysroot "$OPTION_SYSROOT" + +fix_option GDB_VERSION "$OPTION_GDB_VERSION" "gdb version" +if [ ! -d $SRC_DIR/gdb/gdb-$GDB_VERSION ] ; then + echo "ERROR: Missing gdb sources: $SRC_DIR/gdb/gdb-$GDB_VERSION" + echo " Use --gdb-version=<version> to specify alternative." + exit 1 +fi + +fix_option BINUTILS_VERSION "$OPTION_BINUTILS_VERSION" "binutils version" +if [ ! -d $SRC_DIR/binutils/binutils-$BINUTILS_VERSION ] ; then + echo "ERROR: Missing binutils sources: $SRC_DIR/binutils/binutils-$BINUTILS_VERSION" + echo " Use --binutils-version=<version> to specify alternative." + exit 1 +fi + +set_toolchain_install $NDK_DIR/build/prebuilt/$HOST_TAG/$TOOLCHAIN + +# Location where the toolchain license files are +TOOLCHAIN_LICENSES=$ANDROID_NDK_ROOT/build/tools/toolchain-licenses + +# configure the toolchain +# +dump "Configure: $TOOLCHAIN 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 +# this. +BUILD_SRCDIR=$SRC_DIR/build +if [ ! -d $BUILD_SRCDIR ] ; then + BUILD_SRCDIR=$SRC_DIR +fi +OLD_ABI="${ABI}" +OLD_CFLAGS="$CFLAGS" +OLD_LDFLAGS="$LDFLAGS" +mkdir -p $BUILD_OUT && +cd $BUILD_OUT && +export ABI="32" && # needed to build a 32-bit gmp +export CFLAGS="$HOST_CFLAGS" && +export LDFLAGS="$HOST_LDFLAGS" && run \ +$BUILD_SRCDIR/configure --target=$ABI_TOOLCHAIN_PREFIX \ + --disable-nls \ + --prefix=$TOOLCHAIN_PATH \ + --with-sysroot=$SYSROOT \ + --with-binutils-version=$BINUTILS_VERSION \ + --with-gcc-version=$GCC_VERSION \ + --with-gdb-version=$GDB_VERSION +if [ $? != 0 ] ; then + dump "Error while trying to configure toolchain build. See $TMPLOG" + exit 1 +fi +ABI="$OLD_ABI" +CFLAGS="$OLD_CFLAGS" +LDFLAGS="$OLD_LDFLAGS" + +# build the toolchain +dump "Building : $TOOLCHAIN toolchain [this can take a long time]." +OLD_CFLAGS="$CFLAGS" +OLD_LDFLAGS="$LDFLAGS" +OLD_ABI="$ABI" +cd $BUILD_OUT && +export CFLAGS="$HOST_CFLAGS" && +export LDFLAGS="$HOST_LDFLAGS" && +export ABI="32" && +run make -j$JOBS +if [ $? != 0 ] ; then + echo "Error while building toolchain. See $TMPLOG" + exit 1 +fi +CFLAGS="$OLD_CFLAGS" +LDFLAGS="$OLD_LDFLAGS" +ABI="$OLD_ABI" + +# install the toolchain to its final location +dump "Install : $TOOLCHAIN toolchain binaries." +cd $BUILD_OUT && run make install +if [ $? != 0 ] ; then + echo "Error while installing toolchain. See $TMPLOG" + exit 1 +fi +# don't forget to copy the GPL and LGPL license files +run cp -f $TOOLCHAIN_LICENSES/COPYING $TOOLCHAIN_LICENSES/COPYING.LIB $TOOLCHAIN_PATH +# remove some unneeded files +run rm -f $TOOLCHAIN_PATH/bin/*-gccbug +run rm -rf $TOOLCHAIN_PATH/man $TOOLCHAIN_PATH/info +# strip binaries to reduce final package size +run strip $TOOLCHAIN_PATH/bin/* +run strip $TOOLCHAIN_PATH/$ABI_TOOLCHAIN_PATH/bin/* +run strip $TOOLCHAIN_PATH/libexec/gcc/*/*/cc1 +run strip $TOOLCHAIN_PATH/libexec/gcc/*/*/cc1plus +run strip $TOOLCHAIN_PATH/libexec/gcc/*/*/collect2 + +dump "Done." +if [ -n "$OPTION_BUILD_OUT" ] ; then + rm -rf $BUILD_OUT +fi diff --git a/build/tools/build-gdbserver.sh b/build/tools/build-gdbserver.sh new file mode 100755 index 000000000..2bfc7b210 --- /dev/null +++ b/build/tools/build-gdbserver.sh @@ -0,0 +1,167 @@ +#!/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 rebuild the gdbserver binary from +# the Android NDK's prebuilt binaries. +# + +# include common function and variable definitions +. `dirname $0`/prebuilt-common.sh + +PROGRAM_PARAMETERS="<src-dir> <ndk-dir> <toolchain>" + +PROGRAM_DESCRIPTION=\ +"Rebuild the gdbserver prebuilt binary for the Android NDK toolchain. + +Where <src-dir> is the location of the gdbserver sources, +<ndk-dir> is the top-level NDK installation path and <toolchain> +is the name of the toolchain to use (e.g. arm-eabi-4.4.0). + +NOTE: The --platform option is ignored if --sysroot is used." + +RELEASE=`date +%Y%m%d` +BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX` +PLATFORM=android-3 +VERBOSE=no +JOBS=$HOST_NUM_CPUS + +OPTION_HELP=no +OPTION_BUILD_OUT= +OPTION_SYSROOT= + +register_option "--build-out=<path>" do_build_out "Set temporary build directory" "/tmp/random" +register_option "--platform=<name>" do_platform "Target specific platform" "$PLATFORM" +register_option "--sysroot=<path>" do_sysroot "Specify sysroot directory directly." +register_option "-j<number>" do_jobs "Use <number> build jobs in parallel" "$JOBS" + +do_build_out () { OPTION_BUILD_OUT=$1; } +do_platform () { OPTION_PLATFORM=$1; } +do_sysroot () { OPTION_SYSROOT=$1; } +do_jobs () { JOBS=$1; } + +extract_parameters $@ + +set_parameters () +{ + SRC_DIR="$1" + NDK_DIR="$2" + TOOLCHAIN="$3" + + # Check source directory + # + if [ -z "$SRC_DIR" ] ; then + echo "ERROR: Missing source directory parameter. See --help for details." + exit 1 + fi + + if [ ! -f "$SRC_DIR/gdbreplay.c" ] ; then + echo "ERROR: Source directory does not contain gdb sources: $SRC_DIR" + exit 1 + fi + + log "Using source directory: $SRC_DIR" + + # Check NDK installation directory + # + if [ -z "$NDK_DIR" ] ; then + echo "ERROR: Missing NDK directory parameter. See --help for details." + exit 1 + fi + + if [ ! -d "$NDK_DIR" ] ; then + echo "ERROR: NDK directory does not exist: $NDK_DIR" + exit 1 + fi + + log "Using NDK directory: $NDK_DIR" + + # Check toolchain name + # + if [ -z "$TOOLCHAIN" ] ; then + echo "ERROR: Missing toolchain name parameter. See --help for details." + exit 1 + fi +} + +set_parameters $PARAMETERS + +prepare_host_flags + +parse_toolchain_name +check_toolchain_install $NDK_DIR + +# Check build directory +# +fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build out directory" +fix_option PLATFORM "$OPTION_PLATFORM" "platform" +fix_sysroot "$OPTION_SYSROOT" + +# configure the gdbserver build now +dump "Configure: $TOOLCHAIN gdbserver build." +run mkdir -p $BUILD_OUT +OLD_CC="$CC" +OLD_CFLAGS="$CFLAGS" +OLD_LDFLAGS="$LDFLAGS" + +INCLUDE_DIRS=\ +"-I$TOOLCHAIN_PATH/lib/gcc/$ABI_TOOLCHAIN_PREFIX/$GCC_VERSION/include \ +-I$SYSROOT/usr/include" +CRTBEGIN="$SYSROOT/usr/lib/crtbegin_static.o" +CRTEND="$SYSROOT/usr/lib/crtend_android.o" +LIBRARY_LDFLAGS="$CRTBEGIN -L$SYSROOT/usr/lib -lc -lm -lgcc $CRTEND " + +cd $BUILD_OUT && +export CC="$TOOLCHAIN_PREFIX-gcc" && +export CFLAGS="-O2 -nostdinc -nostdlib -D__ANDROID__ -DANDROID -DSTDC_HEADERS $INCLUDE_DIRS" && +export LDFLAGS="-static -Wl,-z,nocopyreloc -Wl,--no-undefined $LIBRARY_LDFLAGS" && +run $SRC_DIR/configure \ +--host=${ABI_CONFIGURE_HOST} \ +--with-sysroot=$SYSROOT +if [ $? != 0 ] ; then + dump "Could not configure gdbserver build. See $TMPLOG" + exit 1 +fi +CC="$OLD_CC" +CFLAGS="$OLD_CFLAGS" +LDFLAGS="$OLD_LDFLAGS" + +# build gdbserver +dump "Building : $TOOLCHAIN gdbserver." +cd $BUILD_OUT && +run make -j$JOBS +if [ $? != 0 ] ; then + dump "Could not build $TOOLCHAIN gdbserver. Use --verbose to see why." + exit 1 +fi + +# install gdbserver +# +# note that we install it in the toolchain bin directory +# not in $SYSROOT/usr/bin +# +dump "Install : $TOOLCHAIN gdbserver." +DEST=$TOOLCHAIN_PATH/bin +mkdir -p $DEST && +run $TOOLCHAIN_PREFIX-objcopy --strip-unneeded $BUILD_OUT/gdbserver $TOOLCHAIN_PATH/bin/gdbserver +if [ $? != 0 ] ; then + dump "Could not install gdbserver. See $TMPLOG" + exit 1 +fi + +dump "Done." +if [ -n "$OPTION_BUILD_OUT" ] ; then + rm -rf $BUILD_OUT +fi diff --git a/build/tools/build-toolchain.sh b/build/tools/build-toolchain.sh deleted file mode 100755 index 6826a78ba..000000000 --- a/build/tools/build-toolchain.sh +++ /dev/null @@ -1,675 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2009 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 rebuild the Android NDK's prebuilt binaries. -# -# The source tarballs must be located in $ANDROID_NDK_ROOT/build/archive -# They will be located in $ANDROID_NDK_ROOT/build/toolchain after compilation -# - -# include common function and variable definitions -. `dirname $0`/../core/ndk-common.sh - -print_help() { - echo "Rebuild the prebuilt binaries for the Android NDK toolchain." - 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 "See build/tools/download-toolchain-sources.sh for a tool that" - echo "can create a compatible source package from the current" - echo "git repositories." - echo "" - echo "options (defaults are within brackets):" - echo "" - echo " --help print this message" - echo " --gcc-version=<version> select GCC version [$GCC_VERSION]" - echo " --gdb-version=<version> select GDB version [$GDB_VERSION]" - echo " --package=<file> specify download source package" - echo " --platform=<name> generate toolchain from platform <name> [$PLATFORM]" - echo " --build-toolchains=<tc> Only build these toolchains (specifiy multiple times)" - echo " --abi=<name> generate toolchain from abi <name> [$ABI]" - echo " --release=<name> specify prebuilt release name [$RELEASE]" - echo " --build-out=<path> set temporary build out directory [/tmp/<random>]" - echo " --force-download force a download and unpacking of the toolchain sources" - echo " --force-build force a rebuild of the sources" - echo "" -} - -# number of jobs to run in parallel when running make -JOBS=$HOST_NUM_CPUS - -PLATFORM=android-3 -ABI=arm -GCC_VERSION=4.2.1 -GDB_VERSION=6.6 -BINUTILS_VERSION=2.17 -RELEASE=`date +%Y%m%d` -BUILD_OUT=`mktemp -d /tmp/ndk-toolchain-XXX` - -OPTION_HELP=no -OPTION_PLATFORM= -OPTION_FORCE_32=no -OPTION_FORCE_BUILD=no -OPTION_GCC_VERSION= -OPTION_GDB_VERSION= -OPTION_PACKAGE= -OPTION_RELEASE= -OPTION_BUILD_OUT= -OPTION_BUILD_TOOLCHAINS= - -VERBOSE=no -for opt do - optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` - case "$opt" in - --help|-h|-\?) OPTION_HELP=yes - ;; - --verbose) - if [ "$VERBOSE" = "yes" ] ; then - VERBOSE2=yes - else - VERBOSE=yes - fi - ;; - --gcc-version=*) - OPTION_GCC_VERSION=$optarg - ;; - --gdb-version=*) - OPTION_GDB_VERSION=$optarg - ;; - --package=*) - OPTION_PACKAGE="$optarg" - ;; - --platform=*) - PLATFORM=$optarg - ;; - --build-out=*) - OPTION_BUILD_OUT="$optarg" - ;; - --abi=*) - ABI=$optarg - ;; - --release=*) - OPTION_RELEASE=$optarg - ;; - --force-download) - OPTION_FORCE_DOWNLOAD=yes - OPTION_FORCE_BUILD=yes - ;; - --force-build) - OPTION_FORCE_BUILD=yes - ;; - --build-toolchains=*) - OPTION_BUILD_TOOLCHAINS="$OPTION_BUILD_TOOLCHAINS $optarg" - ;; - --verbose) - VERBOSE=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 - -case "$ABI" in -arm ) - ARCH="arm" - ABI_INSTALL_NAME="arm-eabi" - ABI_TOOLCHAIN_PREFIX="arm-eabi" - ABI_CONFIGURE_HOST="arm-eabi-linux" - ;; -x86 ) - ARCH="x86" - ABI_INSTALL_NAME="x86" - ABI_TOOLCHAIN_PREFIX="i686-android-linux-gnu" - ABI_CONFIGURE_HOST="i686-linux" - ;; -* ) - echo "Invalid ABI specified ($ABI). Expected [arm | x86]" - echo - print_help - exit 1 - ;; -esac - -setup_log_file - -if [ -n "$OPTION_GCC_VERSION" ] ; then - GCC_VERSION="$OPTION_GCC_VERSION" - log "Using gcc version $GCC_VERSION" -else - log "Using default gcc version $GCC_VERSION" -fi - -if [ -n "$OPTION_GDB_VERSION" ] ; then - GDB_VERSION="$OPTION_GDB_VERSION" - log "Using gdb version $GDB_VERSION" -else - log "Using default gdb version $GDB_VERSION" -fi - -if [ -n "$OPTION_RELEASE" ] ; then - RELEASE="$RELEASE" - log "Using toolchain release name '$RELEASE'" -else - log "Using default toolchain name '$RELEASE'" -fi - -if [ -n "$OPTION_PACKAGE" ] ; then - if [ ! -f "$OPTION_PACKAGE" ] ; then - echo "Package is not a file: $OPTION_PACKAGE" - exit 1 - fi -fi - -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 - -ANDROID_NDK_ROOT=`cd $ANDROID_NDK_ROOT && pwd` -ANDROID_NDK_ARCHIVE=$ANDROID_NDK_ROOT/build/toolchains/archive -ANDROID_PLATFORMS_ROOT=$ANDROID_NDK_ROOT/build/platforms - -# where all generated files will be placed -OUT=$BUILD_OUT -PACKAGE_OUT=$OUT/packages -TIMESTAMP_OUT=$OUT/timestamps - -# where the sysroot is located -ANDROID_TOOLCHAIN_SRC=$OUT/src -ANDROID_SYSROOT=$ANDROID_NDK_ROOT/build/platforms/$PLATFORM/arch-$ARCH - -# Check that we have md5sum to check downloaded binaries -check_md5sum - -# Do we have anything to download stuff -find_program CMD_WGET wget -find_program CMD_CURL curl -find_program CMD_SCP scp - -timestamp_check () -{ - [ -f $TIMESTAMP_OUT/$1/timestamp-$2 ] -} - -timestamp_set () -{ - mkdir -p $TIMESTAMP_OUT/$1 - touch $TIMESTAMP_OUT/$1/timestamp-$2 -} - -timestamp_clear () -{ - rm -f $TIMESTAMP_OUT/$1/timestamp-* -} - -timestamp_force () -{ - rm -f $TIMESTAMP_OUT/$1/timestamp-$2 -} - -# this function will be used to download and verify a toolchain -# package. -# -# $1: directory name under build/archive (e.g. 'toolchain') -# -download_package () -{ - WORKSPACE=$ANDROID_NDK_ARCHIVE/$1 - if [ ! -d $WORKSPACE ] ; then - dump "No directory named $1 under $ANDROID_NDK_ARCHIVE" - exit 2 - fi - SOURCES=$WORKSPACE/sources.txt - if [ ! -f $SOURCES ] ; then - dump "Missing sources.txt in $WORKSPACE" - exit 2 - fi - # First line must be file name - PKGNAME=`cat $SOURCES | sed 1q` - # Second line must be md5sum - PKGSUM=`cat $SOURCES | sed 1d | sed 1q` - if [ -z "$PKGNAME" -o -z "$PKGSUM" ] ; then - dump "Corrupted file: $SOURCES" - exit 2 - fi - - # Try to download the package if it is not there - # the Third line of sources.txt, and all others behind - # must be wget urls or something. - PACKAGE_TARBALL=$PACKAGE_OUT/$PKGNAME - if [ ! -f $PACKAGE_TARBALL ] ; then - cat $SOURCES | sed 1,2d | while read src; do - echo $src | grep -q -e "^/.*" - if [ $? = 0 ] ; then - if [ -f $src ] ; then - dump "Copy : $PKGNAME" - dump " from `dirname $src`" - dump " into $PACKAGE_TARBALL" - run cp -f $src $PACKAGE_TARBALL - if [ $? = 0 ] ; then - break - fi - dump "Copy : Problem copying from $src" - else - dump "Copy : Can't find $src (skipping)" - fi - continue - fi - echo $src | grep -q -e "^\(http\|https\|ftp\|ssh\):.*" - if [ $? = 0 ] ; then - dump "Download: $PKGNAME" - dump " from $src" - dump " into $PACKAGE_TARBALL" - download_file $src $PACKAGE_TARBALL - if [ $? = 0 ] ; then - break - fi - continue - else - dump "Copy : Unknown method in $src" - fi - done - if [ ! -f $PACKAGE_TARBALL ] ; then - dump "ERROR: Could not copy or download $PKGNAME !" - dump "Your probably need to edit $WORKSPACE/sources.txt" - exit 1 - fi - fi - - if ! timestamp_check $1 verify ; then - SUM=`md5sum $PACKAGE_TARBALL | cut -d " " -f 1` - if [ "$SUM" != "$PKGSUM" ] ; then - 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 - - dump "Verified: $PACKAGE_TARBALL" - timestamp_set $1 verify - timestamp_force $1 unpack - fi - eval PKG_$1=$PACKAGE_TARBALL -} - -# Unpack a given package in a target location -# $1: package name (e.g. toolchain) -# $2: target directory (e.g. /tmp/foo) -# -unpack_package () -{ - SRCPKG=`var_value PKG_$1` - SRCDIR=$2 - if ! timestamp_check $1 unpack; then - dump "Unpack : $1 sources" - dump " from $SRCPKG" - dump " into $SRCDIR" - run rm -rf $SRCDIR - run mkdir -p $SRCDIR - TARFLAGS=xjf - if [ $VERBOSE2 = yes ]; then - TARFLAGS="v$TARFLAGS" - fi - run tar $TARFLAGS $SRCPKG -C $SRCDIR - if [ $? != 0 ] ; then - dump "ERROR: Could not unpack $1, See $TMPLOG" - exit 1 - fi - timestamp_set $1 unpack - timestamp_force $1 patch - fi -} - -# Patch a given package at a target location -# $1: package name (e.g. toolchain) -# $2: target directory (e.g. /tmp/foo) -# $3: patch directory (e.g. build/tools/toolchain-patches) -# -# The rationale here is that anything named like $3/<subpath>/<foo>.patch -# will be applied with "patch -p1" under $2/<subpath> -# -# Patches are listed and applied in alphanumerical order of their names -# as returned by 'find'. Consider using numbered prefixes like the patch -# files generated by "git format-patch" are named. -# -patch_package () -{ - SRCPKG=`var_value PKG_$1` - SRCDIR=$2 - if ! timestamp_check $1 patch; then - PATCH_FILES=`(cd $3 && find . -name "*.patch") 2> /dev/null` - if [ -z "$PATCH_FILES" ] ; then - dump "Patch : none provided" - return - fi - for PATCH in $PATCH_FILES; do - 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 - dump "Patch failure !! Please check toolchain package !" - exit 1 - fi - done - timestamp_set $1 patch - timestamp_force $1 configure - fi -} - -if [ $OPTION_FORCE_DOWNLOAD ] ; then - run rm -rf $PACKAGE_OUT $ANDROID_TOOLCHAIN_SRC - timestamp_force toolchain unpack - timestamp_force toolchain verify -fi - -if [ $OPTION_FORCE_BUILD = "yes" ] ; then - run rm -rf $ANDROID_TOOLCHAIN_BUILD - timestamp_clear toolchain - timestamp_clear gdbserver -fi - -# checks, we need more checks.. -run mkdir -p $PACKAGE_OUT -if [ $? != 0 ] ; then - echo "Can't create download/archive directory for toolchain tarballs" - exit 2 -fi - -if [ -n "$OPTION_PACKAGE" ] ; then - PKG_toolchain="$OPTION_PACKAGE" -else - download_package toolchain -fi - -unpack_package toolchain $ANDROID_TOOLCHAIN_SRC -patch_package toolchain $ANDROID_TOOLCHAIN_SRC $ANDROID_NDK_ROOT/build/tools/toolchain-patches - -# remove all info files from the unpacked toolchain sources -# they create countless little problems during the build -# if you don't have exactly the configuration expected by -# the scripts. -# -find $ANDROID_TOOLCHAIN_SRC -type f -a -name "*.info" -print0 | xargs -0 rm -f - - -# Setup variables to properly build a new toolchain -# $1: toolchain name, e.g. arm-eabi-4.2.1 -build_toolchain () -{ - TOOLCHAIN_NAME=$1 - - # where the toolchain is going to be built - TOOLCHAIN_BUILD=$OUT/$TOOLCHAIN_NAME - - # where the gdbserver binaries will be placed - GDBSERVER_BUILD=$TOOLCHAIN_BUILD/gdbserver - - TOOLCHAIN_SRC=$ANDROID_TOOLCHAIN_SRC - TOOLCHAIN_PREFIX=$OUT/build/prebuilt/$HOST_TAG/$TOOLCHAIN_NAME - TOOLCHAIN_LICENSES=$ANDROID_NDK_ROOT/build/tools/toolchain-licenses - - # configure the toolchain - if ! timestamp_check $TOOLCHAIN_NAME configure; then - 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 - # this. - BUILD_SRCDIR=$TOOLCHAIN_SRC/build - if [ ! -d $BUILD_SRCDIR ] ; then - BUILD_SRCDIR=$TOOLCHAIN_SRC - fi - OLD_ABI="${ABI}" - OLD_CFLAGS="$CFLAGS" - OLD_LDFLAGS="$LDFLAGS" - mkdir -p $TOOLCHAIN_BUILD && - cd $TOOLCHAIN_BUILD && - export ABI="32" && # needed to build a 32-bit gmp - export CFLAGS="$HOST_CFLAGS" && - export LDFLAGS="$HOST_LDFLAGS" && run \ - $BUILD_SRCDIR/configure --target=$ABI_TOOLCHAIN_PREFIX \ - --disable-nls \ - --prefix=$TOOLCHAIN_PREFIX \ - --with-sysroot=$ANDROID_SYSROOT \ - --with-binutils-version=$BINUTILS_VERSION \ - --with-gcc-version=$GCC_VERSION \ - --with-gdb-version=$GDB_VERSION - if [ $? != 0 ] ; then - dump "Error while trying to configure toolchain build. See $TMPLOG" - exit 1 - fi - ABI="$OLD_ABI" - CFLAGS="$OLD_CFLAGS" - LDFLAGS="$OLD_LDFLAGS" - timestamp_set $TOOLCHAIN_NAME configure - timestamp_force $TOOLCHAIN_NAME build - fi - - # build the toolchain - if ! timestamp_check $TOOLCHAIN_NAME build ; then - dump "Building : $TOOLCHAIN_NAME toolchain [this can take a long time]." - OLD_CFLAGS="$CFLAGS" - OLD_LDFLAGS="$LDFLAGS" - OLD_ABI="$ABI" - cd $TOOLCHAIN_BUILD && - export CFLAGS="$HOST_CFLAGS" && - export LDFLAGS="$HOST_LDFLAGS" && - export ABI="32" && - run make -j$JOBS - if [ $? != 0 ] ; then - echo "Error while building toolchain. See $TMPLOG" - exit 1 - fi - CFLAGS="$OLD_CFLAGS" - LDFLAGS="$OLD_LDFLAGS" - ABI="$OLD_ABI" - timestamp_set $TOOLCHAIN_NAME build - timestamp_force $TOOLCHAIN_NAME install - fi - - # install the toolchain to its final location - if ! timestamp_check $TOOLCHAIN_NAME install ; then - dump "Install : $TOOLCHAIN_NAME toolchain binaries." - cd $TOOLCHAIN_BUILD && - run make install - if [ $? != 0 ] ; then - echo "Error while installing toolchain. See $TMPLOG" - exit 1 - fi - # don't forget to copy the GPL and LGPL license files - cp -f $TOOLCHAIN_LICENSES/COPYING $TOOLCHAIN_LICENSES/COPYING.LIB $TOOLCHAIN_PREFIX - # remove some unneeded files - rm -f $TOOLCHAIN_PREFIX/bin/*-gccbug - rm -rf $TOOLCHAIN_PREFIX/man $TOOLCHAIN_PREFIX/info - # strip binaries to reduce final package size - strip $TOOLCHAIN_PREFIX/bin/* - strip $TOOLCHAIN_PREFIX/$ABI_TOOLCHAIN_PREFIX/bin/* - strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/cc1 - strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/cc1plus - strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/collect2 - timestamp_set $TOOLCHAIN_NAME install - timestamp_force $TOOLCHAIN_NAME-gdbserver configure - fi - - # configure the gdbserver build now - if ! timestamp_check $TOOLCHAIN_NAME-gdbserver configure; then - 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. - GDB_SRCDIR=$TOOLCHAIN_SRC/gdb/gdb-$GDB_VERSION - if [ ! -d $GDB_SRCDIR ] ; then - GDB_SRCDIR=$TOOLCHAIN_SRC/gdb-$GDB_VERSION - fi - run mkdir -p $GDBSERVER_BUILD - OLD_CC="$CC" - OLD_CFLAGS="$CFLAGS" - OLD_LDFLAGS="$LDFLAGS" - - INCLUDE_DIRS="-I$TOOLCHAIN_PREFIX/lib/gcc/$ABI_TOOLCHAIN_PREFIX/$GCC_VERSION/include \ - -I$ANDROID_SYSROOT/usr/include" - CRTBEGIN="$ANDROID_SYSROOT/usr/lib/crtbegin_static.o" - CRTEND="$ANDROID_SYSROOT/usr/lib/crtend_android.o" - LIBRARY_LDFLAGS="$CRTBEGIN -L$ANDROID_SYSROOT/usr/lib -lc -L$ANDROID_SYSROOT/usr/lib -lm -lgcc $CRTEND " - - cd $GDBSERVER_BUILD && - export CC="$TOOLCHAIN_PREFIX/bin/$ABI_TOOLCHAIN_PREFIX-gcc" && - export CFLAGS="-O2 -nostdinc -nostdlib -D__ANDROID__ -DANDROID -DSTDC_HEADERS $INCLUDE_DIRS" && - export LDFLAGS="-static -Wl,-z,nocopyreloc -Wl,--no-undefined $LIBRARY_LDFLAGS" && - run $GDB_SRCDIR/gdb/gdbserver/configure \ - --host=${ABI_CONFIGURE_HOST} \ - --with-sysroot=$ANDROID_SYSROOT - if [ $? != 0 ] ; then - dump "Could not configure gdbserver build. See $TMPLOG" - exit 1 - fi - CC="$OLD_CC" - CFLAGS="$OLD_CFLAGS" - LDFLAGS="$OLD_LDFLAGS" - timestamp_set $TOOLCHAIN_NAME-gdbserver configure - timestamp_force $TOOLCHAIN_NAME-gdbserver build - fi - - # build gdbserver - if ! timestamp_check $TOOLCHAIN_NAME-gdbserver build; then - dump "Building : $TOOLCHAIN_NAME gdbserver." - cd $GDBSERVER_BUILD && - run make -j$JOBS - if [ $? != 0 ] ; then - dump "Could not build $TOOLCHAIN_NAME gdbserver. See $TMPLOG" - exit 1 - fi - timestamp_set $TOOLCHAIN_NAME-gdbserver build - timestamp_force $TOOLCHAIN_NAME-gdbserver install - fi - - # install gdbserver - # - # note that we install it in the toolchain bin directory - # not in $SYSROOT/usr/bin - # - if ! timestamp_check $TOOLCHAIN_NAME-gdbserver install; then - 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 - dump "Could not install gdbserver. See $TMPLOG" - exit 1 - fi - timestamp_set $TOOLCHAIN_NAME-gdbserver install - timestamp_force package toolchain - fi -} - -# Look at the toolchains available from the source package -# -# The old source tarball only contained gcc 4.2.1, the new -# ones contain multiple toolchains -# -if [ "$OPTION_BUILD_TOOLCHAINS" ]; then - ANDROID_TOOLCHAIN_LIST="$OPTION_BUILD_TOOLCHAINS" -else - ANDROID_TOOLCHAIN_LIST=`ls -1 $ANDROID_TOOLCHAIN_SRC/gcc | grep gcc- | sed "s/gcc-/${ABI_INSTALL_NAME}-/"` -fi - -for _toolchain in $ANDROID_TOOLCHAIN_LIST; do - if [ $OPTION_FORCE_BUILD = "yes" ] ; then - timestamp_force ${_toolchain} configure - timestamp_force ${_toolchain}-gdbserver configure - fi - case "${_toolchain}" in - x86-4.2.1 ) - GCC_VERSION=4.2.1 - BINUTILS_VERSION=2.19 - ;; - arm*-4.2.1 ) - GCC_VERSION=4.2.1 - BINUTILS_VERSION=2.17 - ;; - x86-4.4.0 ) - GCC_VERSION=4.4.0 - BINUTILS_VERSION=2.19 - ;; - arm*-4.4.0 ) - GCC_VERSION=4.4.0 - BINUTILS_VERSION=2.19 - ;; - esac - build_toolchain ${_toolchain} -done - -# package the toolchain -TOOLCHAIN_TARBALL=/tmp/android-ndk-prebuilt-$RELEASE-$HOST_TAG.tar.bz2 -if ! timestamp_check package toolchain; then - 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 - TARFLAGS="v$TARFLAGS" - fi - TOOLCHAIN_SRC_DIRS= - for _toolchain in $ANDROID_TOOLCHAIN_LIST; do - TOOLCHAIN_SRC_DIRS="$TOOLCHAIN_SRC_DIRS build/prebuilt/$HOST_TAG/${_toolchain}" - done - run tar $TARFLAGS $TOOLCHAIN_TARBALL -C $OUT $TOOLCHAIN_SRC_DIRS - if [ $? != 0 ] ; then - dump "ERROR: Cannot package prebuilt toolchain binaries. See $TMPLOG" - exit 1 - fi - timestamp_set package toolchain - dump "prebuilt toolchain is in $TOOLCHAIN_TARBALL" -else - dump "prebuilt toolchain is in $TOOLCHAIN_TARBALL" -fi - -if [ -z "$OPTION_BUILD_OUT" ] ; then - dump "Cleaning temporary directory $OUT" - rm -rf $OUT -else - dump "Don't forget to clean build directory $OUT" -fi - -dump "Done." -rm -f $TMPLOG diff --git a/build/tools/download-toolchain-sources.sh b/build/tools/download-toolchain-sources.sh index 420ef671b..52d1a2130 100755 --- a/build/tools/download-toolchain-sources.sh +++ b/build/tools/download-toolchain-sources.sh @@ -20,83 +20,43 @@ # # include common function and variable definitions -. `dirname $0`/../core/ndk-common.sh +. `dirname $0`/prebuilt-common.sh OPTION_HELP=no OPTION_RELEASE= OPTION_GIT= OPTION_BRANCH= +OPTION_PACKAGE=no # the default release name (use today's date) RELEASE=`date +%Y%m%d` # the default branch to use BRANCH=master - GITCMD=git -VERBOSE=no -VERBOSE2=no - -for opt do - optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` - case "$opt" in - --help|-h|-\?) OPTION_HELP=yes - ;; - --branch=*) - OPTION_BRANCH="$optarg" - ;; - --git=*) - OPTION_GIT="$optarg" - ;; - --verbose) - if [ "$VERBOSE" = "yes" ] ; then - VERBOSE2=yes - else - VERBOSE=yes - fi - ;; - --release=*) - OPTION_RELEASE=$optarg - ;; - *) - echo "unknown option '$opt', use --help" - exit 1 - esac -done - -if [ $OPTION_HELP = "yes" ] ; then - echo "Download the NDK toolchain sources from android.git.kernel.org and package them." - echo "You will need to run this script before being able to rebuild the NDK toolchain" - echo "binaries from scratch with build/tools/build-toolchain.sh" - echo "" - echo "options (defaults in brackets):" - echo "" - echo " --help print this message" - echo " --branch=<name> specify release branch [$BRANCH]" - echo " --release=<name> specify release name [$RELEASE]" - echo " --git=<executable> use this version of the git tool [$GITCMD]" - echo " --verbose increase verbosity" - echo "" - exit 0 -fi +register_option "--branch=<name>" do_branch "Specify release branch" $BRANCH +register_option "--release=<name>" do_release "Specify release name" $RELEASE +register_option "--git=<executable>" do_git "Use this version of the git tool" $GITCMD +register_option "--package" do_package "Create source package in /tmp" -setup_log_file () +do_branch () { OPTION_BRANCH=$1; } +do_release () { OPTION_RELEASE=$1; } +do_git () { OPTION_GIT=$1; } +do_package () { OPTION_PACKAGE=yes; } -if [ -n "$OPTION_RELEASE" ] ; then - RELEASE="$OPTION_RELEASE" - log "Using release name $RELEASE" -else - log "Using default release name $RELEASE" -fi +PROGRAM_PARAMETERS="<src-dir>" +PROGRAM_DESCRIPTION=\ +"Download the NDK toolchain sources from android.git.kernel.org into <src-dir>. +You will need to run this script before being able to rebuilt the NDK toolchain +binaries from scratch with build/tools/build-gcc.sh." + +extract_parameters $@ + +fix_option RELEASE "$OPTION_RELEASE" "release name" # Check that 'git' works -if [ -n "$OPTION_GIT" ] ; then - GITCMD="$OPTION_GIT" - log "Using git tool command: '$GITCMD'" -else - log "Using default git tool command." -fi +fix_option GITCMD "$OPTION_GIT" "git too command" $GITCMD --version > /dev/null 2>&1 if [ $? != 0 ] ; then echo "The git tool doesn't seem to work. Please check $GITCMD" @@ -104,14 +64,19 @@ if [ $? != 0 ] ; then fi log "Git seems to work ok." -if [ -n "$OPTION_BRANCH" ] ; then - BRANCH="$OPTION_BRANCH" - log "Using branch named $BRANCH" -else - log "Using default branch name $BRANCH" +fix_option BRANCH "$OPTION_BRANCH" "branch name" + +SRC_DIR=$PARAMETERS +if [ -z "$SRC_DIR" -a $OPTION_PACKAGE = no ] ; then + echo "ERROR: You need to provide a <src-dir> parameter or use the --package option!" + exit 1 fi -# Create temp directory where everything will be copied +mkdir -p $SRC_DIR +SRC_DIR=`cd $SRC_DIR && pwd` +log "Using target source directory: $SRC_DIR" + +# Create temp directory where everything will be copied first # PKGNAME=android-ndk-toolchain-$RELEASE TMPDIR=/tmp/$PKGNAME @@ -148,7 +113,6 @@ toolchain_clone () run rm -rf $1/.git } - cd $TMPDIR toolchain_clone binutils toolchain_clone build @@ -165,15 +129,45 @@ log "getting rid of obsolete sources: gcc-4.3.1 gdb-6.8" rm -rf $TMPDIR/gcc/gcc-4.3.1 rm -rf $TMPDIR/gcc/gdb-6.8 -# create the package -PACKAGE=/tmp/$PKGNAME.tar.bz2 -dump "Creating package archive $PACKAGE" -cd `dirname $TMPDIR` -run tar cjvf $PACKAGE -C /tmp/$PKGNAME . -if [ $? != 0 ] ; then - dump "Could not package toolchain source archive ?. See $TMPLOG" - exit 1 +# remove all info files from the toolchain sources +# they create countless little problems during the build +# if you don't have exactly the configuration expected by +# the scripts. +# +find $TMPDIR -type f -a -name "*.info" -print0 | xargs -0 rm -f + +if [ $OPTION_PACKAGE = "yes" ] ; then + # create the package + PACKAGE=/tmp/$PKGNAME.tar.bz2 + dump "Creating package archive $PACKAGE" + cd `dirname $TMPDIR` + TARFLAGS="cjf" + if [ $VERBOSE = yes ] ; then + TARFLAGS="${TARFLAGS}v" + fi + run tar $TARFLAGS $PACKAGE -C /tmp/$PKGNAME . + if [ $? != 0 ] ; then + dump "Could not package toolchain source archive ?. See $TMPLOG" + exit 1 + fi + dump "Toolchain sources downloaded and packaged succesfully at $PACKAGE" +else + # copy sources to <src-dir> + SRC_DIR=`cd $SRC_DIR && pwd` + rm -rf $SRC_DIR && mkdir -p $SRC_DIR + if [ $? != 0 ] ; then + dump "ERROR: Could not create target source directory: $SRC_DIR" + exit 1 + fi + run cd $TMPDIR && run cp -rp * $SRC_DIR + if [ $? != 0 ] ; then + dump "ERROR: Could not copy downloaded sources to: $SRC_DIR" + exit 1 + fi + dump "Toolchain sources downloaded and copied to $SRC_DIR" fi -dump "Toolchain sources downloaded and packaged succesfully at $PACKAGE" +dump "Cleaning up..." +rm -rf $TMPDIR rm -f $TMPLOG +dump "Done." diff --git a/build/tools/make-release.sh b/build/tools/make-release.sh index a74cfb3e4..833717eda 100755 --- a/build/tools/make-release.sh +++ b/build/tools/make-release.sh @@ -92,7 +92,7 @@ if [ $OPTION_HELP = yes ] ; then echo "Alternatively, you can use --prebuilt-ndk=<file> where <file> is the" echo "path to a previous official NDK release package. It will be used to" echo "extract the toolchain binaries and copy them to your new release." - echo "Only use this for experimental release packages !" + echo "Only use this for experimental release packages!" echo "" echo "The generated release packages will be stored in a temporary directory" echo "that will be printed at the end of the generation process." diff --git a/build/tools/patch-sources.sh b/build/tools/patch-sources.sh new file mode 100755 index 000000000..7376880b8 --- /dev/null +++ b/build/tools/patch-sources.sh @@ -0,0 +1,77 @@ +#!/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. +# + +# Script used to patch a source directory from a series of patches +# located under a directory hierarchy + +. `dirname $0`/prebuilt-common.sh + +PROGRAM_PARAMETERS="<src-dir> <patches-dir>" +PROGRAM_DESCRIPTION=\ +"Patch a target source directory with a series of patches taken +from another directory hierarchy. The idea is that anything that +is found under <patches-dir>/subdir/foo.patch will be applied with +'patch -p1' in <src-dir>/subdir. + +Patches are applied in the order they are found by 'find'." + +parse_parameters () +{ + SRC_DIR=$1 + if [ -z "$SRC_DIR" ] ; then + echo "ERROR: Missing source directory. See --help for usage." + exit 1 + fi + + if [ ! -d "$SRC_DIR" ] ; then + echo "ERROR: Invalid target source directory: $SRC_DIR" + exit 1 + fi + + PATCHES_DIR=$2 + if [ -z "$PATCHES_DIR" ] ; then + echo "ERROR: Missing patches directory. See --help for usage." + exit 1 + fi + + if [ ! -d "$PATCHES_DIR" ] ; then + echo "ERROR: Invalid patches directory: $PATCHES_DIR" + exit 1 + fi +} + +extract_parameters $@ +parse_parameters $PARAMETERS + +PATCHES=`(cd $PATCHES_DIR && find . -name "*.patch") 2> /dev/null` +if [ -z "$PATCHES" ] ; then + log "No patches files in $PATCHES_DIR" + exit 0 +fi +PATCHES=`echo $PATCHES | sed -e s%^\./%%g` +for PATCH in $PATCHES; do + PATCHDIR=`dirname $PATCH` + PATCHNAME=`basename $PATCH` + log "Applying $PATCHNAME into $SRC_DIR/$PATCHDIR" + cd $SRC_DIR/$PATCHDIR && patch -p1 < $ANDROID_NDK_ROOT/$PATCHES_DIR/$PATCH + if [ $? != 0 ] ; then + dump "ERROR: Patch failure !! Please check your patches directory!" + exit 1 + fi +done + +dump "Done!" diff --git a/build/tools/prebuilt-common.sh b/build/tools/prebuilt-common.sh new file mode 100644 index 000000000..073f4528a --- /dev/null +++ b/build/tools/prebuilt-common.sh @@ -0,0 +1,426 @@ +# Common functions for all prebuilt-related scripts +# This is included/sourced by other scripts +# + +. `dirname $0`/../core/ndk-common.sh + +#==================================================== +# +# UTILITY FUNCTIONS +# +#==================================================== + +# Return the maximum length of a series of strings +# +# Usage: len=`max_length <string1> <string2> ...` +# +max_length () +{ + echo "$@" | tr ' ' '\n' | awk 'BEGIN {max=0} {len=length($1); if (len > max) max=len} END {print max}' +} + +# Translate dashes to underscores +# Usage: str=`dashes_to_underscores <values>` +dashes_to_underscores () +{ + echo $@ | tr '-' '_' +} + +# Translate underscores to dashes +# Usage: str=`underscores_to_dashes <values>` +underscores_to_dashes () +{ + echo $@ | tr '_' '-' +} + +#==================================================== +# +# OPTION PROCESSING +# +#==================================================== + +# We recognize the following option formats: +# +# -f +# --flag +# +# -s<value> +# --setting=<value> +# + +# NOTE: We translate '-' into '_' when storing the options in global variables +# + +OPTIONS="" +OPTION_FLAGS="" +OPTION_SETTINGS="" + +# Set a given option attribute +# $1: option name +# $2: option attribute +# $3: attribute value +# +option_set_attr () +{ + eval OPTIONS_$1_$2=\"$3\" +} + +# Get a given option attribute +# $1: option name +# $2: option attribute +# +option_get_attr () +{ + echo `var_value OPTIONS_$1_$2` +} + +# Register a new option +# $1: option +# $2: name of function that will be called when the option is parsed +# $3: small abstract for the option +# $4: optional. default value +# +register_option () +{ + local optname optvalue opttype optlabel + optlabel= + optname= + optvalue= + opttype= + while [ -n "1" ] ; do + # Check for something like --setting=<value> + echo "$1" | grep -q -E -e '^--[^=]+=<.+>$' + if [ $? = 0 ] ; then + optlabel=`expr -- "$1" : '\(--[^=]*\)=.*'` + optvalue=`expr -- "$1" : '--[^=]*=\(<.*>\)'` + opttype="long_setting" + break + fi + + # Check for something like --flag + echo "$1" | grep -q -E -e '^--[^=]+$' + if [ $? = 0 ] ; then + optlabel="$1" + opttype="long_flag" + break + fi + + # Check for something like -f<value> + echo "$1" | grep -q -E -e '^-[A-Za-z0-9]<.+>$' + if [ $? = 0 ] ; then + optlabel=`expr -- "$1" : '\(-.\).*'` + optvalue=`expr -- "$1" : '-.\(<.+>\)'` + opttype="short_setting" + break + fi + + # Check for something like -f + echo "$1" | grep -q -E -e '^-.$' + if [ $? = 0 ] ; then + optlabel="$1" + opttype="short_flag" + break + fi + + echo "ERROR: Invalid option format: $1" + echo " Check register_option call" + exit 1 + done + + log "new option: type='$opttype' name='$optlabel' value='$optvalue'" + + optname=`dashes_to_underscores $optlabel` + OPTIONS="$OPTIONS $optname" + OPTIONS_TEXT="$OPTIONS_TEXT $1" + option_set_attr $optname label "$optlabel" + option_set_attr $optname otype "$opttype" + option_set_attr $optname value "$optvalue" + option_set_attr $optname text "$1" + option_set_attr $optname funcname "$2" + option_set_attr $optname abstract "$3" + option_set_attr $optname default "$4" +} + +# Print the help, including a list of registered options for this program +# Note: Assumes PROGRAM_PARAMETERS and PROGRAM_DESCRIPTION exist and +# correspond to the parameters list and the program description +# +print_help () +{ + local opt text abstract default + + echo "Usage: $PROGNAME [options] $PROGRAM_PARAMETERS" + echo "" + if [ -n "$PROGRAM_DESCRIPTION" ] ; then + echo "$PROGRAM_DESCRIPTION" + echo "" + fi + echo "Valid options (defaults are in brackets):" + echo "" + + maxw=`max_length "$OPTIONS_TEXT"` + AWK_SCRIPT=`echo "{ printf \"%-${maxw}s\", \\$1 }"` + for opt in $OPTIONS; do + text=`option_get_attr $opt text | awk "$AWK_SCRIPT"` + abstract=`option_get_attr $opt abstract` + default=`option_get_attr $opt default` + if [ -n "$default" ] ; then + echo " $text $abstract [$default]" + else + echo " $text $abstract" + fi + done + echo "" +} + +option_panic_no_args () +{ + echo "ERROR: Option '$1' does not take arguments. See --help for usage." + exit 1 +} + +option_panic_missing_arg () +{ + echo "ERROR: Option '$1' requires an argument. See --help for usage." + exit 1 +} + +extract_parameters () +{ + local opt optname otype value name fin funcname + PARAMETERS="" + while [ -n "$1" ] ; do + # If the parameter does not begin with a dash + # it is not an option. + param=`expr -- "$1" : '^\([^-].*\)$'` + if [ -n "$param" ] ; then + if [ -z "$PARAMETERS" ] ; then + PARAMETERS="$1" + else + PARAMETERS="$PARAMETERS $1" + fi + shift + continue + fi + + while [ -n "1" ] ; do + # Try to match a long setting, i.e. --option=value + opt=`expr -- "$1" : '^\(--[^=]*\)=.*$'` + if [ -n "$opt" ] ; then + otype="long_setting" + value=`expr -- "$1" : '^--[^=]*=\(.*\)$'` + break + fi + + # Try to match a long flag, i.e. --option + opt=`expr -- "$1" : '^\(--.*\)$'` + if [ -n "$opt" ] ; then + otype="long_flag" + value= + break + fi + + # Try to match a short setting, i.e. -o<value> + opt=`expr -- "$1" : '^\(-[A-Za-z0-9]\)..*$'` + if [ -n "$opt" ] ; then + otype="short_setting" + value=`expr -- "$1" : '^-.\(.*\)$'` + break + fi + + # Try to match a short flag, i.e. -o + opt=`expr -- "$1" : '^\(-.\)$'` + if [ -n "$opt" ] ; then + otype="short_flag" + value= + break + fi + + echo "ERROR: Unknown option '$1'. Use --help for list of valid values." + exit 1 + done + + #echo "Found opt='$opt' otype='$otype' value='$value'" + + name=`dashes_to_underscores $opt` + found=0 + for xopt in $OPTIONS; do + if [ "$name" != "$xopt" ] ; then + continue + fi + # Check that the type is correct here + # + # This also allows us to handle -o <value> as -o<value> + # + xotype=`option_get_attr $name otype` + if [ "$otype" != "$xotype" ] ; then + case "$xotype" in + "short_flag") + option_panic_no_args $opt + ;; + "short_setting") + if [ -z "$2" ] ; then + option_panic_missing_arg $opt + fi + value="$2" + shift + ;; + "long_flag") + option_panic_no_args $opt + ;; + "long_setting") + option_panic_missing_arg $opt + ;; + esac + fi + found=1 + break + break + done + if [ "$found" = "0" ] ; then + echo "ERROR: Unknown option '$opt'. See --help for usage." + exit 1 + fi + # Launch option-specific function, value, if any as argument + eval `option_get_attr $name funcname` \"$value\" + shift + done +} + +do_option_help () +{ + print_help + exit 0 +} + +VERBOSE=no +VERBOSE2=no +do_option_verbose () +{ + if [ $VERBOSE = "yes" ] ; then + VERBOSE2=yes + else + VERBOSE=yes + fi +} + +register_option "--help" do_option_help "Print this help." +register_option "--verbose" do_option_verbose "Enable verbose mode." + +#==================================================== +# +# TOOLCHAIN AND ABI PROCESSING +# +#==================================================== + +# Determine optional variable value +# $1: final variable name +# $2: option variable name +# $3: small description for the option +fix_option () +{ + if [ -n "$2" ] ; then + eval $1="$2" + log "Using specific $3: $2" + else + log "Using default $3: `var_value $1`" + fi +} + +# Determine sysroot +# $1: Option value (or empty) +# +fix_sysroot () +{ + if [ -n "$1" ] ; then + eval SYSROOT="$1" + log "Using specified sysroot: $1" + else + SYSROOT_SUFFIX=build/platforms/$PLATFORM/arch-$ARCH + if [ -d $NDK_DIR/$SYSROOT_SUFFIX ] ; then + SYSROOT=$NDK_DIR/$SYSROOT_SUFFIX + log "Using target NDK sysroot: $SYSROOT" + else + SYSROOT=$ANDROID_NDK_ROOT/$SYSROOT_SUFFIX + log "Using install NDK sysroot: $SYSROOT" + fi + fi + + if [ ! -f $SYSROOT/usr/include/stdlib.h ] ; then + echo "ERROR: Invalid sysroot path: $SYSROOT" + echo " Use --sysroot=<path> to indicate a valid one." + exit 1 + fi +} + +prepare_host_flags () +{ + # 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 +} + +parse_toolchain_name () +{ + if [ -z "$TOOLCHAIN" ] ; then + echo "ERROR: Missing toolchain name!" + exit 1 + fi + + # Determine ABI based on toolchain name + # + case "$TOOLCHAIN" in + arm-eabi-*) + ARCH="arm" + ABI_INSTALL_NAME="arm-eabi" + ABI_TOOLCHAIN_PREFIX="arm-eabi" + ABI_CONFIGURE_HOST="arm-eabi-linux" + ;; + x86-*) + ARCH="x86" + ABI_INSTALL_NAME="x86" + ABI_TOOLCHAIN_PREFIX="i686-android-linux-gnu" + ABI_CONFIGURE_HOST="i686-linux" + PLATFORM=android-5 + ;; + * ) + echo "Invalid toolchain specified. Expected (arm-eabi-*|x86-*)" + echo "" + print_help + exit 1 + ;; + esac + + log "Targetting CPU: $ARCH" + + GCC_VERSION=`expr -- "$TOOLCHAIN" : '.*-\([0-9\.]*\)'` + log "Using GCC version: $GCC_VERSION" + +} + +set_toolchain_install () +{ + TOOLCHAIN_PATH=$1 + log "Using toolchain path: $TOOLCHAIN_PATH" + + TOOLCHAIN_PREFIX=$TOOLCHAIN_PATH/bin/$ABI_TOOLCHAIN_PREFIX + log "Using toolchain prefix: $TOOLCHAIN_PREFIX" +} + +check_toolchain_install () +{ + TOOLCHAIN_PATH=$1/build/prebuilt/$HOST_TAG/$TOOLCHAIN + if [ ! -d "$TOOLCHAIN_PATH" ] ; then + echo "ERROR: Toolchain '$TOOLCHAIN' not installed in '$NDK_DIR'!" + echo " Ensure that the toolchain has been installed there before." + exit 1 + fi + + set_toolchain_install $TOOLCHAIN_PATH +} + diff --git a/build/tools/rebuild-all-prebuilt.sh b/build/tools/rebuild-all-prebuilt.sh new file mode 100755 index 000000000..b0f19681c --- /dev/null +++ b/build/tools/rebuild-all-prebuilt.sh @@ -0,0 +1,199 @@ +#!/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. +# + +# Download and rebuild all prebuilt binaries for the Android NDK +# This includes: +# - cross toolchains (gcc, ld, gdb, etc...) +# - target-specific gdbserver +# - host ccache +# + +. `dirname $0`/prebuilt-common.sh +PROGDIR=`dirname $0` + +prepare_host_flags + +PROGRAM_PARAMETERS= +PROGRAM_DESCRIPTION=\ +"Download and rebuild from scratch all prebuilt binaries for the Android NDK." + +NDK_DIR=$ANDROID_NDK_ROOT + +register_option "--ndk-dir=<path>" do_ndk_dir "Specify target NDK directory" "$NDK_DIR" +do_ndk_dir () { OPTION_NDK_DIR=$1; } + +BUILD_DIR=`mktemp -d /tmp/ndk-prebuilt-XXX` +OPTION_BUILD_DIR= +register_option "--build-dir=<path>" do_build_dir "Specify temporary build directory" "/tmp/<random>" +do_build_dir () { OPTION_BUILD_DIR=$1; } + +GDB_VERSION=6.6 +OPTION_GDB_VERSION= +register_option "--gdb-version=<version>" do_gdb_version "Specify gdb version" "$GDB_VERSION" +do_gdb_version () { OPTION_GDB_VERSION=$1; } + +OPTION_TOOLCHAIN_SRC_PKG= +OPTION_TOOLCHAIN_SRC_DIR= +OPTION_PACKAGE= +register_option "--toolchain-src-pkg=<file>" do_toolchain_src_pkg "Use toolchain source package" +register_option "--toolchain-src-dir=<path>" do_toolchain_src_dir "Use toolchain source directory" +register_option "--package" do_toolchain_package "Package prebuilt binaries" + +do_toolchain_src_pkg () { OPTION_TOOLCHAIN_SRC_PKG=$1; } +do_toolchain_src_dir () { OPTION_TOOLCHAIN_SRC_DIR=$1; } +do_toolchain_package () { OPTION_PACKAGE=yes; } + +extract_parameters $@ + +if [ "$OPTION_PACKAGE" = yes -a -z "$OPTION_NDK_DIR" ] ; then + NDK_DIR=/tmp/ndk-prebuilt-$$ +fi + +if [ -n "$PARAMETERS" ]; then + dump "ERROR: Too many parameters. See --help for proper usage." + exit 1 +fi + +fix_option NDK_DIR "$OPTION_NDK_DIR" "target NDK directory" +fix_option BUILD_DIR "$OPTION_BUILD_DIR" "build directory" +fix_option GDB_VERSION "$OPTION_GDB_VERSION" "gdb version" + +mkdir -p $BUILD_DIR +if [ $? != 0 ] ; then + dump "ERROR: Could not create build directory: $BUILD_DIR" + exit 1 +fi + +if [ -n "$OPTION_TOOLCHAIN_SRC_DIR" ] ; then + if [ -n "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then + dump "ERROR: You can't use both --toolchain-src-dir and --toolchain-src-pkg" + exi t1 + fi + SRC_DIR=$OPTION_TOOLCHAIN_SRC_DIR + if [ ! -d $SRC_DIR/gcc ] ; then + dump "ERROR: Invalid toolchain source directory: $SRC_DIR" + exit 1 + fi +else + SRC_DIR=$BUILD_DIR/src + mkdir -p $SRC_DIR +fi + +FLAGS="" +if [ $VERBOSE2 = yes ] ; then + FLAGS="--verbose" +fi + +if [ -z "$OPTION_TOOLCHAIN_SRC_DIR" ] ; then + if [ -n "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then + # Unpack the toolchain sources + if [ ! -f "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then + dump "ERROR: Invalid toolchain source package: $OPTION_TOOLCHAIN_SRC_PKG" + exit 1 + fi + TARFLAGS="xf" + if [ $VERBOSE2 = yes ] ; then + TARFLAGS="v$TARFLAGS" + fi + if pattern_match '\.tar\.gz$' "$OPTION_TOOLCHAIN_SRC_PKG"; then + TARFLAGS="z$TARFLAGS" + fi + if pattern_match '\.tar\.bz2$' "$OPTION_TOOLCHAIN_SRC_PKG"; then + TARFLAGS="j$TARFLAGS" + fi + dump "Unpack sources from $OPTION_TOOLCHAIN_SRC_PKG" + mkdir -p $SRC_DIR && tar $TARFLAGS $OPTION_TOOLCHAIN_SRC_PKG -C $SRC_DIR + if [ $? != 0 ] ; then + dump "ERROR: Could not unpack toolchain sources!" + exit 1 + fi + else + # Download the toolchain sources + dump "Download sources from android.git.kernel.org" + $PROGDIR/download-toolchain-sources.sh $FLAGS $SRC_DIR + if [ $? != 0 ] ; then + dump "ERROR: Could not download toolchain sources!" + exit 1 + fi + fi + + # Patch the sources + PATCHES_DIR=$PROGDIR/patches + if [ -d "$PATCHES_DIR" ] ; then + $PROGDIR/patch-sources.sh $FLAGS $SRC_DIR $PATCHES_DIR + if [ $? != 0 ] ; then + dump "ERROR: Could not patch sources." + exit 1 + fi + fi + +fi # ! $TOOLCHAIN_SRC_DIR + +# Build the toolchain from sources +build_toolchain () +{ + dump "Building $1 toolchain... (this can be long)" + $PROGDIR/build-gcc.sh $FLAGS --build-out=$BUILD_DIR/toolchain-$1 $SRC_DIR $NDK_DIR $1 + if [ $? != 0 ] ; then + dump "ERROR: Could not build $1 toolchain!" + exit 1 + fi +} + +build_gdbserver () +{ + dump "Build $1 gdbserver..." + $PROGDIR/build-gdbserver.sh $FLAGS --build-out=$BUILD_DIR/gdbserver-$1 $SRC_DIR/gdb/gdb-$GDB_VERSION/gdb/gdbserver $NDK_DIR $1 + if [ $? != 0 ] ; then + dump "ERROR: Could not build $1 toolchain!" + exit 1 + fi +} + +build_toolchain arm-eabi-4.2.1 +build_gdbserver arm-eabi-4.2.1 + +build_toolchain arm-eabi-4.4.0 +build_gdbserver arm-eabi-4.4.0 + +# XXX: NOT READY YET! +# +#build_toolchain x86-4.2.1 +#build_gdbserver x86-4.2.1 + +# XXX: NOT YET NEEDED! +# +#dump "Building host ccache binary..." +#$PROGDIR/build-ccache.sh $FLAGS --build-out=$BUILD_DIR/ccache $NDK_DIR +#if [ $? != 0 ] ; then +# dump "ERROR: Could not build host ccache binary!" +# exit 1 +#fi + +if [ $OPTION_PACKAGE = yes ] ; then + RELEASE=`date +%Y%m%d` + dump "Packaging prebuilt binaries..." + PREBUILT_PACKAGE=/tmp/android-ndk-prebuilt-$RELEASE-$HOST_TAG.tar.bz2 + cd $NDK_DIR && tar cjf $PREBUILT_PACKAGE * + if [ $? != 0 ] ; then + dump "ERROR: Could not package prebuilt binaries!" + exit 1 + fi + dump "See: $PREBUILT_PACKAGE" +fi + +dump "Done!" |