3 # Copyright (C) 2013-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Neither the author nor the names of any contributors may be used
14 # to endorse or promote products derived from this software without
15 # specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Android NDK version number; eg r10, r10b etc
30 ANDROID_NDK_VER=${ANDROID_NDK_VER:-r10}
32 # Android NDK gcc version; eg 4.8, 4.9 etc.
33 ANDROID_GCC_VER=${ANDROID_GCC_VER:-4.9}
35 # Android API version; eg 14 (Android 4.0), 21 (Android 5.0) etc.
36 ANDROID_API_VER=${ANDROID_API_VER:-14}
38 ANDROID_TARGET=${ANDROID_TARGET:-arm-linux-androideabi}
40 if test -z ${ANDROID_TOOLCHAIN_HOME} ; then
41 echo "Environment variable ANDROID_TOOLCHAIN_HOME not defined."
42 echo "This should point to the directory containing the Android NDK."
46 #-------------------------------------------------------------------------------
47 # No more user config beyond here.
49 BUILD_MACHINE=$(uname -s | tr 'A-Z' 'a-z')-$(uname -m)
56 export CROSS_COMPILE=${ANDROID_TARGET}
58 # Don't forget to adjust this to your NDK path
59 export ANDROID_NDK=${ANDROID_TOOLCHAIN_HOME}/android-ndk-${ANDROID_NDK_VER}
60 test -d ${ANDROID_NDK} || die_with "Error : ANDROID_NDK '$ANDROID_NDK' does not exist."
62 export ANDROID_PREFIX=${ANDROID_NDK}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VER}/prebuilt/${BUILD_MACHINE}
63 test -d ${ANDROID_PREFIX} || die_with "Error : ANDROID_PREFIX '$ANDROID_PREFIX' does not exist."
65 export SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API_VER}/arch-arm
66 test -d ${SYSROOT} || die_with "Error : SYSROOT '$SYSROOT' does not exist."
68 export CROSS_PREFIX=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}
69 test -f ${CROSS_PREFIX}-gcc || die_with "Error : CROSS_PREFIX compiler '${CROSS_PREFIX}-gcc' does not exist."
72 # Non-exhaustive lists of compiler + binutils
73 # Depending on what you compile, you might need more binutils than that
74 export CPP=${CROSS_PREFIX}-cpp
75 export AR=${CROSS_PREFIX}-ar
76 export AS=${CROSS_PREFIX}-as
77 export NM=${CROSS_PREFIX}-nm
78 export CC=${CROSS_PREFIX}-gcc
79 export CXX=${CROSS_PREFIX}-g++
80 export LD=${CROSS_PREFIX}-ld
81 export RANLIB=${CROSS_PREFIX}-ranlib
83 # Don't mix up .pc files from your host and build target
84 export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
86 # Set up the needed FLAGS.
87 export CFLAGS="${CFLAGS} -gstabs --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
88 export CXXFLAGS="${CXXFLAGS} -gstabs -fno-exceptions --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/include/ -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/libs/armeabi/include"
90 export CPPFLAGS="${CFLAGS}"
91 export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"
93 # Create a symlink to the gdbclient.
94 test -h gdbclient || ln -s ${ANDROID_PREFIX}/bin/arm-linux-androideabi-gdb gdbclient
96 ./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$@"