Index: pjproject/trunk/configure-android
===================================================================
--- pjproject/trunk/configure-android	(revision 4435)
+++ pjproject/trunk/configure-android	(revision 4594)
@@ -17,9 +17,10 @@
   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
@@ -54,43 +55,67 @@
 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
-    if test "x`echo $i | grep 'gcc'`" != "x"; then
+
+    # 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
+
+    # 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}"
+  export CPPFLAGS="${CFLAGS}"
+  export CXXFLAGS="${NDK_CXXFLAGS}"
+
+else
+
+  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 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 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
-
-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
-
-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 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}"
 
 # Print settings
