Skip to content

Commit 5ad866d

Browse files
digit-androidAndroid Git Automerger
authored andcommitted
am e4df0ea: Merge change I8d8b5816 into eclair
Merge commit 'e4df0ea14bcfc6e2d395e36970749cf9a916a0fb' into eclair-mr2 * commit 'e4df0ea14bcfc6e2d395e36970749cf9a916a0fb': Update build-toolchain.sh to be able to build gcc 4.4.0
2 parents 245c428 + e4df0ea commit 5ad866d

File tree

3 files changed

+986
-56
lines changed

3 files changed

+986
-56
lines changed

ndk/build/tools/build-toolchain.sh

Lines changed: 136 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,62 +29,87 @@ JOBS=$HOST_NUM_CPUS
2929
TOOLCHAIN_NAME=arm-eabi-4.2.1
3030
PLATFORM=android-3
3131
ABI=arm
32+
GCC_VERSION=4.2.1
33+
GDB_VERSION=6.6
3234

3335
OPTION_HELP=no
3436
OPTION_PLATFORM=
3537
OPTION_FORCE_32=no
3638
OPTION_REBUILD=no
39+
OPTION_GCC_VERSION=
40+
OPTION_GDB_VERSION=
41+
OPTION_TOOLCHAIN_NAME=
42+
OPTION_PACKAGE=
3743

3844
VERBOSE=no
3945
for opt do
40-
optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
41-
case "$opt" in
42-
--help|-h|-\?) OPTION_HELP=yes
43-
;;
44-
--verbose)
45-
if [ "$VERBOSE" = "yes" ] ; then
46-
VERBOSE2=yes
47-
else
48-
VERBOSE=yes
49-
fi
50-
;;
51-
--toolchain=*)
52-
TOOLCHAIN_NAME=$optarg
53-
;;
54-
--platform=*)
55-
PLATFORM=$optarg
56-
;;
57-
--abi=*)
58-
ABI=$optarg
59-
;;
60-
--force-download)
61-
OPTION_FORCE_DOWNLOAD=yes
62-
OPTION_FORCE_BUILD=yes
46+
optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
47+
case "$opt" in
48+
--help|-h|-\?) OPTION_HELP=yes
6349
;;
64-
--force-build)
65-
OPTION_FORCE_BUILD=yes
66-
;;
67-
--verbose)
68-
VERBOSE=yes
69-
;;
70-
*)
71-
echo "unknown option '$opt', use --help"
72-
exit 1
73-
esac
50+
--verbose)
51+
if [ "$VERBOSE" = "yes" ] ; then
52+
VERBOSE2=yes
53+
else
54+
VERBOSE=yes
55+
fi
56+
;;
57+
--gcc-version=*)
58+
OPTION_GCC_VERSION=$optarg
59+
;;
60+
--gdb-version=*)
61+
OPTION_GDB_VERSION=$optarg
62+
;;
63+
--toolchain=*)
64+
OPTION_TOOLCHAIN_NAME=$optarg
65+
;;
66+
--package=*)
67+
OPTION_PACKAGE="$optarg"
68+
;;
69+
--platform=*)
70+
PLATFORM=$optarg
71+
;;
72+
--abi=*)
73+
ABI=$optarg
74+
;;
75+
--force-download)
76+
OPTION_FORCE_DOWNLOAD=yes
77+
OPTION_FORCE_BUILD=yes
78+
;;
79+
--force-build)
80+
OPTION_FORCE_BUILD=yes
81+
;;
82+
--verbose)
83+
VERBOSE=yes
84+
;;
85+
*)
86+
echo "unknown option '$opt', use --help"
87+
exit 1
88+
esac
7489
done
7590

7691
if [ $OPTION_HELP = "yes" ] ; then
7792
echo "Rebuild the prebuilt binaries for the Android NDK toolchain."
93+
echo "This script will automatically download the sources from the"
94+
echo "Internet, unless you use the --package=<file> option to specify"
95+
echo "the exact source package to use."
96+
echo ""
97+
echo "See build/tools/download-toolchain-sources.sh for a tool that"
98+
echo "can create a compatible source package from the current"
99+
echo "git repositories."
78100
echo ""
79-
echo "options:"
101+
echo "options (defaults are within brackets):"
80102
echo ""
81-
echo " --help print this message"
82-
echo " --toolchain=<name> toolchain name (default is $TOOLCHAIN_NAME)"
83-
echo " --platform=<name> generate toolchain from platform <name> (default is $PLATFORM)"
84-
echo " --abi=<name> generate toolchain from abi <name> (default is $ABI)"
85-
echo " --build-out=<path> set Android build out directory"
86-
echo " --force-download force a download and unpacking of the toolchain sources"
87-
echo " --force-build force a rebuild of the sources"
103+
echo " --help print this message"
104+
echo " --gcc-version=<version> select GCC version [$GCC_VERSION]"
105+
echo " --gdb-version=<version> select GDB version [$GDB_VERSION]"
106+
echo " --toolchain=<name> toolchain name (default is $TOOLCHAIN_NAME)"
107+
echo " --package=<file> specify download source package"
108+
echo " --platform=<name> generate toolchain from platform <name> (default is $PLATFORM)"
109+
echo " --abi=<name> generate toolchain from abi <name> (default is $ABI)"
110+
echo " --build-out=<path> set Android build out directory"
111+
echo " --force-download force a download and unpacking of the toolchain sources"
112+
echo " --force-build force a rebuild of the sources"
88113
echo ""
89114
exit 0
90115
fi
@@ -105,19 +130,56 @@ if [ $VERBOSE = yes ] ; then
105130
run ()
106131
{
107132
echo "##### NEW COMMAND"
108-
echo $@
109-
$@ 2>&1 | tee $TMPLOG
133+
echo "$@"
134+
$@ 2>&1
135+
}
136+
log ()
137+
{
138+
echo "LOG: $@"
110139
}
111140
else
112-
echo "To follow build long, please use in another terminal: tail -F $TMPLOG"
141+
echo "To follow build, please use in another terminal: tail -F $TMPLOG"
113142
run ()
114143
{
115144
echo "##### NEW COMMAND" >> $TMPLOG
116145
echo "$@" >> $TMPLOG
117-
$@ 1>$TMPLOG 2>&1
146+
$@ >>$TMPLOG 2>&1
147+
}
148+
log ()
149+
{
150+
echo "$@" > /dev/null
118151
}
119152
fi
120153

154+
if [ -n "$OPTION_GCC_VERSION" ] ; then
155+
GCC_VERSION="$OPTION_GCC_VERSION"
156+
log "Using gcc version $GCC_VERSION"
157+
else
158+
log "Using default gcc version $GCC_VERSION"
159+
fi
160+
161+
if [ -n "$OPTION_GDB_VERSION" ] ; then
162+
GDB_VERSION="$OPTION_GDB_VERSION"
163+
log "Using gdb version $GDB_VERSION"
164+
else
165+
log "Using default gdb version $GDB_VERSION"
166+
fi
167+
168+
if [ -n "$OPTION_TOOLCHAIN_NAME" ] ; then
169+
TOOLCHAIN_NAME="$OPTION_TOOLCHAIN_NAME"
170+
log "Using toolchain name '$TOOLCHAIN_NAME'"
171+
else
172+
TOOLCHAIN_NAME=arm-eabi-$GCC_VERSION
173+
log "Using default toolchain name '$TOOLCHAIN_NAME'"
174+
fi
175+
176+
if [ -n "$OPTION_PACKAGE" ] ; then
177+
if [ ! -f "$OPTION_PACKAGE" ] ; then
178+
echo "Package is not a file: $OPTION_PACKAGE"
179+
exit 1
180+
fi
181+
fi
182+
121183
ANDROID_NDK_ROOT=`cd $ANDROID_NDK_ROOT && pwd`
122184
ANDROID_NDK_ARCHIVE=$ANDROID_NDK_ROOT/build/toolchains/archive
123185
ANDROID_PLATFORMS_ROOT=$ANDROID_NDK_ROOT/build/platforms
@@ -193,6 +255,7 @@ download_file ()
193255
TOOLCHAIN_SRC=$ANDROID_TOOLCHAIN_SRC
194256
TOOLCHAIN_BUILD=$ANDROID_TOOLCHAIN_BUILD
195257
TOOLCHAIN_PREFIX=$ANDROID_NDK_ROOT/build/prebuilt/$HOST_TAG/$TOOLCHAIN_NAME
258+
TOOLCHAIN_LICENSES=$ANDROID_NDK_ROOT/build/tools/toolchain-licenses
196259

197260
GDBSERVER_BUILD=$ANDROID_GDBSERVER_BUILD
198261

@@ -315,10 +378,10 @@ unpack_package ()
315378
echo "Unpack : $1 sources"
316379
echo " from $SRCPKG"
317380
echo " into $SRCDIR"
318-
rm -rf $SRCDIR
319-
mkdir -p $SRCDIR
381+
run rm -rf $SRCDIR
382+
run mkdir -p $SRCDIR
320383
TARFLAGS=xjf
321-
if [ $VERBOSE = yes ]; then
384+
if [ $VERBOSE2 = yes ]; then
322385
TARFLAGS="v$TARFLAGS"
323386
fi
324387
run tar $TARFLAGS $SRCPKG -C $SRCDIR
@@ -350,7 +413,12 @@ if [ $? != 0 ] ; then
350413
exit 2
351414
fi
352415

353-
download_package toolchain
416+
if [ -n "$OPTION_PACKAGE" ] ; then
417+
PKG_toolchain="$OPTION_PACKAGE"
418+
else
419+
download_package toolchain
420+
fi
421+
354422
unpack_package toolchain $ANDROID_TOOLCHAIN_SRC
355423

356424
# remove all info files from the unpacked toolchain sources
@@ -363,15 +431,21 @@ find $ANDROID_TOOLCHAIN_SRC -type f -a -name "*.info" -print0 | xargs -0 rm -f
363431
# configure the toolchain
364432
if ! timestamp_check toolchain configure; then
365433
echo "Configure: toolchain build"
434+
BUILD_SRCDIR=$TOOLCHAIN_SRC/build
435+
if [ ! -d $BUILD_SRCDIR ] ; then
436+
BUILD_SRCDIR=$TOOLCHAIN_SRC
437+
fi
366438
mkdir -p $TOOLCHAIN_BUILD &&
367439
cd $TOOLCHAIN_BUILD &&
440+
export ABI="32" && # needed to build a 32-bit gmp
368441
export CFLAGS="$HOST_CFLAGS" &&
369442
export LDFLAGS="$HOST_LDFLAGS" && run \
370-
$TOOLCHAIN_SRC/configure --target=arm-eabi \
443+
$BUILD_SRCDIR/configure --target=arm-eabi \
371444
--disable-nls \
372445
--prefix=$TOOLCHAIN_PREFIX \
373-
--with-sysroot=$ANDROID_SYSROOT
374-
446+
--with-sysroot=$ANDROID_SYSROOT \
447+
--with-gcc-version=$GCC_VERSION \
448+
--with-gdb-version=$GDB_VERSION
375449
if [ $? != 0 ] ; then
376450
echo "Error while trying to configure toolchain build. See $TMPLOG"
377451
exit 1
@@ -405,7 +479,7 @@ if ! timestamp_check toolchain install ; then
405479
exit 1
406480
fi
407481
# don't forget to copy the GPL and LGPL license files
408-
cp -f $TOOLCHAIN_SRC/COPYING $TOOLCHAIN_SRC/COPYING.LIB $TOOLCHAIN_PREFIX
482+
cp -f $TOOLCHAIN_LICENSES/COPYING $TOOLCHAIN_LICENSES/COPYING.LIB $TOOLCHAIN_PREFIX
409483
# remove some unneeded files
410484
rm -f $TOOLCHAIN_PREFIX/bin/*-gccbug
411485
rm -rf $TOOLCHAIN_PREFIX/man $TOOLCHAIN_PREFIX/info
@@ -422,12 +496,17 @@ fi
422496
# configure the gdbserver build now
423497
if ! timestamp_check gdbserver configure; then
424498
echo "Configure: gdbserver build."
499+
if [ -d $TOOLCHAIN_SRC/gdb ] ; then
500+
GDB_SRCDIR=$TOOLCHAIN_SRC/gdb/gdb-$GDB_VERSION
501+
else
502+
GDB_SRCDIR=$TOOLCHAIN_SRC/gdb-$GDB_VERSION
503+
fi
425504
mkdir -p $GDBSERVER_BUILD
426505
cd $GDBSERVER_BUILD &&
427506
export CC="$TOOLCHAIN_PREFIX/bin/arm-eabi-gcc" &&
428-
export CFLAGS="-g -O2 -static -mandroid -I$ANDROID_SYSROOT/usr/include" &&
507+
export CFLAGS="-g -O2 -static -mandroid" &&
429508
export LDFLAGS= &&
430-
run $TOOLCHAIN_SRC/gdb-6.6/gdb/gdbserver/configure \
509+
run $GDB_SRCDIR/gdb/gdbserver/configure \
431510
--host=arm-eabi-linux \
432511
--with-sysroot=$ANDROID_SYSROOT
433512
if [ $? != 0 ] ; then
@@ -471,7 +550,7 @@ if ! timestamp_check gdbserver install; then
471550
fi
472551

473552
# package the toolchain
474-
TOOLCHAIN_TARBALL=/tmp/prebuilt-$TOOLCHAIN_NAME-$HOST_TAG.tar.bz2
553+
TOOLCHAIN_TARBALL=/tmp/android-ndk-prebuilt-$TOOLCHAIN_NAME-$HOST_TAG.tar.bz2
475554
if ! timestamp_check package toolchain; then
476555
echo "Package : $HOST_ARCH toolchain binaries"
477556
echo " into $TOOLCHAIN_TARBALL"
@@ -486,6 +565,7 @@ if ! timestamp_check package toolchain; then
486565
exit 1
487566
fi
488567
timestamp_set package toolchain
568+
echo "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
489569
else
490570
echo "prebuilt toolchain is in $TOOLCHAIN_TARBALL"
491571
fi

0 commit comments

Comments
 (0)