Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [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-8. By default, configure will use the maximum" |
| 20 | echo " platform level detected." |
| 21 | echo " TARGET_ABI Optionally specify a single target architecture, e.g." |
| 22 | echo " armeabi-v7a. By default, the target architecture is" |
| 23 | echo " armeabi." |
| 24 | echo "" |
| 25 | exit 0 |
| 26 | fi |
| 27 | |
| 28 | if test "x${ANDROID_NDK_ROOT}" = "x"; then |
| 29 | echo "$F error: ANDROID_NDK_ROOT must be specified" |
| 30 | exit 0 |
| 31 | fi |
| 32 | |
| 33 | #if test "$1" = "--simulator"; then |
| 34 | if test "1" = "0"; then |
| 35 | shift |
| 36 | TARGET_HOST="i686-android-linux" |
| 37 | TC_DIR="x86" |
| 38 | else |
| 39 | TARGET_HOST="arm-linux-androideabi" |
| 40 | TC_DIR=${TARGET_HOST} |
| 41 | fi |
| 42 | |
| 43 | if test "x$APP_PLATFORM" = "x"; then |
| 44 | APP_PLATFORM=`ls ${ANDROID_NDK_ROOT}/platforms/ | sed 's/android-//' | sort -gr | head -1` |
| 45 | APP_PLATFORM="android-${APP_PLATFORM}" |
| 46 | echo "$F: APP_PLATFORM not specified, using ${APP_PLATFORM}" |
| 47 | fi |
| 48 | |
| 49 | if test "x$TARGET_ABI" = "x"; then |
| 50 | TARGET_ABI="armeabi" |
| 51 | echo "$F: TARGET_ABI not specified, using ${TARGET_ABI}" |
| 52 | fi |
| 53 | |
| 54 | if test "$1" = "--use-ndk-cflags"; then |
| 55 | shift |
| 56 | 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 |
| 57 | if test "$i" = "-c"; then break; fi |
| 58 | 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 |
| 59 | NDK_CFLAGS="${NDK_CFLAGS} $i" |
| 60 | fi |
| 61 | if test "x`echo $i | grep 'gcc'`" != "x"; then |
| 62 | NDK_CC=$i |
| 63 | fi |
| 64 | done |
| 65 | export CFLAGS="${CFLAGS} ${NDK_CFLAGS}" |
| 66 | fi |
| 67 | |
| 68 | HOST_OS=$(uname -s) |
| 69 | case $HOST_OS in |
| 70 | Darwin) BUILD_MACHINE="darwin-x86";; |
| 71 | Linux) BUILD_MACHINE="linux-x86";; |
| 72 | CYGWIN*|*_NT-*) BUILD_MACHINE="windows";; |
| 73 | esac |
| 74 | |
| 75 | ANDROID_TC="${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-4.4.3/prebuilt/${BUILD_MACHINE}" |
| 76 | if test ! -d ${ANDROID_TC}; then |
| 77 | echo "$F error: unable to find directory ${ANDROID_TC} in Android NDK" |
| 78 | exit 1 |
| 79 | fi |
| 80 | |
| 81 | export ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-arm" |
| 82 | if test ! -d ${ANDROID_SYSROOT}; then |
| 83 | echo "$F error: unable to find sysroot dir ${ANDROID_SYSROOT} in Android NDK" |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc" |
| 88 | export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++" |
| 89 | |
| 90 | export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/" |
| 91 | export LIBS="${LIBS} -lc -lgcc" |
| 92 | export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include" |
| 93 | export CPPFLAGS="${CFLAGS}" |
| 94 | export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT}" |
| 95 | |
| 96 | # Print settings |
| 97 | if test "1" = "1"; then |
| 98 | echo "$F: calling ./configure with env vars:" |
| 99 | echo " CC = ${CC}" |
| 100 | echo " CXX = ${CXX}" |
| 101 | echo " CFLAGS = ${CFLAGS}" |
| 102 | echo " CXXFLAGS = ${CXXFLAGS}" |
| 103 | echo " LDFLAGS = ${LDFLAGS}" |
| 104 | echo " LIBS = ${LIBS}" |
| 105 | fi |
| 106 | |
| 107 | ./configure --host=${TARGET_HOST} --disable-video $* |