aboutsummaryrefslogtreecommitdiff
path: root/build/tools
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2009-05-07 20:39:04 +0200
committerDavid 'Digit' Turner <digit@google.com>2009-05-07 20:39:04 +0200
commit48ef1859ef0bb25547e5aceeedb9b175c6193bc5 (patch)
tree9b8099893d8085154a66f006c0abfc05394f7ce5 /build/tools
parentd4d8cb949a871d8e3bc1c995f1364a99e6cc830f (diff)
downloadndk-48ef1859ef0bb25547e5aceeedb9b175c6193bc5.tar.gz
Initial import of new NDK into donut tree
Diffstat (limited to 'build/tools')
-rwxr-xr-xbuild/tools/build-ndk-sysroot.sh270
-rwxr-xr-xbuild/tools/build-toolchain.sh499
-rwxr-xr-xbuild/tools/make-previews.sh56
3 files changed, 825 insertions, 0 deletions
diff --git a/build/tools/build-ndk-sysroot.sh b/build/tools/build-ndk-sysroot.sh
new file mode 100755
index 000000000..bc39f8e64
--- /dev/null
+++ b/build/tools/build-ndk-sysroot.sh
@@ -0,0 +1,270 @@
+#!/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.
+#
+# build-ndk-sysroot.sh
+#
+# collect files from an Android tree to assemble a sysroot suitable for
+# building a standable toolchain.
+#
+# after that, you may use build/tools/package-ndk-sysroot.sh to package
+# the resulting files for distribution.
+#
+# NOTE: this is different from the Android toolchain original build-sysroot.sh
+# script because we place target files differently.
+#
+# WARNING: For now, only a single target ABI/Architecture us supported
+#
+
+source `dirname $0`/../core/ndk-common.sh
+
+# PLATFORM is the name of the current Android system platform
+PLATFORM=android-1.5
+
+# ABI is the target ABI name for the NDK
+ABI=arm
+
+# ARCH is the target ABI name in the Android sources
+ARCH=arm
+
+OPTION_HELP=no
+OPTION_BUILD_OUT=
+OPTION_PLATFORM=
+OPTION_PACKAGE=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
+ ;;
+ --platform=*)
+ OPTION_PLATFORM=$optarg
+ ;;
+ --build-out=*)
+ OPTION_BUILD_OUT=$optarg
+ ;;
+ --package)
+ OPTION_PACKAGE=yes
+ ;;
+ *)
+ echo "unknown option '$opt', use --help"
+ exit 1
+ esac
+done
+
+if [ $OPTION_HELP = "yes" ] ; then
+ echo "Collect files from an Android build tree and assembles a sysroot"
+ echo "suitable for building a standalone toolchain or be used by the"
+ echo "Android NDK."
+ echo ""
+ echo "options:"
+ echo ""
+ echo " --help print this message"
+ echo " --verbose enable verbose messages"
+ echo " --platform=<name> generate sysroot for platform <name> (default is $PLATFORM)"
+ echo " --build-out=<path> set Android build out directory"
+ echo " --package generate sysroot package tarball"
+ echo ""
+ exit 0
+fi
+
+if [ -n "$OPTION_PLATFORM" ] ; then
+ PLATFORM=$OPTION_PLATFORM
+fi
+
+# Get the root of the NDK from the current program location
+NDK_ROOT=`dirname $0`
+NDK_ROOT=`dirname $NDK_ROOT`
+NDK_ROOT=`dirname $NDK_ROOT`
+
+# Get the Android out directory
+if [ -z "$OPTION_BUILD_OUT" ] ; then
+ if [ -z "$ANDROID_PRODUCT_OUT" ] ; then
+ echo "ANDROID_PRODUCT_OUT is not defined in your environment. Aborting"
+ exit 1
+ fi
+ if [ ! -d $ANDROID_PRODUCT_OUT ] ; then
+ echo "ANDROID_PRODUCT_OUT does not point to a valid directory. Aborting"
+ exit 1
+ fi
+else
+ ANDROID_PRODUCT_OUT=$OPTION_BUILD_OUT
+ if [ ! -d $ANDROID_PRODUCT_OUT ] ; then
+ echo "The build out path is not a valid directory: $OPTION_BUILD_OUT"
+ exit 1
+ fi
+fi
+
+PRODUCT_DIR=$ANDROID_PRODUCT_OUT
+SYSROOT=$NDK_ROOT/build/platforms/$PLATFORM/arch-$ABI
+COMMON_ROOT=$NDK_ROOT/build/platforms/$PLATFORM/common
+
+# clean up everything in existing sysroot
+rm -rf $SYSROOT
+mkdir -p $SYSROOT
+
+rm -rf $COMMON_ROOT
+mkdir -p $COMMON_ROOT
+
+LIB_ROOT=$SYSROOT/usr/lib
+INCLUDE_ROOT=$SYSROOT/usr/include
+
+install_file ()
+{
+ mkdir -p $2/`dirname $1`
+ cp -fp $1 $2/$1
+}
+
+install_helper ()
+{
+ (cd $1 && find . -type f | while read ff; do install_file $ff $2; done)
+}
+
+TOP=$PRODUCT_DIR/../../../..
+
+# CRT objects that need to be copied
+CRT_OBJS_DIR=$PRODUCT_DIR/obj/lib
+CRT_OBJS="$CRT_OBJS_DIR/crtbegin_static.o \
+$CRT_OBJS_DIR/crtbegin_dynamic.o \
+$CRT_OBJS_DIR/crtend_android.o"
+
+# static libraries that need to be copied.
+STATIC_LIBS_DIR=$PRODUCT_DIR/obj/STATIC_LIBRARIES
+STATIC_LIBS="$STATIC_LIBS_DIR/libc_intermediates/libc.a \
+$STATIC_LIBS_DIR/libm_intermediates/libm.a \
+$STATIC_LIBS_DIR/libstdc++_intermediates/libstdc++.a
+$STATIC_LIBS_DIR/libthread_db_intermediates/libthread_db.a"
+
+# dynamic libraries that need to be copied.
+DYNAMIC_LIBS_DIR=$PRODUCT_DIR/symbols/system/lib
+DYNAMIC_LIBS="$DYNAMIC_LIBS_DIR/libdl.so \
+$DYNAMIC_LIBS_DIR/libc.so \
+$DYNAMIC_LIBS_DIR/libm.so \
+$DYNAMIC_LIBS_DIR/libstdc++.so \
+$DYNAMIC_LIBS_DIR/libthread_db.so"
+
+# Copy all CRT objects and libraries
+rm -rf $LIB_ROOT
+mkdir -p $LIB_ROOT
+cp -f $CRT_OBJS $STATIC_LIBS $DYNAMIC_LIBS $LIB_ROOT
+
+# Check $TOP/bionic to see if this is new layout in cupcake.
+if [ -d $TOP/bionic ] ;then
+ BIONIC_ROOT=$TOP/bionic
+ LIBC_ROOT=$BIONIC_ROOT/libc
+else
+ BIONIC_ROOT=$TOP/system
+ LIBC_ROOT=$BIONIC_ROOT/bionic
+fi
+
+# Copy headers. This need to be done in the reverse order of inclusion
+# in case there are different headers with the same name.
+ARCH_INCLUDE=$SYSROOT/usr/include
+rm -rf $ARCH_INCLUDE
+mkdir -p $ARCH_INCLUDE
+
+COMMON_INCLUDE=$COMMON_ROOT/include
+rm -rf $COMMON_INCLUDE
+mkdir -p $COMMON_INCLUDE
+
+# Install a common header and create the appropriate arch-specific
+# directory for it.
+#
+# $1: source directory
+# $2: header path, relative to source directory
+#
+common_header ()
+{
+ echo "Copy: $COMMON_INCLUDE/$2"
+ mkdir -p `dirname $COMMON_INCLUDE/$2`
+ install $1/$2 $COMMON_INCLUDE/$2
+ # just to be safe
+ chmod a-x $COMMON_INCLUDE/$2
+
+ # the link prefix, used to point to common/
+ # from arch-$ARCH/usr/
+ link_prefix=../../common/include
+
+ # we need to count the number of directory separators in $2
+ # for each one of them, we're going to prepend ../ to the
+ # link prefix
+ for item in `echo $2 | tr '/' ' '`; do
+ link_prefix=../$link_prefix
+ done
+
+ echo "Link: $ARCH_INCLUDE/$2"
+ mkdir -p `dirname $ARCH_INCLUDE/$2`
+ ln -s $link_prefix/$2 $ARCH_INCLUDE/$2
+}
+
+common_headers ()
+{
+ srcs=`cd $1 && find . -type f`
+ # remove leading ./
+ srcs=`echo $srcs | sed -e "s%\./%%g"`
+
+ for src in $srcs; do
+ common_header $1 $src
+ done
+}
+
+arch_header ()
+{
+ echo "Copy: $ARCH_INCLUDE/$2"
+ mkdir -p `dirname $ARCH_INCLUDE/$2`
+ install $1/$2 $ARCH_INCLUDE/$2
+ # just to be safe
+ chmod a-x $ARCH_INCLUDE/$2
+}
+
+arch_headers ()
+{
+ srcs=`cd $1 && find . -type f`
+ # remove leading ./
+ srcs=`echo $srcs | sed -e "s%\./%%g"`
+
+ for src in $srcs; do
+ arch_header $1 $src
+ done
+}
+
+common_header $TOP/dalvik/libnativehelper/include/nativehelper jni.h
+common_headers $BIONIC_ROOT/libthread_db/include
+
+# for libm, just copy math.h and fenv.h
+common_header $BIONIC_ROOT/libm/include math.h
+arch_header $BIONIC_ROOT/libm/include $ARCH/fenv.h
+
+common_headers $BIONIC_ROOT/libstdc++/include
+
+common_headers $LIBC_ROOT/kernel/common
+arch_headers $LIBC_ROOT/kernel/arch-arm
+
+common_headers $LIBC_ROOT/include
+arch_headers $LIBC_ROOT/arch-$ARCH/include
+
+# Do we need to package the result
+if [ $OPTION_PACKAGE = yes ] ; then
+ DATE=`date +%Y%m%d`
+ PKGFILE=/tmp/android-ndk-sysroot-$DATE.tar.bz2
+ tar cjf $PKGFILE build/platforms/$PLATFORM
+ echo "Packaged in $PKGFILE"
+fi
diff --git a/build/tools/build-toolchain.sh b/build/tools/build-toolchain.sh
new file mode 100755
index 000000000..e1047bd92
--- /dev/null
+++ b/build/tools/build-toolchain.sh
@@ -0,0 +1,499 @@
+#!/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
+source `dirname $0`/../core/ndk-common.sh
+
+# number of jobs to run in parallel when running make
+JOBS=$HOST_NUM_CPUS
+
+TOOLCHAIN_NAME=arm-eabi-4.2.1
+PLATFORM=android-1.5
+ABI=arm
+
+OPTION_HELP=no
+OPTION_PLATFORM=
+OPTION_FORCE_32=no
+OPTION_REBUILD=no
+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
+ ;;
+ --toolchain=*)
+ TOOLCHAIN_NAME=$optarg
+ ;;
+ --platform=*)
+ PLATFORM=$optarg
+ ;;
+ --abi=*)
+ ABI=$optarg
+ ;;
+ --force-download)
+ OPTION_FORCE_DOWNLOAD=yes
+ OPTION_FORCE_BUILD=yes
+ ;;
+ --force-build)
+ OPTION_FORCE_BUILD=yes
+ ;;
+ --verbose)
+ VERBOSE=yes
+ ;;
+ *)
+ echo "unknown option '$opt', use --help"
+ exit 1
+ esac
+done
+
+if [ $OPTION_HELP = "yes" ] ; then
+ echo "Collect files from an Android build tree and assembles a sysroot"
+ echo "suitable for building a standalone toolchain or be used by the"
+ echo "Android NDK."
+ echo ""
+ echo "options:"
+ echo ""
+ echo " --help print this message"
+ echo " --toolchain=<name> toolchain name (default is $TOOLCHAIN_NAME)"
+ echo " --platform=<name> generate toolchain from platform <name> (default is $PLATFORM)"
+ echo " --abi=<name> generate toolchain from abi <name> (default is $ABI)"
+ echo " --build-out=<path> set Android build out directory"
+ echo " --force-download force a download and unpacking of the toolchain sources"
+ echo " --force-build force a rebuild of the sources"
+ echo ""
+ exit 0
+fi
+
+# some Linux platforms report 64-bit while they have a 32-bit userland
+# so check that the compiler generates 32-bit binaries
+# if it does, call force_32bit_binaries to change the value of $HOST_TAG
+#
+# note that this also changes HOST_CFLAGS and HOST_LDFLAGS, however, there
+# is no way for the configure script in the toolchain to get these properly.
+#
+if [ $HOST_TAG = linux-x86_64 ] ; then
+ setup_toolchain
+ cat >$TMPC <<EOF
+int main(void)
+{
+ return 0;
+}
+EOF
+ compile_exec_run
+ readelf -h $TMPE | grep -q -e "ELF32"
+ if [ $? = 0 ] ; then
+ force_32bit_binaries
+ fi
+fi
+
+TMPLOG=/tmp/android-toolchain-build-$$.log
+rm -rf $TMPLOG
+
+if [ $VERBOSE = yes ] ; then
+ run ()
+ {
+ echo "##### NEW COMMAND"
+ echo $@
+ $@ 2>&1 | tee $TMPLOG
+ }
+else
+ echo "To follow build long, please use in another terminal: tail -F $TMPLOG"
+ run ()
+ {
+ echo "##### NEW COMMAND" >> $TMPLOG
+ echo "$@" >> $TMPLOG
+ $@ 1>$TMPLOG 2>&1
+ }
+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=$ANDROID_NDK_ROOT/out/$TOOLCHAIN_NAME
+PACKAGE_OUT=$OUT/packages
+TIMESTAMP_OUT=$OUT/timestamps
+
+# where the sysroot is located
+ANDROID_SYSROOT=$ANDROID_NDK_ROOT/build/platforms/$PLATFORM/arch-$ABI
+
+# where the toolchain binaries will be placed
+ANDROID_TOOLCHAIN_OUT=$OUT/toolchain
+ANDROID_TOOLCHAIN_SRC=$ANDROID_TOOLCHAIN_OUT/src
+ANDROID_TOOLCHAIN_BUILD=$ANDROID_TOOLCHAIN_OUT/build
+
+# where the gdbserver binaries will be placed
+ANDROID_GDBSERVER_OUT=$OUT/gdbserver
+ANDROID_GDBSERVER_BUILD=$ANDROID_GDBSERVER_OUT/build
+ANDROID_GDBSERVER_DEST=$ANDROID_SYSROOT/usr/bin
+
+# checks, we need more checks..
+mkdir -p $PACKAGE_OUT
+if [ $? != 0 ] ; then
+ echo "Can't create download/archive directory for toolchain tarballs"
+ exit 2
+fi
+
+# 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
+
+# And wget too
+WGET=`which wget`
+CURL=`which curl`
+SCP=`which 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
+}
+
+TOOLCHAIN_SRC=$ANDROID_TOOLCHAIN_SRC
+TOOLCHAIN_BUILD=$ANDROID_TOOLCHAIN_BUILD
+TOOLCHAIN_PREFIX=$ANDROID_NDK_ROOT/build/prebuilt/$HOST_TAG/$TOOLCHAIN_NAME
+
+GDBSERVER_BUILD=$ANDROID_GDBSERVER_BUILD
+
+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. 'android-toolchain')
+#
+download_package ()
+{
+ WORKSPACE=$ANDROID_NDK_ARCHIVE/$1
+ if [ ! -d $WORKSPACE ] ; then
+ echo "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"
+ 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
+ echo "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
+ echo "Copy : $PKGNAME"
+ echo " from `dirname $src`"
+ echo " into $PACKAGE_TARBALL"
+ run cp -f $src $PACKAGE_TARBALL
+ if [ $? = 0 ] ; then
+ break
+ fi
+ echo "Copy : Problem copying from $src"
+ else
+ echo "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"
+ download_file $src $PACKAGE_TARBALL
+ if [ $? = 0 ] ; then
+ break
+ fi
+ continue
+ else
+ "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"
+ exit 1
+ fi
+ fi
+
+ 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"
+ exit 2
+ fi
+
+ echo "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
+# $2: target directory
+#
+unpack_package ()
+{
+ WORKSPACE=$ANDROID_NDK_ARCHIVE/$1
+ SRCDIR=$2
+ SRCPKG=`var_value PKG_$1`
+ if ! timestamp_check $1 unpack; then
+ echo "Unpack : $1 sources"
+ echo " from $SRCPKG"
+ echo " into $SRCDIR"
+ rm -rf $SRCDIR
+ mkdir -p $SRCDIR
+ TARFLAGS=xjf
+ if [ $VERBOSE = yes ]; then
+ TARFLAGS="v$TARFLAGS"
+ fi
+ run tar $TARFLAGS $SRCPKG -C $SRCDIR
+ if [ $? != 0 ] ; then
+ echo "ERROR: Could not unpack $1, See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set $1 unpack
+ timestamp_force $1 configure
+ fi
+}
+
+if [ $OPTION_FORCE_DOWNLOAD ] ; then
+ rm -rf $ANDROID_TOOLCHAIN_SRC
+ timestamp_force toolchain unpack
+ timestamp_force toolchain verify
+fi
+
+if [ $OPTION_FORCE_BUILD ] ; then
+ rm -rf $ANDROID_TOOLCHAIN_BUILD
+ timestamp_clear toolchain
+ timestamp_clear gdbserver
+fi
+
+download_package toolchain
+unpack_package toolchain $ANDROID_TOOLCHAIN_SRC
+
+# 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
+
+# configure the toolchain
+if ! timestamp_check toolchain configure; then
+ echo "Configure: toolchain build"
+ mkdir -p $TOOLCHAIN_BUILD &&
+ cd $TOOLCHAIN_BUILD &&
+ CFLAGS="$HOST_CFLAGS" LDFLAGS="$HOST_LDFLAGS" run \
+ $TOOLCHAIN_SRC/configure --target=arm-eabi \
+ --disable-nls \
+ --prefix=$TOOLCHAIN_PREFIX \
+ --with-sysroot=$ANDROID_SYSROOT
+
+ if [ $? != 0 ] ; then
+ echo "Error while trying to configure toolchain build. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set toolchain configure
+ timestamp_force toolchain build
+fi
+
+# build the toolchain
+if ! timestamp_check toolchain build ; then
+ echo "Building : toolchain (this can take a long time)."
+ cd $TOOLCHAIN_BUILD &&
+ CFLAGS="$HOST_CFLAGS" LDFLAGS="$HOST_LDFLAGS" run make -j$JOBS
+ if [ $? != 0 ] ; then
+ echo "Error while building toolchain. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set toolchain build
+ timestamp_force toolchain install
+fi
+
+# install the toolchain to its final location
+if ! timestamp_check toolchain install ; then
+ echo "Install : toolchain binaries."
+ cd $TOOLCHAIN_BUILD &&
+ run make install
+ if [ $? != 0 ] ; then
+ echo "Error while installing toolchain. See $TMPLOG"
+ exit 1
+ fi
+ rm -f $TOOLCHAIN_PREFIX/bin/*-gccbug
+ rm -rf $TOOLCHAIN_PREFIX/man $TOOLCHAIN_PREFIX/info
+ strip $TOOLCHAIN_PREFIX/bin/*
+ strip $TOOLCHAIN_PREFIX/arm-eabi/bin/*
+ strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/cc1
+ strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/cc1plus
+ strip $TOOLCHAIN_PREFIX/libexec/gcc/*/*/collect2
+ timestamp_set toolchain install
+ timestamp_force gdbserver configure
+fi
+
+# configure the gdbserver build now
+if ! timestamp_check gdbserver configure; then
+ echo "Configure: gdbserver build."
+ mkdir -p $GDBSERVER_BUILD
+ cd $GDBSERVER_BUILD &&
+ CFLAGS="-g -O2 -static -mandroid -I$ANDROID_SYSROOT/usr/include" \
+ CC="$TOOLCHAIN_PREFIX/bin/arm-eabi-gcc" \
+ run $TOOLCHAIN_SRC/gdb-6.6/gdb/gdbserver/configure \
+ --host=arm-eabi-linux \
+ --with-sysroot=$ANDROID_SYSROOT
+ if [ $? != 0 ] ; then
+ echo "Could not configure gdbserver build. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set gdbserver configure
+ timestamp_force gdbserver build
+fi
+
+# build gdbserver
+if ! timestamp_check gdbserver build; then
+ echo "Building : gdbserver."
+ cd $GDBSERVER_BUILD &&
+ run make -j$JOBS
+ if [ $? != 0 ] ; then
+ echo "Could not build gdbserver. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set gdbserver build
+ timestamp_force gdbserver install
+fi
+
+# install gdbserver
+#
+# note that we install it in the toolchain bin directory
+# not in $SYSROOT/usr/bin
+#
+if ! timestamp_check gdbserver install; then
+ echo "Install : gdbserver."
+ DEST=$TOOLCHAIN_PREFIX/bin
+ mkdir -p $DEST &&
+ $TOOLCHAIN_PREFIX/bin/arm-eabi-strip $GDBSERVER_BUILD/gdbserver &&
+ run cp -f $GDBSERVER_BUILD/gdbserver $DEST/gdbserver
+ if [ $? != 0 ] ; then
+ echo "Could not install gdbserver. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set gdbserver install
+ timestamp_force package toolchain
+fi
+
+# package the toolchain
+TOOLCHAIN_TARBALL=/tmp/prebuilt-$TOOLCHAIN_NAME-$HOST_TAG.tar.bz2
+if ! timestamp_check package toolchain; then
+ echo "Package : $HOST_ARCH toolchain binaries"
+ echo " into $TOOLCHAIN_TARBALL"
+ cd $ANDROID_NDK_ROOT &&
+ TARFLAGS="cjf"
+ if [ $VERBOSE = yes ] ; then
+ TARFLAGS="v$TARFLAGS"
+ fi
+ run tar $TARFLAGS $TOOLCHAIN_TARBALL build/prebuilt/$HOST_TAG/$TOOLCHAIN_NAME
+ if [ $? != 0 ] ; then
+ echo "ERROR: Cannot package prebuilt toolchain binaries. See $TMPLOG"
+ exit 1
+ fi
+ timestamp_set package toolchain
+else
+ echo "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
+fi
+
+echo "Done."
+rm -f $TMPLOG
diff --git a/build/tools/make-previews.sh b/build/tools/make-previews.sh
new file mode 100755
index 000000000..5557d1fed
--- /dev/null
+++ b/build/tools/make-previews.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# This script is used to build complete Android NDK preview packages
+# from the git repository and a set of prebuilt cross-toolchain tarballs
+#
+
+TMPDIR=/tmp/ndk-preview
+GIT_REFERENCE=/home/digit/android/ndk.git
+PREBUILT_PREFIX=/home/digit/android/ndk/android-ndk-prebuilt-20090323
+PREVIEW_PREFIX=android-ndk-preview-`date "+%Y%m%d"`
+PREBUILT_SYSTEMS="linux-x86 linux-x86_64 darwin-x86 windows"
+
+rm -rf $TMPDIR && mkdir -p $TMPDIR
+
+# first create the reference ndk directory from the git reference
+git clone $GIT_REFERENCE $TMPDIR/reference
+if [ $? != 0 ] ; then
+ echo "Could not clone git reference. Aborting."
+ exit 2
+fi
+# get rid of .git directory
+rm -rf $TMPDIR/reference/.git
+
+# now, for each system, create a preview package
+#
+for SYSTEM in $PREBUILT_SYSTEMS; do
+ echo "Preparing package for system $SYSTEM."
+ PREVIEW=$PREVIEW_PREFIX-$SYSTEM
+ PREBUILT=$PREBUILT_PREFIX-$SYSTEM
+ DSTDIR=$TMPDIR/$PREVIEW
+ rm -rf $DSTDIR && mkdir -p $DSTDIR &&
+ cp -rp $TMPDIR/reference/* $DSTDIR
+ if [ $? != 0 ] ; then
+ echo "Could not copy reference. Aborting."
+ exit 2
+ fi
+ echo "Unpacking $PREBUILT.tar.bz2"
+ (cd $DSTDIR && tar xjf $PREBUILT.tar.bz2)
+ if [ $? != 0 ] ; then
+ echo "Could not unpack prebuilt for system $SYSTEM. Aborting."
+ exit 1
+ fi
+ echo "Creating $PREVIEW.tar.bz2"
+ (cd $TMPDIR && tar cjf $PREVIEW.tar.bz2 $PREVIEW && rm -rf $DSTDIR)
+ if [ $? != 0 ] ; then
+ echo "Could not create archive. Aborting."
+ exit 1
+ fi
+done
+
+echo "Cleaning up."
+rm -rf $TMPDIR/reference
+
+echo "Done, please see packages in $TMPDIR:"
+ls -l $TMPDIR
+