blob: 09553c7c64f3a40b72087f8b8babd3f7c081034c [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001#!/bin/sh
2#
3
4F="configure-android"
5
6if 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
26fi
27
28if test "x${ANDROID_NDK_ROOT}" = "x"; then
29 echo "$F error: ANDROID_NDK_ROOT must be specified"
30 exit 0
31fi
32
33#if test "$1" = "--simulator"; then
34if test "1" = "0"; then
35 shift
36 TARGET_HOST="i686-android-linux"
37 TC_DIR="x86"
38else
39 TARGET_HOST="arm-linux-androideabi"
40 TC_DIR=${TARGET_HOST}
41fi
42
43if 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}"
47fi
48
49if test "x$TARGET_ABI" = "x"; then
50 TARGET_ABI="armeabi"
51 echo "$F: TARGET_ABI not specified, using ${TARGET_ABI}"
52fi
53
54if 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}"
66fi
67
68HOST_OS=$(uname -s)
69case $HOST_OS in
70 Darwin) BUILD_MACHINE="darwin-x86";;
71 Linux) BUILD_MACHINE="linux-x86";;
72 CYGWIN*|*_NT-*) BUILD_MACHINE="windows";;
73esac
74
Alexandre Lision440ce6b2013-09-19 15:08:09 -040075case $(uname -p) in
76 x86_64) BUILD_MACHINE="linux-x86_64"
77esac
78
79ANDROID_TC="${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-4.8/prebuilt/${BUILD_MACHINE}"
Tristan Matthews0a329cc2013-07-17 13:20:14 -040080if test ! -d ${ANDROID_TC}; then
81 echo "$F error: unable to find directory ${ANDROID_TC} in Android NDK"
82 exit 1
83fi
84
85export ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/platforms/${APP_PLATFORM}/arch-arm"
86if test ! -d ${ANDROID_SYSROOT}; then
87 echo "$F error: unable to find sysroot dir ${ANDROID_SYSROOT} in Android NDK"
88 exit 1
89fi
90
91export CC="${ANDROID_TC}/bin/${TARGET_HOST}-gcc"
92export CXX="${ANDROID_TC}/bin/${TARGET_HOST}-g++"
93
94export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/"
95export LIBS="${LIBS} -lc -lgcc"
96export CFLAGS="${CFLAGS} -I${ANDROID_SYSROOT}/usr/include"
97export CPPFLAGS="${CFLAGS}"
98export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT}"
99
100# Print settings
101if test "1" = "1"; then
102 echo "$F: calling ./configure with env vars:"
103 echo " CC = ${CC}"
104 echo " CXX = ${CXX}"
105 echo " CFLAGS = ${CFLAGS}"
106 echo " CXXFLAGS = ${CXXFLAGS}"
107 echo " LDFLAGS = ${LDFLAGS}"
108 echo " LIBS = ${LIBS}"
109fi
110
111./configure --host=${TARGET_HOST} --disable-video $*