1#!/bin/bash -e 2 3# Copyright (C) 2013-2016 Erik de Castro Lopo <erikd@mega-nerd.com> 4# 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are 9# met: 10# 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. 16# 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. 28 29# Android NDK version number; eg r10, r10b etc 30ANDROID_NDK_VER=${ANDROID_NDK_VER:-r10} 31 32# Android NDK gcc version; eg 4.8, 4.9 etc. 33ANDROID_GCC_VER=${ANDROID_GCC_VER:-4.9} 34 35# Android API version; eg 14 (Android 4.0), 21 (Android 5.0) etc. 36ANDROID_API_VER=${ANDROID_API_VER:-14} 37 38ANDROID_TARGET=${ANDROID_TARGET:-arm-linux-androideabi} 39 40if 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." 43 exit 1 44 fi 45 46#------------------------------------------------------------------------------- 47# No more user config beyond here. 48 49BUILD_MACHINE=$(uname -s | tr 'A-Z' 'a-z')-$(uname -m) 50 51function die_with { 52 echo $1 53 exit 1 54} 55 56export CROSS_COMPILE=${ANDROID_TARGET} 57 58# Don't forget to adjust this to your NDK path 59export ANDROID_NDK=${ANDROID_TOOLCHAIN_HOME}/android-ndk-${ANDROID_NDK_VER} 60test -d ${ANDROID_NDK} || die_with "Error : ANDROID_NDK '$ANDROID_NDK' does not exist." 61 62export ANDROID_PREFIX=${ANDROID_NDK}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VER}/prebuilt/${BUILD_MACHINE} 63test -d ${ANDROID_PREFIX} || die_with "Error : ANDROID_PREFIX '$ANDROID_PREFIX' does not exist." 64 65export SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API_VER}/arch-arm 66test -d ${SYSROOT} || die_with "Error : SYSROOT '$SYSROOT' does not exist." 67 68export CROSS_PREFIX=${ANDROID_PREFIX}/bin/${CROSS_COMPILE} 69test -f ${CROSS_PREFIX}-gcc || die_with "Error : CROSS_PREFIX compiler '${CROSS_PREFIX}-gcc' does not exist." 70 71 72# Non-exhaustive lists of compiler + binutils 73# Depending on what you compile, you might need more binutils than that 74export CPP=${CROSS_PREFIX}-cpp 75export AR=${CROSS_PREFIX}-ar 76export AS=${CROSS_PREFIX}-as 77export NM=${CROSS_PREFIX}-nm 78export CC=${CROSS_PREFIX}-gcc 79export CXX=${CROSS_PREFIX}-g++ 80export LD=${CROSS_PREFIX}-ld 81export RANLIB=${CROSS_PREFIX}-ranlib 82 83# Don't mix up .pc files from your host and build target 84export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig 85 86# Set up the needed FLAGS. 87export CFLAGS="${CFLAGS} -gstabs --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include" 88export 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" 89 90export CPPFLAGS="${CFLAGS}" 91export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib" 92 93# Create a symlink to the gdbclient. 94test -h gdbclient || ln -s ${ANDROID_PREFIX}/bin/arm-linux-androideabi-gdb gdbclient 95 96./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$@" 97