blob: 02298a9719be74419fb2eb09205d148626ca1ec3 [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."
Alexandre Lision94f06ba2013-12-09 16:28:33 -050019 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."
Alexandre Lision8af73cb2013-12-10 14:11:20 -050025 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."
Tristan Matthews0a329cc2013-07-17 13:20:14 -040030 echo ""
31 exit 0
32fi
33
34if test "x${ANDROID_NDK_ROOT}" = "x"; then
35 echo "$F error: ANDROID_NDK_ROOT must be specified"
36 exit 0
37fi
38
39#if test "$1" = "--simulator"; then
40if test "1" = "0"; then
41 shift
42 TARGET_HOST="i686-android-linux"
43 TC_DIR="x86"
44else
45 TARGET_HOST="arm-linux-androideabi"
46 TC_DIR=${TARGET_HOST}
47fi
48
49if 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}"
53fi
54
55if test "x$TARGET_ABI" = "x"; then
56 TARGET_ABI="armeabi"
57 echo "$F: TARGET_ABI not specified, using ${TARGET_ABI}"
58fi
59
60if test "$1" = "--use-ndk-cflags"; then
61 shift
Alexandre Lision94f06ba2013-12-09 16:28:33 -050062 ADD_CFLAGS="1"
Alexandre Lision8af73cb2013-12-10 14:11:20 -050063 if test "x${IGNORE_CFLAGS}" = "x"; then
64 IGNORE_CFLAGS="\-M\|\-f*stack\|\-f*alias"
65 fi
Tristan Matthews0a329cc2013-07-17 13:20:14 -040066 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
Alexandre Lision94f06ba2013-12-09 16:28:33 -050067 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"
Tristan Matthews0a329cc2013-07-17 13:20:14 -040075 fi
Alexandre Lision94f06ba2013-12-09 16:28:33 -050076
77 # Parse NDK CFLAGS
Alexandre Lision8af73cb2013-12-10 14:11:20 -050078 if test "x${NDK_CC}" != "x" -a "x`echo $i|grep 'hello-jni'`" = "x" -a "${ADD_CFLAGS}" = "1"; then
Alexandre Lision94f06ba2013-12-09 16:28:33 -050079 if test "$i" = "-c"; then ADD_CFLAGS="0"; else
Alexandre Lision8af73cb2013-12-10 14:11:20 -050080 if test "x`echo $i|grep ${IGNORE_CFLAGS}`" = "x"; then
81 NDK_CFLAGS="${NDK_CFLAGS} $i"
82 fi
Alexandre Lision94f06ba2013-12-09 16:28:33 -050083 fi
84 fi
85
86 # Find gcc toolchain
87 if test "x${NDK_CC}" = "x" -a "x`echo $i | grep 'gcc'`" != "x"; then
Tristan Matthews0a329cc2013-07-17 13:20:14 -040088 NDK_CC=$i
89 fi
Alexandre Lision94f06ba2013-12-09 16:28:33 -050090 # Find g++ toolchain
91 if test "x`echo $i | grep 'g++'`" != "x"; then
92 NDK_CXX=$i
93 fi
Tristan Matthews0a329cc2013-07-17 13:20:14 -040094 done
Alexandre Lision94f06ba2013-12-09 16:28:33 -050095
96 export CC="${NDK_CC}"
97 export CXX="${NDK_CXX}"
Alexandre Lision8af73cb2013-12-10 14:11:20 -050098 export AR=`echo ${NDK_CXX}|sed 's/-g++/-ar/'`;
99 export RANLIB=`echo ${NDK_CXX}|sed 's/-g++/-ranlib/'`;
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500100
101 export LDFLAGS="${LDFLAGS} -nostdlib -L${ANDROID_SYSROOT}/usr/lib/"
102 export LIBS="${LIBS} -lc -lgcc"
Alexandre Lision8af73cb2013-12-10 14:11:20 -0500103 export CFLAGS="${NDK_CFLAGS} ${CFLAGS}"
Alexandre Lision0e143012014-01-22 11:02:46 -0500104 export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
105 export CXXFLAGS="${NDK_CXXFLAGS} -fexceptions -frtti"
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500106
107else
108
109 ANDROID_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/toolchains/${TC_DIR}-* | sed 's/clang/0/' | sort -gr | head -1`
Alexandre Lision8af73cb2013-12-10 14:11:20 -0500110 ANDROID_TC=`ls -d ${ANDROID_TC_VER}/prebuilt/* | grep -v gdbserver | head -1`
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500111 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++"
Alexandre Lision8af73cb2013-12-10 14:11:20 -0500124 export AR="${ANDROID_TC}/bin/${TARGET_HOST}-ar"
125 export RANLIB="${ANDROID_TC}/bin/${TARGET_HOST}-ranlib"
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500126
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"
Alexandre Lision0e143012014-01-22 11:02:46 -0500130 export CPPFLAGS="${CFLAGS} -fexceptions -frtti"
131 export CXXFLAGS="${CXXFLAGS} -shared --sysroot=${ANDROID_SYSROOT} -fexceptions -frtti"
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500132
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400133fi
134
Alexandre Lision0e143012014-01-22 11:02:46 -0500135# C++ STL
136# Note: STL for pjsua2 sample app is specified in pjsip-apps/src/swig/java/android/jni/Application.mk
137
138# gnustl
139STDCPP_TC_VER=`ls -d ${ANDROID_NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/[0-9]* | sort -gr | head -1`
140STDCPP_CFLAGS="-I${STDCPP_TC_VER}/include -I${STDCPP_TC_VER}/libs/armeabi/include"
141STDCPP_LIBS="${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o -lgnustl_static"
142STDCPP_LDFLAGS="-L${STDCPP_TC_VER}/libs/armeabi"
143
144# stlport
145#STDCPP_CFLAGS="-I${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/stlport"
146#STDCPP_LIBS="${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o -lstlport_static -ldl"
147#STDCPP_LDFLAGS="-L${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/libs/armeabi"
148
149export CFLAGS="${CFLAGS} ${STDCPP_CFLAGS}"
150export LIBS="${STDCPP_LIBS} ${LIBS}"
151export LDFLAGS="${LDFLAGS} ${STDCPP_LDFLAGS}"
152
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400153# Print settings
154if test "1" = "1"; then
155 echo "$F: calling ./configure with env vars:"
156 echo " CC = ${CC}"
157 echo " CXX = ${CXX}"
158 echo " CFLAGS = ${CFLAGS}"
159 echo " CXXFLAGS = ${CXXFLAGS}"
160 echo " LDFLAGS = ${LDFLAGS}"
161 echo " LIBS = ${LIBS}"
Alexandre Lision8af73cb2013-12-10 14:11:20 -0500162 echo " AR = ${AR}"
163 echo " RANLIB = ${RANLIB}"
Tristan Matthews0a329cc2013-07-17 13:20:14 -0400164fi
165
Alexandre Lision94f06ba2013-12-09 16:28:33 -0500166./configure --host=${TARGET_HOST} --disable-video $*