Chris@40: #!/bin/bash -e Chris@40: Chris@40: # Copyright (C) 2013 Erik de Castro Lopo Chris@40: # Chris@40: # All rights reserved. Chris@40: # Chris@40: # Redistribution and use in source and binary forms, with or without Chris@40: # modification, are permitted provided that the following conditions are Chris@40: # met: Chris@40: # Chris@40: # * Redistributions of source code must retain the above copyright Chris@40: # notice, this list of conditions and the following disclaimer. Chris@40: # * Neither the author nor the names of any contributors may be used Chris@40: # to endorse or promote products derived from this software without Chris@40: # specific prior written permission. Chris@40: # Chris@40: # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@40: # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED Chris@40: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR Chris@40: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR Chris@40: # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@40: # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@40: # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; Chris@40: # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, Chris@40: # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR Chris@40: # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF Chris@40: # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@40: Chris@40: # Android NDK version number; eg r8e, r9 etc Chris@40: ANDROID_NDK_VER=r9 Chris@40: Chris@40: # Android NDK gcc version; eg 4.7, 4.9 etc. Chris@40: ANDROID_GCC_VER=4.8 Chris@40: Chris@40: # Android API version; eg 9 (Android 2.3), 14 (Android 4.0) etc. Chris@40: ANDROID_API_VER=9 Chris@40: Chris@40: #------------------------------------------------------------------------------- Chris@40: # No more user config beyond here. Chris@40: Chris@40: BUILD_MACHINE=$(uname -s | tr 'A-Z' 'a-z')-$(uname -m) Chris@40: Chris@40: function die_with { Chris@40: echo $1 Chris@40: exit 1 Chris@40: } Chris@40: Chris@40: export CROSS_COMPILE=arm-linux-androideabi Chris@40: Chris@40: # I put all my dev stuff in here Chris@40: export DEV_PREFIX=$HOME/Android Chris@40: test -d ${DEV_PREFIX} || die_with "Error : DEV_PREFIX '$DEV_PREFIX' does not exist." Chris@40: Chris@40: # Don't forget to adjust this to your NDK path Chris@40: export ANDROID_NDK=${DEV_PREFIX}/android-ndk-${ANDROID_NDK_VER} Chris@40: test -d ${ANDROID_NDK} || die_with "Error : ANDROID_NDK '$ANDROID_NDK' does not exist." Chris@40: Chris@40: export ANDROID_PREFIX=${ANDROID_NDK}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VER}/prebuilt/${BUILD_MACHINE} Chris@40: test -d ${ANDROID_PREFIX} || die_with "Error : ANDROID_PREFIX '$ANDROID_PREFIX' does not exist." Chris@40: Chris@40: export SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API_VER}/arch-arm Chris@40: test -d ${SYSROOT} || die_with "Error : SYSROOT '$SYSROOT' does not exist." Chris@40: Chris@40: export CROSS_PREFIX=${ANDROID_PREFIX}/bin/${CROSS_COMPILE} Chris@40: test -f ${CROSS_PREFIX}-gcc || die_with "Error : CROSS_PREFIX compiler '${CROSS_PREFIX}-gcc' does not exist." Chris@40: Chris@40: Chris@40: # Non-exhaustive lists of compiler + binutils Chris@40: # Depending on what you compile, you might need more binutils than that Chris@40: export CPP=${CROSS_PREFIX}-cpp Chris@40: export AR=${CROSS_PREFIX}-ar Chris@40: export AS=${CROSS_PREFIX}-as Chris@40: export NM=${CROSS_PREFIX}-nm Chris@40: export CC=${CROSS_PREFIX}-gcc Chris@40: export CXX=${CROSS_PREFIX}-g++ Chris@40: export LD=${CROSS_PREFIX}-ld Chris@40: export RANLIB=${CROSS_PREFIX}-ranlib Chris@40: Chris@40: # Don't mix up .pc files from your host and build target Chris@40: export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig Chris@40: Chris@40: # Set up the needed FLAGS. Chris@40: export CFLAGS="${CFLAGS} -gstabs --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include" Chris@40: 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" Chris@40: Chris@40: export CPPFLAGS="${CFLAGS}" Chris@40: export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib" Chris@40: Chris@40: # Create a symlink to the gdbclient. Chris@40: test -h gdbclient || ln -s ${ANDROID_PREFIX}/bin/arm-linux-androideabi-gdb gdbclient Chris@40: Chris@40: ./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$@"