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