Unverified Commit 98e82ddf authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3828 from sappo/master

Android build helper improvement + fix for prefix dir
parents 91792109 67e6a8c2
......@@ -22,6 +22,10 @@ To specify the minimum sdk version set the environment variable below:
export MIN_SDK_VERSION=21 # Default value if unset
To specify the prefix directory set the environment variable below:
export ANDROID_BUILD_DIR=./builds/android/prefix/<android_arch> # Default value if unset
## Build
In the android directory, run:
......
......@@ -69,12 +69,36 @@ function android_build_check_fail {
fi
}
function android_build_arch {
function android_build_set_env {
BUILD_ARCH=$1
export TOOLCHAIN_PATH="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin"
export TOOLCHAIN_HOST=$1
export TOOLCHAIN_COMP=$2
export TOOLCHAIN_CXXSTL=$3
export TOOLCHAIN_ARCH=$4
# Set variables for each architecture
if [ $BUILD_ARCH == "arm" ]; then
export TOOLCHAIN_HOST="arm-linux-androideabi"
export TOOLCHAIN_COMP="armv7a-linux-androideabi${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="armeabi-v7a"
export TOOLCHAIN_ARCH="arm"
elif [ $BUILD_ARCH == "x86" ]; then
export TOOLCHAIN_HOST="i686-linux-android"
export TOOLCHAIN_COMP="i686-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="x86"
export TOOLCHAIN_ARCH="x86"
elif [ $BUILD_ARCH == "arm64" ]; then
export TOOLCHAIN_HOST="aarch64-linux-android"
export TOOLCHAIN_COMP="aarch64-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="arm64-v8a"
export TOOLCHAIN_ARCH="arm64"
elif [ $BUILD_ARCH == "x86_64" ]; then
export TOOLCHAIN_HOST="x86_64-linux-android"
export TOOLCHAIN_COMP="x86_64-linux-android${MIN_SDK_VERSION}"
export TOOLCHAIN_ABI="x86_64"
export TOOLCHAIN_ARCH="x86_64"
fi
export ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
export ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
}
function android_build_env {
......@@ -101,9 +125,9 @@ function android_build_env {
ANDROID_BUILD_FAIL+=(" (eg. \"armv7a-linux-androideabi\")")
fi
if [ -z "$TOOLCHAIN_CXXSTL" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_CXXSTL environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7abi\")")
if [ -z "$TOOLCHAIN_ABI" ]; then
ANDROID_BUILD_FAIL+=("Please set the TOOLCHAIN_ABI environment variable")
ANDROID_BUILD_FAIL+=(" (eg. \"armeabi-v7a\")")
fi
if [ -z "$TOOLCHAIN_ARCH" ]; then
......@@ -129,15 +153,11 @@ function android_build_env {
##
# Set up some local variables and check them
ANDROID_BUILD_SYSROOT="${ANDROID_NDK_ROOT}/platforms/android-${MIN_SDK_VERSION}/arch-${TOOLCHAIN_ARCH}"
if [ ! -d "$ANDROID_BUILD_SYSROOT" ]; then
ANDROID_BUILD_FAIL+=("The ANDROID_BUILD_SYSROOT directory does not exist")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_SYSROOT}")
fi
ANDROID_BUILD_PREFIX="${ANDROID_BUILD_DIR}/prefix/${TOOLCHAIN_ARCH}"
mkdir -p "$ANDROID_BUILD_PREFIX" || {
ANDROID_BUILD_FAIL+=("Failed to make ANDROID_BUILD_PREFIX directory")
ANDROID_BUILD_FAIL+=(" ${ANDROID_BUILD_PREFIX}")
......@@ -211,7 +231,7 @@ function android_build_opts {
local LIBS="-lc -lgcc -ldl -lm -llog -lc++_shared"
local LDFLAGS="-L${ANDROID_BUILD_PREFIX}/lib"
LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_CXXSTL}"
LDFLAGS+=" -L${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${TOOLCHAIN_ABI}"
CFLAGS+=" -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE"
CPPFLAGS+=" -I${ANDROID_BUILD_PREFIX}/include"
......
......@@ -6,16 +6,15 @@ function usage {
# Use directory of current script as the build directory and working directory
cd "$( dirname "${BASH_SOURCE[0]}" )"
ANDROID_BUILD_DIR="$(pwd)"
ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
# Get access to android_build functions and variables
source ${ANDROID_BUILD_DIR}/android_build_helper.sh
source ./android_build_helper.sh
# Choose a C++ standard library implementation from the ndk
ANDROID_BUILD_CXXSTL="gnustl_shared_49"
BUILD_ARCH=$1
if [ -z $BUILD_ARCH ]; then
usage
exit 1
......@@ -41,41 +40,8 @@ export NDK_VERSION=${NDK_VERSION:-android-ndk-r20}
# SDK version 21 is the minimum version for 64-bit builds.
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
# Set variables for each architecture
HOST_ARM="arm-linux-androideabi"
HOST_ARM64="aarch64-linux-android"
HOST_X86="i686-linux-android"
HOST_X86_64="x86_64-linux-android"
COMP_ARM="armv7a-linux-androideabi${MIN_SDK_VERSION}"
COMP_ARM64="aarch64-linux-android${MIN_SDK_VERSION}"
COMP_X86="i686-linux-android${MIN_SDK_VERSION}"
COMP_X86_64="x86_64-linux-android${MIN_SDK_VERSION}"
CXXSTL_ARM="armeabi-v7a"
CXXSTL_ARM64="arm64-v8a"
CXXSTL_X86="x86"
CXXSTL_X86_64="x86_64"
ARCH_ARM="arm"
ARCH_ARM64="arm64"
ARCH_X86="x86"
ARCH_X86_64="x86_64"
if [ $BUILD_ARCH == "arm" ]; then
android_build_arch $HOST_ARM $COMP_ARM $CXXSTL_ARM $ARCH_ARM
elif [ $BUILD_ARCH == "x86" ]; then
android_build_arch $HOST_X86 $COMP_X86 $CXXSTL_X86 $ARCH_X86
elif [ $BUILD_ARCH == "arm64" ]; then
android_build_arch $HOST_ARM64 $COMP_ARM64 $CXXSTL_ARM64 $ARCH_ARM64
elif [ $BUILD_ARCH == "x86_64" ]; then
android_build_arch $HOST_X86_64 $COMP_X86_64 $CXXSTL_X86_64 $ARCH_X86_64
else
usage
exit 1
fi
# Set up android build environment and set ANDROID_BUILD_OPTS array
android_build_set_env $BUILD_ARCH
android_build_env
android_build_opts
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment