From 93384987920caa35c0de8739d1ba0233c3279a8b Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Mon, 9 Sep 2013 05:53:58 +0000 Subject: Re #1516: Add support to build for other targets. Example: TARGET_ABI=armeabi-v7a ./configure-android --use-ndk-cflags git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4594 74dad513-b988-da41-8d7b-12977e46ad98 --- configure-android | 93 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 34 deletions(-) (limited to 'configure-android') diff --git a/configure-android b/configure-android index d749b681..ca5d9f08 100755 --- a/configure-android +++ b/configure-android @@ -16,11 +16,12 @@ if test "$*" = "--help" -o "$*" = "-h"; then echo "Environment variables:" echo " ANDROID_NDK_ROOT Specify the directory of Android NDK to use." echo " APP_PLATFORM Optionally specify the platform level used, e.g." - echo " android-8. By default, configure will use the maximum" - echo " platform level detected." - echo " TARGET_ABI Optionally specify a single target architecture, e.g." - echo " armeabi-v7a. By default, the target architecture is" - echo " armeabi." + echo " android-9. By default, configure will use the" + echo " maximum platform level detected." + echo " TARGET_ABI Optionally specify a single target architecture," + echo " e.g. armeabi-v7a, mips, x86. By default, the target" + echo " architecture is armeabi. Only used when" + echo " --use-ndk-cflags is specified." echo "" exit 0 fi @@ -53,45 +54,69 @@ fi if test "$1" = "--use-ndk-cflags"; then shift + ADD_CFLAGS="1" for i in `${ANDROID_NDK_ROOT}/ndk-build -n -C ${ANDROID_NDK_ROOT}/samples/hello-jni NDK_LOG=1 APP_PLATFORM=${APP_PLATFORM} APP_ABI=${TARGET_ABI}`; do - if test "$i" = "-c"; then break; fi - if test "x${NDK_CC}" != "x" -a "$i" != "-MF" -a "x`echo $i|grep '\.o\.d'`" = "x" -a "x`echo $i|grep 'include'`" = "x"; then - NDK_CFLAGS="${NDK_CFLAGS} $i" + if test "x${NDK_CXX}" != "x" -a "$i" = "-o"; then break; fi + + # Parse NDK CXXFLAGS + if test "x${NDK_CXX}" != "x" -a "x`echo $i|grep 'hello-jni'`" = "x"; then + if test "x`echo $i|grep '\-\-sysroot='`" != "x"; then + ANDROID_SYSROOT=`echo $i|sed 's/--sysroot=//'`; + fi + NDK_CXXFLAGS="${NDK_CXXFLAGS} $i" + fi + + # Parse NDK CFLAGS + if test "x${NDK_CC}" != "x" -a "x`echo $i|grep 'hello-jni'`" = "x" -a "x`echo $i|grep '\-M'`" = "x" -a "${ADD_CFLAGS}" = "1"; then + if test "$i" = "-c"; then ADD_CFLAGS="0"; else + NDK_CFLAGS="${NDK_CFLAGS} $i" + fi fi - if test "x`echo $i | grep 'gcc'`" != "x"; then + + # Find gcc toolchain + if test "x${NDK_CC}" = "x" -a "x`echo $i | grep 'gcc'`" != "x"; then NDK_CC=$i fi + # Find g++ toolchain + if test "x`echo $i | grep 'g++'`" != "x"; then + NDK_CXX=$i + fi done + + export CC="${NDK_CC}" + export CXX="${NDK_CXX}" + + export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" + export LIBS="${LIBS} -lc -lgcc" export CFLAGS="${CFLAGS} ${NDK_CFLAGS}" -fi + export CPPFLAGS="${CFLAGS}" + export CXXFLAGS="${NDK_CXXFLAGS}" -HOST_OS=$(uname -s) -case $HOST_OS in - Darwin) BUILD_MACHINE="darwin-x86";; - Linux) BUILD_MACHINE="linux-x86";; - CYGWIN*|*_NT-*) BUILD_MACHINE="windows";; -esac - -ANDROID_TC="${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-4.4.3/prebuilt/${BUILD_MACHINE}" -if test ! -d ${ANDROID_TC}; then - echo "$F error: unable to find directory ${ANDROID_TC} in Android NDK" - exit 1 -fi +else -export ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-arm" -if test ! -d ${ANDROID_SYSROOT}; then - echo "$F error: unable to find sysroot dir ${ANDROID_SYSROOT} in Android NDK" - exit 1 -fi + ANDROID_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-* | sed 's/clang/0/' | sort -gr | head -1` + ANDROID_TC=`ls -d ${ANDROID_TC_VER}/prebuilt/*` + if test ! -d ${ANDROID_TC}; then + echo "$F error: unable to find directory ${ANDROID_TC} in Android NDK" + exit 1 + fi -export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc" -export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++" + export ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-arm" + if test ! -d ${ANDROID_SYSROOT}; then + echo "$F error: unable to find sysroot dir ${ANDROID_SYSROOT} in Android NDK" + exit 1 + fi -export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" -export LIBS="${LIBS} -lc -lgcc" -export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include" -export CPPFLAGS="${CFLAGS}" -export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT}" + export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc" + export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++" + + export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" + export LIBS="${LIBS} -lc -lgcc" + export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include" + export CPPFLAGS="${CFLAGS}" + export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT}" + +fi # Print settings if test "1" = "1"; then -- cgit v1.2.3