OSDN Git Service

Port NDK build tools to IA
authorBruce Beare <brucex.j.beare@intel.com>
Thu, 11 Mar 2010 19:14:29 +0000 (11:14 -0800)
committerThe Android Open Source Project <initial-contribution@android.com>
Wed, 31 Mar 2010 22:34:18 +0000 (15:34 -0700)
Change-Id: I4788cafb998b79234e7fb16661bb225680d5566c

build/tools/build-ndk-sysroot.sh
build/tools/build-toolchain.sh
build/tools/make-release.sh

index c9f3285..4b3bb41 100755 (executable)
@@ -36,13 +36,12 @@ PLATFORM=android-3
 # 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
+OPTION_ABI=
+
 for opt do
   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
   case "$opt" in
@@ -64,6 +63,9 @@ for opt do
   --package)
     OPTION_PACKAGE=yes
     ;;
+  --abi=*)
+    OPTION_ABI=$optarg
+    ;;
   *)
     echo "unknown option '$opt', use --help"
     exit 1
@@ -80,6 +82,7 @@ if [ $OPTION_HELP = "yes" ] ; then
     echo "  --help             print this message"
     echo "  --verbose          enable verbose messages"
     echo "  --platform=<name>  generate sysroot for platform <name> (default is $PLATFORM)"
+    echo "  --abi=<name>       generate sysroot for abi <name> (default is $ABI)"
     echo "  --build-out=<path> set Android build out directory"
     echo "  --package          generate sysroot package tarball"
     echo ""
@@ -90,6 +93,20 @@ if [ -n "$OPTION_PLATFORM" ] ; then
     PLATFORM=$OPTION_PLATFORM
 fi
 
+if [ -n "$OPTION_ABI" ] ; then
+    ABI=$OPTION_ABI
+fi
+
+case "$ABI" in
+arm*)
+    ARCH=arm
+    ;;
+*)
+    ARCH=$ABI
+    ;;
+esac
+
+
 # Get the root of the NDK from the current program location
 NDK_ROOT=`dirname $0`
 NDK_ROOT=`dirname $NDK_ROOT`
@@ -258,14 +275,18 @@ 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
+if [ "$ARCH" = "x86" ]; then
+    arch_header   $BIONIC_ROOT/libm/include i387/fenv.h
+else
+    arch_header   $BIONIC_ROOT/libm/include $ARCH/fenv.h
+fi
 
 # our tiny C++ standard library
 common_headers $BIONIC_ROOT/libstdc++/include
 
 # C library kernel headers
 common_headers $LIBC_ROOT/kernel/common
-arch_headers   $LIBC_ROOT/kernel/arch-arm
+arch_headers   $LIBC_ROOT/kernel/arch-$ARCH
 
 # C library headers
 common_headers $LIBC_ROOT/include
@@ -275,6 +296,6 @@ arch_headers   $LIBC_ROOT/arch-$ARCH/include
 if [ $OPTION_PACKAGE = yes ] ; then
     DATE=`date +%Y%m%d`
     PKGFILE=/tmp/android-ndk-sysroot-$DATE.tar.bz2
-    tar cjf $PKGFILE build/platforms/$PLATFORM
+    tar cjf $PKGFILE build/platforms/$PLATFORM/arch-$ARCH
     echo "Packaged in $PKGFILE"
 fi
index 51f3fa7..70f3b07 100755 (executable)
 # 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
 
@@ -43,13 +69,14 @@ 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
@@ -85,6 +112,9 @@ for opt do
     --force-build)
         OPTION_FORCE_BUILD=yes
         ;;
+    --build-toolchains=*)
+        OPTION_BUILD_TOOLCHAINS="$OPTION_BUILD_TOOLCHAINS $optarg"
+        ;;
     --verbose)
         VERBOSE=yes
         ;;
@@ -95,28 +125,7 @@ for opt do
 done
 
 if [ $OPTION_HELP = "yes" ] ; then
-    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 "  --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 ""
+    print_help
     exit 0
 fi
 
@@ -129,6 +138,27 @@ case $HOST_TAG in
         ;;
 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
+
 TMPLOG=/tmp/android-toolchain-build-$$.log
 rm -rf $TMPLOG
 
@@ -157,6 +187,7 @@ else
     }
 fi
 
+
 if [ -n "$OPTION_GCC_VERSION" ] ; then
     GCC_VERSION="$OPTION_GCC_VERSION"
     log "Using gcc version $GCC_VERSION"
@@ -203,7 +234,7 @@ TIMESTAMP_OUT=$OUT/timestamps
 
 # where the sysroot is located
 ANDROID_TOOLCHAIN_SRC=$OUT/src
-ANDROID_SYSROOT=$ANDROID_NDK_ROOT/build/platforms/$PLATFORM/arch-$ABI
+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`
@@ -518,7 +549,7 @@ build_toolchain ()
         if [ ! -d $BUILD_SRCDIR ] ; then
             BUILD_SRCDIR=$TOOLCHAIN_SRC
         fi
-        OLD_ABI="$ABI"
+        OLD_ABI="${ABI}"
         OLD_CFLAGS="$CFLAGS"
         OLD_LDFLAGS="$LDFLAGS"
         mkdir -p $TOOLCHAIN_BUILD &&
@@ -526,7 +557,7 @@ build_toolchain ()
         export ABI="32" &&  # needed to build a 32-bit gmp
         export CFLAGS="$HOST_CFLAGS" &&
         export LDFLAGS="$HOST_LDFLAGS" && run \
-        $BUILD_SRCDIR/configure --target=arm-eabi \
+        $BUILD_SRCDIR/configure --target=$ABI_TOOLCHAIN_PREFIX \
                                 --disable-nls \
                                 --prefix=$TOOLCHAIN_PREFIX \
                                 --with-sysroot=$ANDROID_SYSROOT \
@@ -582,7 +613,7 @@ build_toolchain ()
         rm -rf $TOOLCHAIN_PREFIX/man $TOOLCHAIN_PREFIX/info
         # strip binaries to reduce final package size
         strip $TOOLCHAIN_PREFIX/bin/*
-        strip $TOOLCHAIN_PREFIX/arm-eabi/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
@@ -604,12 +635,19 @@ build_toolchain ()
         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/arm-eabi-gcc" &&
-        export CFLAGS="-g -O2 -static -mandroid"  &&
-        export LDFLAGS= &&
+        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=arm-eabi-linux \
+        --host=${ABI_CONFIGURE_HOST} \
         --with-sysroot=$ANDROID_SYSROOT
         if [ $? != 0 ] ; then
             echo "Could not configure gdbserver build. See $TMPLOG"
@@ -644,7 +682,7 @@ build_toolchain ()
         echo "Install  : $TOOLCHAIN_NAME gdbserver."
         DEST=$TOOLCHAIN_PREFIX/bin
         mkdir -p $DEST &&
-        $TOOLCHAIN_PREFIX/bin/arm-eabi-strip $GDBSERVER_BUILD/gdbserver &&
+        $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"
@@ -660,11 +698,10 @@ build_toolchain ()
 # The old source tarball only contained gcc 4.2.1, the new
 # ones contain multiple toolchains
 #
-if [ -d $ANDROID_TOOLCHAIN_SRC/gcc-4.2.1 ] ; then
-    # An old toolchain source package
-    ANDROID_TOOLCHAIN_LIST=arm-eabi-4.2.1
+if [ "$OPTION_BUILD_TOOLCHAINS" ]; then
+    ANDROID_TOOLCHAIN_LIST="$OPTION_BUILD_TOOLCHAINS"
 else
-    ANDROID_TOOLCHAIN_LIST="arm-eabi-4.2.1 arm-eabi-4.4.0"
+    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
@@ -672,14 +709,24 @@ for _toolchain in $ANDROID_TOOLCHAIN_LIST; do
         timestamp_force ${_toolchain} configure
         timestamp_force ${_toolchain}-gdbserver configure
     fi
-    # Gcc 4.2.1 needs binutils 2.17
-    if [ ${_toolchain} = arm-eabi-4.2.1 ] ; then
+    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
-    else
+        ;;
+    x86-4.4.0 )
         GCC_VERSION=4.4.0
         BINUTILS_VERSION=2.19
-    fi
+        ;;
+    arm*-4.4.0 )
+        GCC_VERSION=4.4.0
+        BINUTILS_VERSION=2.19
+        ;;
+    esac
     build_toolchain ${_toolchain}
 done
 
@@ -689,7 +736,7 @@ 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 "libarm-elf-linux-sim.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"
     cd $ANDROID_NDK_ROOT &&
index 7ddb63d..a74cfb3 100755 (executable)
@@ -171,6 +171,7 @@ else
     rm -rf $NDK_ROOT_DIR/out
     rm -rf $NDK_ROOT_DIR/apps/*/project/libs/armeabi
     rm -rf $NDK_ROOT_DIR/apps/*/project/libs/armeabi-v7a
+    rm -rf $NDK_ROOT_DIR/apps/*/project/libs/x86
     # Get all files under the NDK root
     GIT_FILES=`cd $NDK_ROOT_DIR && find .`
     GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"`