Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | |
| 4 | F="configure-android" |
| 5 | |
| 6 | if test "$*" = "--help" -o "$*" = "-h"; then |
| 7 | echo "$F [--use-ndk-cflags] [OPTIONS]" |
| 8 | echo "" |
| 9 | echo "where:" |
| 10 | echo " --use-ndk-cflags Optional parameter to use the same compilation flags" |
| 11 | echo " as the one used by ndk-build" |
| 12 | echo " OPTIONS Other options that will be passed directly to" |
| 13 | echo " ./aconfigure script. Run ./aconfigure --help" |
| 14 | echo " for more info." |
| 15 | echo "" |
| 16 | echo "Environment variables:" |
| 17 | echo " ANDROID_NDK_ROOT Specify the directory of Android NDK to use." |
| 18 | echo " APP_PLATFORM Optionally specify the platform level used, e.g." |
| 19 | echo " android-9. By default, configure will use the" |
| 20 | echo " maximum platform level detected." |
| 21 | echo " TARGET_ABI Optionally specify a single target architecture," |
| 22 | echo " e.g. armeabi-v7a, mips, x86. By default, the target" |
| 23 | echo " architecture is armeabi. Only used when" |
| 24 | echo " --use-ndk-cflags is specified." |
| 25 | echo " IGNORE_CFLAGS Optionally specify compilation flags to be ignored." |
| 26 | echo " Each grepped flag that satisfies the criteria will" |
| 27 | echo " be ignored. Default:" |
| 28 | echo " IGNORE_CFLAGS=\"\-M\|\-f*stack\|\-f*alias\"" |
| 29 | echo " Only used when --use-ndk-cflags is specified." |
| 30 | echo "" |
| 31 | exit 0 |
| 32 | fi |
| 33 | |
| 34 | if test "x${ANDROID_NDK_ROOT}" = "x"; then |
| 35 | echo "$F error: ANDROID_NDK_ROOT must be specified" |
| 36 | exit 0 |
| 37 | fi |
| 38 | |
| 39 | #if test "$1" = "--simulator"; then |
| 40 | if test "1" = "0"; then |
| 41 | shift |
| 42 | TARGET_HOST="i686-android-linux" |
| 43 | TC_DIR="x86" |
| 44 | else |
| 45 | TARGET_HOST="arm-linux-androideabi" |
| 46 | TC_DIR=${TARGET_HOST} |
| 47 | fi |
| 48 | |
| 49 | if test "x$APP_PLATFORM" = "x"; then |
| 50 | APP_PLATFORM=`ls ${ANDROID_NDK_ROOT}/platforms/ | sed 's/android-//' | sort -gr | head -1` |
| 51 | APP_PLATFORM="android-${APP_PLATFORM}" |
| 52 | echo "$F: APP_PLATFORM not specified, using ${APP_PLATFORM}" |
| 53 | fi |
| 54 | |
| 55 | if test "x$TARGET_ABI" = "x"; then |
| 56 | TARGET_ABI="armeabi" |
| 57 | echo "$F: TARGET_ABI not specified, using ${TARGET_ABI}" |
| 58 | fi |
| 59 | |
| 60 | if test "$1" = "--use-ndk-cflags"; then |
| 61 | shift |
| 62 | ADD_CFLAGS="1" |
| 63 | if test "x${IGNORE_CFLAGS}" = "x"; then |
| 64 | IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias" |
| 65 | fi |
| 66 | 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 |
| 67 | if test "x${NDK_CXX}" != "x" -a "$i" = "-o"; then break; fi |
| 68 | |
| 69 | # Parse NDK CXXFLAGS |
| 70 | if test "x${NDK_CXX}" != "x" -a "x`echo $i|grep 'hello-jni'`" = "x"; then |
| 71 | if test "x`echo $i|grep '\-\-sysroot='`" != "x"; then |
| 72 | ANDROID_SYSROOT=`echo $i|sed 's/--sysroot=//'`; |
| 73 | fi |
| 74 | NDK_CXXFLAGS="${NDK_CXXFLAGS} $i" |
| 75 | fi |
| 76 | |
| 77 | # Parse NDK CFLAGS |
| 78 | if test "x${NDK_CC}" != "x" -a "x`echo $i|grep 'hello-jni'`" = "x" -a "${ADD_CFLAGS}" = "1"; then |
| 79 | if test "$i" = "-c"; then ADD_CFLAGS="0"; else |
| 80 | if test "x`echo $i|grep ${IGNORE_CFLAGS}`" = "x"; then |
| 81 | NDK_CFLAGS="${NDK_CFLAGS} $i" |
| 82 | fi |
| 83 | fi |
| 84 | fi |
| 85 | |
| 86 | # Find gcc toolchain |
| 87 | if test "x${NDK_CC}" = "x" -a "x`echo $i | grep 'gcc'`" != "x"; then |
| 88 | NDK_CC=$i |
| 89 | fi |
| 90 | # Find g++ toolchain |
| 91 | if test "x`echo $i | grep 'g++'`" != "x"; then |
| 92 | NDK_CXX=$i |
| 93 | fi |
| 94 | done |
| 95 | |
| 96 | export CC="${NDK_CC}" |
| 97 | export CXX="${NDK_CXX}" |
| 98 | export AR=`echo ${NDK_CXX}|sed 's/-g++/-ar/'`; |
| 99 | export RANLIB=`echo ${NDK_CXX}|sed 's/-g++/-ranlib/'`; |
| 100 | |
| 101 | export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" |
| 102 | export LIBS="${LIBS} -lc -lgcc" |
| 103 | export CFLAGS="${NDK_CFLAGS} ${CFLAGS}" |
| 104 | export CPPFLAGS="${CFLAGS}" |
| 105 | export CXXFLAGS="${NDK_CXXFLAGS}" |
| 106 | |
| 107 | else |
| 108 | |
| 109 | ANDROID_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-* | sed 's/clang/0/' | sort -gr | head -1` |
| 110 | ANDROID_TC=`ls -d ${ANDROID_TC_VER}/prebuilt/* | grep -v gdbserver | head -1` |
| 111 | if test ! -d ${ANDROID_TC}; then |
| 112 | echo "$F error: unable to find directory ${ANDROID_TC} in Android NDK" |
| 113 | exit 1 |
| 114 | fi |
| 115 | |
| 116 | export ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-arm" |
| 117 | if test ! -d ${ANDROID_SYSROOT}; then |
| 118 | echo "$F error: unable to find sysroot dir ${ANDROID_SYSROOT} in Android NDK" |
| 119 | exit 1 |
| 120 | fi |
| 121 | |
| 122 | export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc" |
| 123 | export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++" |
| 124 | export AR="${ANDROID_TC}/bin/${TARGET_HOST}-ar" |
| 125 | export RANLIB="${ANDROID_TC}/bin/${TARGET_HOST}-ranlib" |
| 126 | |
| 127 | export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" |
| 128 | export LIBS="${LIBS} -lc -lgcc" |
| 129 | export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include" |
| 130 | export CPPFLAGS="${CFLAGS}" |
| 131 | export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT}" |
| 132 | |
| 133 | fi |
| 134 | |
| 135 | # Print settings |
| 136 | if test "1" = "1"; then |
| 137 | echo "$F: calling ./configure with env vars:" |
| 138 | echo " CC = ${CC}" |
| 139 | echo " CXX = ${CXX}" |
| 140 | echo " CFLAGS = ${CFLAGS}" |
| 141 | echo " CXXFLAGS = ${CXXFLAGS}" |
| 142 | echo " LDFLAGS = ${LDFLAGS}" |
| 143 | echo " LIBS = ${LIBS}" |
| 144 | echo " AR = ${AR}" |
| 145 | echo " RANLIB = ${RANLIB}" |
| 146 | fi |
| 147 | |
| 148 | ./configure --host=${TARGET_HOST} --disable-video $* |