Add sanity check to setenv-*.sh scripts

Prompt user to source the script when required. Whitespace check-in
pull/853/head
Jeffrey Walton 2019-05-21 05:37:40 -04:00
parent 3e897eb0f6
commit 1973674732
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
7 changed files with 480 additions and 445 deletions

View File

@ -18,6 +18,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
unset IS_CROSS_COMPILE unset IS_CROSS_COMPILE
unset IS_IOS unset IS_IOS
@ -38,8 +43,8 @@ unset CPP CC CXX LD AS AR RANLIB STRIP
# Similar to a "make clean" # Similar to a "make clean"
if [ x"${1-}" = "xunset" ]; then if [ x"${1-}" = "xunset" ]; then
echo "Unsetting script variables. PATH may remain tainted" echo "Unsetting script variables. PATH may remain tainted"
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0
fi fi
# Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library. # Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library.
@ -47,7 +52,7 @@ fi
# AOSP_TOOLCHAIN_SUFFIX=4.8 # AOSP_TOOLCHAIN_SUFFIX=4.8
# AOSP_TOOLCHAIN_SUFFIX=4.9 # AOSP_TOOLCHAIN_SUFFIX=4.9
if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then
AOSP_TOOLCHAIN_SUFFIX=4.9 AOSP_TOOLCHAIN_SUFFIX=4.9
fi fi
# Set AOSP_API_VERSION to the API you want to use. 'armeabi' and 'armeabi-v7a' need # Set AOSP_API_VERSION to the API you want to use. 'armeabi' and 'armeabi-v7a' need
@ -63,15 +68,15 @@ fi
# AOSP_API_VERSION="21" # Android 5.0 and above # AOSP_API_VERSION="21" # Android 5.0 and above
# AOSP_API_VERSION="23" # Android 6.0 and above # AOSP_API_VERSION="23" # Android 6.0 and above
if [ -z "${AOSP_API_VERSION-}" ]; then if [ -z "${AOSP_API_VERSION-}" ]; then
AOSP_API_VERSION="21" AOSP_API_VERSION="21"
fi fi
if [ -z "${AOSP_API-}" ]; then if [ -z "${AOSP_API-}" ]; then
AOSP_API="android-${AOSP_API_VERSION}" AOSP_API="android-${AOSP_API_VERSION}"
else else
echo "WARNING: Using AOSP_API has been deprecated. Please use AOSP_API_VERSION instead." echo "WARNING: Using AOSP_API has been deprecated. Please use AOSP_API_VERSION instead."
echo "If you set for example AOSP_API=android-23 then now instead set AOSP_API_VERSION=23" echo "If you set for example AOSP_API=android-23 then now instead set AOSP_API_VERSION=23"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
##################################################################### #####################################################################
@ -82,104 +87,104 @@ fi
# like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e. # like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e.
if [ -z "${ANDROID_NDK_ROOT-}" ]; then if [ -z "${ANDROID_NDK_ROOT-}" ]; then
ANDROID_NDK_ROOT=$(find /opt -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find /opt -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
fi fi
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
fi fi
if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then
ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle"
fi fi
fi fi
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
##################################################################### #####################################################################
if [ "$#" -lt 1 ]; then if [ "$#" -lt 1 ]; then
THE_ARCH=armv7a-neon THE_ARCH=armv7a-neon
else else
THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") THE_ARCH=$(tr [A-Z] [a-z] <<< "$1")
fi fi
# https://developer.android.com/ndk/guides/abis.html # https://developer.android.com/ndk/guides/abis.html
case "$THE_ARCH" in case "$THE_ARCH" in
arm|armv5|armv6|armv7|armeabi) arm|armv5|armv6|armv7|armeabi)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi" AOSP_ABI="armeabi"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti"
;; ;;
armv7a|armv7-a|armeabi-v7a) armv7a|armv7-a|armeabi-v7a)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi-v7a" AOSP_ABI="armeabi-v7a"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -DCRYPTOPP_DISABLE_ASM -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -DCRYPTOPP_DISABLE_ASM -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti"
;; ;;
hard|armv7a-hard|armeabi-v7a-hard) hard|armv7a-hard|armeabi-v7a-hard)
echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
#TOOLCHAIN_ARCH="arm-linux-androideabi" #TOOLCHAIN_ARCH="arm-linux-androideabi"
#TOOLCHAIN_NAME="arm-linux-androideabi" #TOOLCHAIN_NAME="arm-linux-androideabi"
#AOSP_ABI="armeabi-v7a" #AOSP_ABI="armeabi-v7a"
#AOSP_ARCH="arch-arm" #AOSP_ARCH="arch-arm"
#AOSP_FLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfpu=vfpv3-d16 -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti -Wl,--no-warn-mismatch -Wl,-lm_hard" #AOSP_FLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfpu=vfpv3-d16 -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti -Wl,--no-warn-mismatch -Wl,-lm_hard"
;; ;;
neon|armv7a-neon) neon|armv7a-neon)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi-v7a" AOSP_ABI="armeabi-v7a"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti"
;; ;;
armv8|armv8a|aarch64|arm64|arm64-v8a) armv8|armv8a|aarch64|arm64|arm64-v8a)
TOOLCHAIN_ARCH="aarch64-linux-android" TOOLCHAIN_ARCH="aarch64-linux-android"
TOOLCHAIN_NAME="aarch64-linux-android" TOOLCHAIN_NAME="aarch64-linux-android"
AOSP_ABI="arm64-v8a" AOSP_ABI="arm64-v8a"
AOSP_ARCH="arch-arm64" AOSP_ARCH="arch-arm64"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
mips|mipsel) mips|mipsel)
TOOLCHAIN_ARCH="mipsel-linux-android" TOOLCHAIN_ARCH="mipsel-linux-android"
TOOLCHAIN_NAME="mipsel-linux-android" TOOLCHAIN_NAME="mipsel-linux-android"
AOSP_ABI="mips" AOSP_ABI="mips"
AOSP_ARCH="arch-mips" AOSP_ARCH="arch-mips"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
mips64|mipsel64|mips64el) mips64|mipsel64|mips64el)
TOOLCHAIN_ARCH="mips64el-linux-android" TOOLCHAIN_ARCH="mips64el-linux-android"
TOOLCHAIN_NAME="mips64el-linux-android" TOOLCHAIN_NAME="mips64el-linux-android"
AOSP_ABI="mips64" AOSP_ABI="mips64"
AOSP_ARCH="arch-mips64" AOSP_ARCH="arch-mips64"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
x86) x86)
TOOLCHAIN_ARCH="x86" TOOLCHAIN_ARCH="x86"
TOOLCHAIN_NAME="i686-linux-android" TOOLCHAIN_NAME="i686-linux-android"
AOSP_ABI="x86" AOSP_ABI="x86"
AOSP_ARCH="arch-x86" AOSP_ARCH="arch-x86"
AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti"
;; ;;
x86_64|x64) x86_64|x64)
TOOLCHAIN_ARCH="x86_64" TOOLCHAIN_ARCH="x86_64"
TOOLCHAIN_NAME="x86_64-linux-android" TOOLCHAIN_NAME="x86_64-linux-android"
AOSP_ABI="x86_64" AOSP_ABI="x86_64"
AOSP_ARCH="arch-x86_64" AOSP_ARCH="arch-x86_64"
AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti"
;; ;;
*) *)
echo "ERROR: Unknown architecture $1" echo "ERROR: Unknown architecture $1"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
;; ;;
esac esac
##################################################################### #####################################################################
@ -209,79 +214,79 @@ export AOSP_SYS_ARCH_INC="$ANDROID_NDK_ROOT/sysroot/usr/include/$TOOLCHAIN_NAME"
AOSP_TOOLCHAIN_PATH="" AOSP_TOOLCHAIN_PATH=""
for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86" for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86"
do do
if [ -d "$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" ]; then if [ -d "$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" ]; then
AOSP_TOOLCHAIN_PATH="$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" AOSP_TOOLCHAIN_PATH="$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin"
break break
fi fi
done done
# Error checking # Error checking
if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then
echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then
echo "ERROR: Failed to find Android cpp. Please edit this script." echo "ERROR: Failed to find Android cpp. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then
echo "ERROR: Failed to find Android gcc. Please edit this script." echo "ERROR: Failed to find Android gcc. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then
echo "ERROR: Failed to find Android g++. Please edit this script." echo "ERROR: Failed to find Android g++. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then
echo "ERROR: Failed to find Android ranlib. Please edit this script." echo "ERROR: Failed to find Android ranlib. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then
echo "ERROR: Failed to find Android ar. Please edit this script." echo "ERROR: Failed to find Android ar. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then
echo "ERROR: Failed to find Android as. Please edit this script." echo "ERROR: Failed to find Android as. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then
echo "ERROR: Failed to find Android ld. Please edit this script." echo "ERROR: Failed to find Android ld. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Only modify/export PATH if AOSP_TOOLCHAIN_PATH good # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good
if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then
# And only modify PATH if AOSP_TOOLCHAIN_PATH is not present # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present
LEN=${#AOSP_TOOLCHAIN_PATH} LEN=${#AOSP_TOOLCHAIN_PATH}
SUBSTR=${PATH:0:$LEN} SUBSTR=${PATH:0:$LEN}
if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then
export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH"
fi fi
fi fi
##################################################################### #####################################################################
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then
echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script." echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then
echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script." echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Android SYSROOT. It will be used on the command line with --sysroot # Android SYSROOT. It will be used on the command line with --sysroot
@ -294,76 +299,76 @@ export AOSP_LD_SYSROOT="$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH"
# Android STL. We support GNU, LLVM and STLport out of the box. # Android STL. We support GNU, LLVM and STLport out of the box.
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
THE_STL=gnu-shared THE_STL=gnu-shared
else else
THE_STL=$(tr [A-Z] [a-z] <<< "$2") THE_STL=$(tr [A-Z] [a-z] <<< "$2")
fi fi
# LLVM include directory may be different depending on NDK version. Default to new location (latest NDK checked: r16beta1). # LLVM include directory may be different depending on NDK version. Default to new location (latest NDK checked: r16beta1).
LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/include" LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/include"
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libcxx/include" LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libcxx/include"
fi fi
case "$THE_STL" in case "$THE_STL" in
stlport-static) stlport-static)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_static.a"
;; ;;
stlport|stlport-shared) stlport|stlport-shared)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_shared.so"
;; ;;
gabi++-static|gnu-static) gabi++-static|gnu-static)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include"
AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include" AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a"
;; ;;
gnu|gabi++|gnu-shared|gabi++-shared) gnu|gabi++|gnu-shared|gabi++-shared)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include"
AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include" AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so"
;; ;;
llvm-static) llvm-static)
echo WARNING: llvm is still in experimental state and migth not work as expected echo WARNING: llvm is still in experimental state and migth not work as expected
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a"
;; ;;
llvm|llvm-shared) llvm|llvm-shared)
echo WARNING: llvm is still in experimental state and migth not work as expected echo WARNING: llvm is still in experimental state and migth not work as expected
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so"
;; ;;
*) *)
echo "ERROR: Unknown STL library $2" echo "ERROR: Unknown STL library $2"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
esac esac
# Error checking # Error checking
if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then
echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." echo "ERROR: AOSP_STL_INC is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_STL_LIB" ]; then if [ ! -e "$AOSP_STL_LIB" ]; then
echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
export AOSP_STL_INC export AOSP_STL_INC
export AOSP_STL_LIB export AOSP_STL_LIB
if [ ! -z "$AOSP_BITS_INC" ]; then if [ ! -z "$AOSP_BITS_INC" ]; then
export AOSP_BITS_INC export AOSP_BITS_INC
fi fi
# Now that we are using cpu-features from Android rather than CPU probing, we # Now that we are using cpu-features from Android rather than CPU probing, we
@ -371,14 +376,14 @@ fi
# directory and then build it. # directory and then build it.
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then
echo "ERROR: Unable to locate cpu-features.h" echo "ERROR: Unable to locate cpu-features.h"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" .
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then
echo "ERROR: Unable to locate cpu-features.c" echo "ERROR: Unable to locate cpu-features.c"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" .
@ -409,33 +414,33 @@ fi
COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libstdc\+\+') COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libstdc\+\+')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using GNU's runtime and STL library. Please ensure the resulting" echo "You are using GNU's runtime and STL library. Please ensure the resulting"
echo "binary meets licensing requirements. If you can't use GNU's runtime" echo "binary meets licensing requirements. If you can't use GNU's runtime"
echo "and STL library, then reconfigure with stlport or llvm. Also see" echo "and STL library, then reconfigure with stlport or llvm. Also see"
echo "http://code.google.com/p/android/issues/detail?id=216331" echo "http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport') COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using STLport's runtime and STL library. STLport could cause problems" echo "You are using STLport's runtime and STL library. STLport could cause problems"
echo "if the resulting binary is used in other environments, like a QT project." echo "if the resulting binary is used in other environments, like a QT project."
echo "Also see http://code.google.com/p/android/issues/detail?id=216331" echo "Also see http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+') COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using LLVM's runtime and STL library. LLVM could cause problems" echo "You are using LLVM's runtime and STL library. LLVM could cause problems"
echo "if the resulting binary is used in other environments, like a QT project." echo "if the resulting binary is used in other environments, like a QT project."
echo "Also see http://code.google.com/p/android/issues/detail?id=216331" echo "Also see http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
echo echo
@ -446,4 +451,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -20,6 +20,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
unset IS_CROSS_COMPILE unset IS_CROSS_COMPILE
unset IS_IOS unset IS_IOS
@ -38,8 +43,8 @@ unset CPP CC CXX LD AS AR RANLIB STRIP
# Similar to a "make clean" # Similar to a "make clean"
if [ x"${1-}" = "xunset" ]; then if [ x"${1-}" = "xunset" ]; then
echo "Unsetting script variables. PATH may remain tainted" echo "Unsetting script variables. PATH may remain tainted"
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0
fi fi
# Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library. # Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library.
@ -47,7 +52,7 @@ fi
# AOSP_TOOLCHAIN_SUFFIX=4.8 # AOSP_TOOLCHAIN_SUFFIX=4.8
# AOSP_TOOLCHAIN_SUFFIX=4.9 # AOSP_TOOLCHAIN_SUFFIX=4.9
if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then
AOSP_TOOLCHAIN_SUFFIX=4.9 AOSP_TOOLCHAIN_SUFFIX=4.9
fi fi
# Set AOSP_API to the API you want to use. 'armeabi' and 'armeabi-v7a' need # Set AOSP_API to the API you want to use. 'armeabi' and 'armeabi-v7a' need
@ -63,7 +68,7 @@ fi
# AOSP_API="android-21" # Android 5.0 and above # AOSP_API="android-21" # Android 5.0 and above
# AOSP_API="android-23" # Android 6.0 and above # AOSP_API="android-23" # Android 6.0 and above
if [ -z "${AOSP_API-}" ]; then if [ -z "${AOSP_API-}" ]; then
AOSP_API="android-21" AOSP_API="android-21"
fi fi
##################################################################### #####################################################################
@ -74,102 +79,102 @@ fi
# like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e. # like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e.
if [ -z "${ANDROID_NDK_ROOT-}" ]; then if [ -z "${ANDROID_NDK_ROOT-}" ]; then
ANDROID_NDK_ROOT=$(find /opt -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find /opt -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
fi fi
if [ -z "$ANDROID_NDK_ROOT" ]; then if [ -z "$ANDROID_NDK_ROOT" ]; then
ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1)
fi fi
if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then
ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle"
fi fi
fi fi
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
##################################################################### #####################################################################
if [ "$#" -lt 1 ]; then if [ "$#" -lt 1 ]; then
THE_ARCH=armv7a-neon THE_ARCH=armv7a-neon
else else
THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") THE_ARCH=$(tr [A-Z] [a-z] <<< "$1")
fi fi
# https://developer.android.com/ndk/guides/abis.html # https://developer.android.com/ndk/guides/abis.html
case "$THE_ARCH" in case "$THE_ARCH" in
arm|armv5|armv6|armv7|armeabi) arm|armv5|armv6|armv7|armeabi)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi" AOSP_ABI="armeabi"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti"
;; ;;
armv7a|armv7-a|armeabi-v7a) armv7a|armv7-a|armeabi-v7a)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi-v7a" AOSP_ABI="armeabi-v7a"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -DCRYPTOPP_DISABLE_ASM -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv7-a -mthumb -mfpu=vfpv3-d16 -mfloat-abi=softfp -DCRYPTOPP_DISABLE_ASM -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti"
;; ;;
hard|armv7a-hard|armeabi-v7a-hard) hard|armv7a-hard|armeabi-v7a-hard)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi-v7a" AOSP_ABI="armeabi-v7a"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfpu=vfpv3-d16 -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti -Wl,--no-warn-mismatch -Wl,-lm_hard" AOSP_FLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1 -march=armv7-a -mfpu=vfpv3-d16 -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti -Wl,--no-warn-mismatch -Wl,-lm_hard"
;; ;;
neon|armv7a-neon) neon|armv7a-neon)
TOOLCHAIN_ARCH="arm-linux-androideabi" TOOLCHAIN_ARCH="arm-linux-androideabi"
TOOLCHAIN_NAME="arm-linux-androideabi" TOOLCHAIN_NAME="arm-linux-androideabi"
AOSP_ABI="armeabi-v7a" AOSP_ABI="armeabi-v7a"
AOSP_ARCH="arch-arm" AOSP_ARCH="arch-arm"
AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti"
;; ;;
armv8|armv8a|aarch64|arm64|arm64-v8a) armv8|armv8a|aarch64|arm64|arm64-v8a)
TOOLCHAIN_ARCH="aarch64-linux-android" TOOLCHAIN_ARCH="aarch64-linux-android"
TOOLCHAIN_NAME="aarch64-linux-android" TOOLCHAIN_NAME="aarch64-linux-android"
AOSP_ABI="arm64-v8a" AOSP_ABI="arm64-v8a"
AOSP_ARCH="arch-arm64" AOSP_ARCH="arch-arm64"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
mips|mipsel) mips|mipsel)
TOOLCHAIN_ARCH="mipsel-linux-android" TOOLCHAIN_ARCH="mipsel-linux-android"
TOOLCHAIN_NAME="mipsel-linux-android" TOOLCHAIN_NAME="mipsel-linux-android"
AOSP_ABI="mips" AOSP_ABI="mips"
AOSP_ARCH="arch-mips" AOSP_ARCH="arch-mips"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
mips64|mipsel64|mips64el) mips64|mipsel64|mips64el)
TOOLCHAIN_ARCH="mips64el-linux-android" TOOLCHAIN_ARCH="mips64el-linux-android"
TOOLCHAIN_NAME="mips64el-linux-android" TOOLCHAIN_NAME="mips64el-linux-android"
AOSP_ABI="mips64" AOSP_ABI="mips64"
AOSP_ARCH="arch-mips64" AOSP_ARCH="arch-mips64"
AOSP_FLAGS="-funwind-tables -fexceptions -frtti" AOSP_FLAGS="-funwind-tables -fexceptions -frtti"
;; ;;
x86) x86)
TOOLCHAIN_ARCH="x86" TOOLCHAIN_ARCH="x86"
TOOLCHAIN_NAME="i686-linux-android" TOOLCHAIN_NAME="i686-linux-android"
AOSP_ABI="x86" AOSP_ABI="x86"
AOSP_ARCH="arch-x86" AOSP_ARCH="arch-x86"
AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti"
;; ;;
x86_64|x64) x86_64|x64)
TOOLCHAIN_ARCH="x86_64" TOOLCHAIN_ARCH="x86_64"
TOOLCHAIN_NAME="x86_64-linux-android" TOOLCHAIN_NAME="x86_64-linux-android"
AOSP_ABI="x86_64" AOSP_ABI="x86_64"
AOSP_ARCH="arch-x86_64" AOSP_ARCH="arch-x86_64"
AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti"
;; ;;
*) *)
echo "ERROR: Unknown architecture $1" echo "ERROR: Unknown architecture $1"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
;; ;;
esac esac
##################################################################### #####################################################################
@ -195,79 +200,79 @@ export STRIP="$TOOLCHAIN_NAME-strip"
AOSP_TOOLCHAIN_PATH="" AOSP_TOOLCHAIN_PATH=""
for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86" for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86"
do do
if [ -d "$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" ]; then if [ -d "$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" ]; then
AOSP_TOOLCHAIN_PATH="$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin" AOSP_TOOLCHAIN_PATH="$ANDROID_NDK_ROOT/toolchains/$TOOLCHAIN_ARCH-$AOSP_TOOLCHAIN_SUFFIX/prebuilt/$host/bin"
break break
fi fi
done done
# Error checking # Error checking
if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then
echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then
echo "ERROR: Failed to find Android cpp. Please edit this script." echo "ERROR: Failed to find Android cpp. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then
echo "ERROR: Failed to find Android gcc. Please edit this script." echo "ERROR: Failed to find Android gcc. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then
echo "ERROR: Failed to find Android g++. Please edit this script." echo "ERROR: Failed to find Android g++. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then
echo "ERROR: Failed to find Android ranlib. Please edit this script." echo "ERROR: Failed to find Android ranlib. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then
echo "ERROR: Failed to find Android ar. Please edit this script." echo "ERROR: Failed to find Android ar. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then
echo "ERROR: Failed to find Android as. Please edit this script." echo "ERROR: Failed to find Android as. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then
echo "ERROR: Failed to find Android ld. Please edit this script." echo "ERROR: Failed to find Android ld. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Only modify/export PATH if AOSP_TOOLCHAIN_PATH good # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good
if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then
# And only modify PATH if AOSP_TOOLCHAIN_PATH is not present # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present
LEN=${#AOSP_TOOLCHAIN_PATH} LEN=${#AOSP_TOOLCHAIN_PATH}
SUBSTR=${PATH:0:$LEN} SUBSTR=${PATH:0:$LEN}
if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then
export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH"
fi fi
fi fi
##################################################################### #####################################################################
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then
echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script." echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then
echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script." echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Android SYSROOT. It will be used on the command line with --sysroot # Android SYSROOT. It will be used on the command line with --sysroot
@ -279,74 +284,74 @@ export AOSP_SYSROOT="$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH"
# Android STL. We support GNU, LLVM and STLport out of the box. # Android STL. We support GNU, LLVM and STLport out of the box.
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
THE_STL=gnu-shared THE_STL=gnu-shared
else else
THE_STL=$(tr [A-Z] [a-z] <<< "$2") THE_STL=$(tr [A-Z] [a-z] <<< "$2")
fi fi
# LLVM include directory may be different depending on NDK version. Default to new location (latest NDK checked: r16beta1). # LLVM include directory may be different depending on NDK version. Default to new location (latest NDK checked: r16beta1).
LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/include" LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/include"
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libcxx/include" LLVM_INCLUDE_DIR="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libcxx/include"
fi fi
case "$THE_STL" in case "$THE_STL" in
stlport-static) stlport-static)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_static.a"
;; ;;
stlport|stlport-shared) stlport|stlport-shared)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$AOSP_ABI/libstlport_shared.so"
;; ;;
gabi++-static|gnu-static) gabi++-static|gnu-static)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include"
AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include" AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a"
;; ;;
gnu|gabi++|gnu-shared|gabi++-shared) gnu|gabi++|gnu-shared|gabi++-shared)
AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include" AOSP_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/include"
AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include" AOSP_BITS_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/include"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so"
;; ;;
llvm-static) llvm-static)
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a"
;; ;;
llvm|llvm-shared) llvm|llvm-shared)
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so"
;; ;;
*) *)
echo "ERROR: Unknown STL library $2" echo "ERROR: Unknown STL library $2"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
esac esac
# Error checking # Error checking
if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then
echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." echo "ERROR: AOSP_STL_INC is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_STL_LIB" ]; then if [ ! -e "$AOSP_STL_LIB" ]; then
echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
export AOSP_STL_INC export AOSP_STL_INC
export AOSP_STL_LIB export AOSP_STL_LIB
if [ ! -z "$AOSP_BITS_INC" ]; then if [ ! -z "$AOSP_BITS_INC" ]; then
export AOSP_BITS_INC export AOSP_BITS_INC
fi fi
# Now that we are using cpu-features from Android rather than CPU probing, we # Now that we are using cpu-features from Android rather than CPU probing, we
@ -354,14 +359,14 @@ fi
# directory and then build it. # directory and then build it.
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then
echo "ERROR: Unable to locate cpu-features.h" echo "ERROR: Unable to locate cpu-features.h"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" .
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then
echo "ERROR: Unable to locate cpu-features.c" echo "ERROR: Unable to locate cpu-features.c"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" .
@ -390,33 +395,33 @@ fi
COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libstdc\+\+') COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libstdc\+\+')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using GNU's runtime and STL library. Please ensure the resulting" echo "You are using GNU's runtime and STL library. Please ensure the resulting"
echo "binary meets licensing requirements. If you can't use GNU's runtime" echo "binary meets licensing requirements. If you can't use GNU's runtime"
echo "and STL library, then reconfigure with stlport or llvm. Also see" echo "and STL library, then reconfigure with stlport or llvm. Also see"
echo "http://code.google.com/p/android/issues/detail?id=216331" echo "http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport') COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using STLport's runtime and STL library. STLport could cause problems" echo "You are using STLport's runtime and STL library. STLport could cause problems"
echo "if the resulting binary is used in other environments, like a QT project." echo "if the resulting binary is used in other environments, like a QT project."
echo "Also see http://code.google.com/p/android/issues/detail?id=216331" echo "Also see http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+') COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+')
if [[ ("$COUNT" -ne "0") ]]; then if [[ ("$COUNT" -ne "0") ]]; then
echo echo
echo "*******************************************************************************" echo "*******************************************************************************"
echo "You are using LLVM's runtime and STL library. LLVM could cause problems" echo "You are using LLVM's runtime and STL library. LLVM could cause problems"
echo "if the resulting binary is used in other environments, like a QT project." echo "if the resulting binary is used in other environments, like a QT project."
echo "Also see http://code.google.com/p/android/issues/detail?id=216331" echo "Also see http://code.google.com/p/android/issues/detail?id=216331"
echo "*******************************************************************************" echo "*******************************************************************************"
fi fi
echo echo
@ -427,4 +432,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -15,6 +15,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
# Unset old options # Unset old options
unset IS_CROSS_COMPILE unset IS_CROSS_COMPILE
@ -24,12 +29,12 @@ unset IS_ANDROID
unset IS_ARM_EMBEDDED unset IS_ARM_EMBEDDED
if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then
ARM_EMBEDDED_TOOLCHAIN="/usr/bin" ARM_EMBEDDED_TOOLCHAIN="/usr/bin"
fi fi
if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then
echo "ARM_EMBEDDED_TOOLCHAIN is not valid" echo "ARM_EMBEDDED_TOOLCHAIN is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Fedora # Fedora
@ -50,37 +55,37 @@ export RANLIB="$ARM_EMBEDDED_TOOLCHAIN/$TOOL_PREFIX-ranlib"
# Test a few of the tools # Test a few of the tools
if [ ! -e "$CPP" ]; then if [ ! -e "$CPP" ]; then
echo "ERROR: CPP is not valid" echo "ERROR: CPP is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$CC" ]; then if [ ! -e "$CC" ]; then
echo "ERROR: CC is not valid" echo "ERROR: CC is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$CXX" ]; then if [ ! -e "$CXX" ]; then
echo "ERROR: CXX is not valid" echo "ERROR: CXX is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AR" ]; then if [ ! -e "$AR" ]; then
echo "ERROR: AR is not valid" echo "ERROR: AR is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AS" ]; then if [ ! -e "$AS" ]; then
echo "ERROR: AS is not valid" echo "ERROR: AS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$RANLIB" ]; then if [ ! -e "$RANLIB" ]; then
echo "ERROR: RANLIB is not valid" echo "ERROR: RANLIB is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$LD" ]; then if [ ! -e "$LD" ]; then
echo "ERROR: LD is not valid" echo "ERROR: LD is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# The Crypto++ Makefile uses these to disable host settings like # The Crypto++ Makefile uses these to disable host settings like
@ -94,7 +99,7 @@ fi
if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then
echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid" echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Fix C++ header paths for Ubuntu # Fix C++ header paths for Ubuntu
@ -104,12 +109,12 @@ ARM_EMBEDDED_CXX_HEADERS="$ARM_EMBEDDED_SYSROOT/include/c++/$ARM_EMBEDDED_TOOLCH
if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS" ]; then if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid" echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid" echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Finally, the flags... # Finally, the flags...
@ -142,4 +147,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -13,6 +13,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
######################################### #########################################
##### Clear old options ##### ##### Clear old options #####
######################################### #########################################
@ -131,12 +136,12 @@ done
# Defaults if not set # Defaults if not set
if [ -z "$APPLE_SDK" ]; then if [ -z "$APPLE_SDK" ]; then
BACK_ARCH=armv7 BACK_ARCH=armv7
APPLE_SDK=iPhoneOS APPLE_SDK=iPhoneOS
fi fi
# Defaults if not set # Defaults if not set
if [ -z "$IOS_ARCH" ]; then if [ -z "$IOS_ARCH" ]; then
IOS_ARCH="$BACK_ARCH" IOS_ARCH="$BACK_ARCH"
fi fi
# Allow a user override? I think we should be doing this. The use case is: # Allow a user override? I think we should be doing this. The use case is:
@ -149,7 +154,7 @@ fi
if [ ! -d "$XCODE_DEVELOPER" ]; then if [ ! -d "$XCODE_DEVELOPER" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER directory." echo "ERROR: unable to find XCODE_DEVELOPER directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Default toolchain location # Default toolchain location
@ -157,7 +162,7 @@ XCODE_TOOLCHAIN="$XCODE_DEVELOPER/usr/bin"
if [ ! -d "$XCODE_TOOLCHAIN" ]; then if [ ! -d "$XCODE_TOOLCHAIN" ]; then
echo "ERROR: unable to find XCODE_TOOLCHAIN directory." echo "ERROR: unable to find XCODE_TOOLCHAIN directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# XCODE_DEVELOPER_TOP is the top of the development tools tree # XCODE_DEVELOPER_TOP is the top of the development tools tree
@ -165,7 +170,7 @@ XCODE_DEVELOPER_TOP="$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer"
if [ ! -d "$XCODE_DEVELOPER_TOP" ]; then if [ ! -d "$XCODE_DEVELOPER_TOP" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_TOP directory." echo "ERROR: unable to find XCODE_DEVELOPER_TOP directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# IOS_TOOLCHAIN is the location of the actual compiler tools. # IOS_TOOLCHAIN is the location of the actual compiler tools.
@ -177,7 +182,7 @@ fi
if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools." echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# #
@ -187,16 +192,16 @@ fi
unset XCODE_SDK unset XCODE_SDK
for i in $(seq -f "%.1f" 20.0 -0.1 1.0) for i in $(seq -f "%.1f" 20.0 -0.1 1.0)
do do
if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then
XCODE_SDK="$APPLE_SDK$i.sdk" XCODE_SDK="$APPLE_SDK$i.sdk"
break break
fi fi
done done
# Error checking # Error checking
if [ -z "$XCODE_SDK" ]; then if [ -z "$XCODE_SDK" ]; then
echo "ERROR: unable to find a SDK." echo "ERROR: unable to find a SDK."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# https://github.com/weidai11/cryptopp/issues/635 # https://github.com/weidai11/cryptopp/issues/635
@ -276,16 +281,16 @@ fi
# Only modify/export PATH if IOS_TOOLCHAIN good # Only modify/export PATH if IOS_TOOLCHAIN good
if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then
# And only modify PATH if IOS_TOOLCHAIN is not present # And only modify PATH if IOS_TOOLCHAIN is not present
TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN"
LEN=${#TOOL_PATH} LEN=${#TOOL_PATH}
SUBSTR=${PATH:0:$LEN} SUBSTR=${PATH:0:$LEN}
if [ "$SUBSTR" != "$TOOL_PATH" ]; then if [ "$SUBSTR" != "$TOOL_PATH" ]; then
export PATH="$TOOL_PATH":"$PATH" export PATH="$TOOL_PATH":"$PATH"
fi fi
else else
echo "ERROR: unable to set new PATH." echo "ERROR: unable to set new PATH."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
######################################## ########################################
@ -300,14 +305,14 @@ FOUND_ALL=1
TOOLS=(clang clang++ libtool ld) TOOLS=(clang clang++ libtool ld)
for tool in ${TOOLS[@]} for tool in ${TOOLS[@]}
do do
if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then
echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN"
FOUND_ALL=0 FOUND_ALL=0
fi fi
done done
if [ "$FOUND_ALL" -eq "0" ]; then if [ "$FOUND_ALL" -eq "0" ]; then
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Exports added for Autotools. GNUmakefile-cross does not use them. # Exports added for Autotools. GNUmakefile-cross does not use them.
@ -329,4 +334,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -18,6 +18,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
unset IS_CROSS_COMPILE unset IS_CROSS_COMPILE
unset IS_IOS unset IS_IOS
@ -39,7 +44,7 @@ unset CPP CC CXX LD AS AR RANLIB STRIP
# Similar to a "make clean" # Similar to a "make clean"
if [ x"${1-}" = "xunset" ]; then if [ x"${1-}" = "xunset" ]; then
echo "Unsetting script variables. PATH may remain tainted" echo "Unsetting script variables. PATH may remain tainted"
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0
fi fi
# Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library. # Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library.
@ -71,7 +76,7 @@ if [ -z "${AOSP_API-}" ]; then
else else
echo "WARNING: Using AOSP_API has been deprecated. Please use AOSP_API_VERSION instead." echo "WARNING: Using AOSP_API has been deprecated. Please use AOSP_API_VERSION instead."
echo "If you set for example AOSP_API=android-23 then now instead set AOSP_API_VERSION=23" echo "If you set for example AOSP_API=android-23 then now instead set AOSP_API_VERSION=23"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
##################################################################### #####################################################################
@ -98,7 +103,7 @@ fi
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
##################################################################### #####################################################################
@ -127,7 +132,7 @@ case "$THE_ARCH" in
;; ;;
hard|armv7a-hard|armeabi-v7a-hard) hard|armv7a-hard|armeabi-v7a-hard)
echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
#TOOLCHAIN_ARCH="arm-linux-androideabi" #TOOLCHAIN_ARCH="arm-linux-androideabi"
#TOOLCHAIN_NAME="arm-linux-androideabi" #TOOLCHAIN_NAME="arm-linux-androideabi"
#AOSP_ABI="armeabi-v7a" #AOSP_ABI="armeabi-v7a"
@ -178,7 +183,7 @@ case "$THE_ARCH" in
;; ;;
*) *)
echo "ERROR: Unknown architecture $1" echo "ERROR: Unknown architecture $1"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
;; ;;
esac esac
@ -218,48 +223,48 @@ done
# Error checking # Error checking
if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then
echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then
echo "ERROR: Failed to find Android cpp. Please edit this script." echo "ERROR: Failed to find Android cpp. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then
echo "ERROR: Failed to find Android gcc. Please edit this script." echo "ERROR: Failed to find Android gcc. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then
echo "ERROR: Failed to find Android g++. Please edit this script." echo "ERROR: Failed to find Android g++. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then
echo "ERROR: Failed to find Android ranlib. Please edit this script." echo "ERROR: Failed to find Android ranlib. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then
echo "ERROR: Failed to find Android ar. Please edit this script." echo "ERROR: Failed to find Android ar. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then
echo "ERROR: Failed to find Android as. Please edit this script." echo "ERROR: Failed to find Android as. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then
echo "ERROR: Failed to find Android ld. Please edit this script." echo "ERROR: Failed to find Android ld. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Only modify/export PATH if AOSP_TOOLCHAIN_PATH good # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good
@ -278,10 +283,10 @@ fi
# Error checking # Error checking
if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then if [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API" ]; then
echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script." echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then elif [ ! -d "$ANDROID_NDK_ROOT/platforms/$AOSP_API/$AOSP_ARCH" ]; then
echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script." echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Android SYSROOT. It will be used on the command line with --sysroot # Android SYSROOT. It will be used on the command line with --sysroot
@ -328,7 +333,7 @@ case "$THE_STL" in
echo WARNING: llvm is still in experimental state and migth not work as expected echo WARNING: llvm is still in experimental state and migth not work as expected
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a"
@ -337,26 +342,26 @@ case "$THE_STL" in
echo WARNING: llvm is still in experimental state and migth not work as expected echo WARNING: llvm is still in experimental state and migth not work as expected
if [ ! -d "$LLVM_INCLUDE_DIR" ]; then if [ ! -d "$LLVM_INCLUDE_DIR" ]; then
echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_INC="$LLVM_INCLUDE_DIR"
AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so"
;; ;;
*) *)
echo "ERROR: Unknown STL library $2" echo "ERROR: Unknown STL library $2"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
esac esac
# Error checking # Error checking
if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then
echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." echo "ERROR: AOSP_STL_INC is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Error checking # Error checking
if [ ! -e "$AOSP_STL_LIB" ]; then if [ ! -e "$AOSP_STL_LIB" ]; then
echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
export AOSP_STL_INC export AOSP_STL_INC
@ -372,13 +377,13 @@ fi
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then
echo "ERROR: Unable to locate cpu-features.h" echo "ERROR: Unable to locate cpu-features.h"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" .
if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then
echo "ERROR: Unable to locate cpu-features.c" echo "ERROR: Unable to locate cpu-features.c"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" . cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" .
@ -446,4 +451,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -15,6 +15,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
# Unset old options # Unset old options
unset IS_CROSS_COMPILE unset IS_CROSS_COMPILE
@ -24,12 +29,12 @@ unset IS_ANDROID
unset IS_ARM_EMBEDDED unset IS_ARM_EMBEDDED
if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then
ARM_EMBEDDED_TOOLCHAIN="/usr/bin" ARM_EMBEDDED_TOOLCHAIN="/usr/bin"
fi fi
if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then
echo "ARM_EMBEDDED_TOOLCHAIN is not valid" echo "ARM_EMBEDDED_TOOLCHAIN is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Fedora # Fedora
@ -50,37 +55,37 @@ export RANLIB="$ARM_EMBEDDED_TOOLCHAIN/$TOOL_PREFIX-ranlib"
# Test a few of the tools # Test a few of the tools
if [ ! -e "$CPP" ]; then if [ ! -e "$CPP" ]; then
echo "ERROR: CPP is not valid" echo "ERROR: CPP is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$CC" ]; then if [ ! -e "$CC" ]; then
echo "ERROR: CC is not valid" echo "ERROR: CC is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$CXX" ]; then if [ ! -e "$CXX" ]; then
echo "ERROR: CXX is not valid" echo "ERROR: CXX is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AR" ]; then if [ ! -e "$AR" ]; then
echo "ERROR: AR is not valid" echo "ERROR: AR is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$AS" ]; then if [ ! -e "$AS" ]; then
echo "ERROR: AS is not valid" echo "ERROR: AS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$RANLIB" ]; then if [ ! -e "$RANLIB" ]; then
echo "ERROR: RANLIB is not valid" echo "ERROR: RANLIB is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -e "$LD" ]; then if [ ! -e "$LD" ]; then
echo "ERROR: LD is not valid" echo "ERROR: LD is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# The Crypto++ Makefile uses these to disable host settings like # The Crypto++ Makefile uses these to disable host settings like
@ -94,7 +99,7 @@ fi
if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then
echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid" echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Fix C++ header paths for Ubuntu # Fix C++ header paths for Ubuntu
@ -104,12 +109,12 @@ ARM_EMBEDDED_CXX_HEADERS="$ARM_EMBEDDED_SYSROOT/include/c++/$ARM_EMBEDDED_TOOLCH
if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS" ]; then if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid" echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid" echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Finally, the flags... # Finally, the flags...
@ -142,4 +147,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@ -13,6 +13,11 @@
# set -eu # set -eu
# Sanity check
if [ "$0" != "${BASH_SOURCE[0]}" ]; then
echo "Please source this setenv script"
fi
######################################### #########################################
##### Clear old options ##### ##### Clear old options #####
######################################### #########################################
@ -131,12 +136,12 @@ done
# Defaults if not set # Defaults if not set
if [ -z "$APPLE_SDK" ]; then if [ -z "$APPLE_SDK" ]; then
BACK_ARCH=armv7 BACK_ARCH=armv7
APPLE_SDK=iPhoneOS APPLE_SDK=iPhoneOS
fi fi
# Defaults if not set # Defaults if not set
if [ -z "$IOS_ARCH" ]; then if [ -z "$IOS_ARCH" ]; then
IOS_ARCH="$BACK_ARCH" IOS_ARCH="$BACK_ARCH"
fi fi
# Allow a user override? I think we should be doing this. The use case is: # Allow a user override? I think we should be doing this. The use case is:
@ -149,7 +154,7 @@ fi
if [ ! -d "$XCODE_DEVELOPER" ]; then if [ ! -d "$XCODE_DEVELOPER" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER directory." echo "ERROR: unable to find XCODE_DEVELOPER directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Default toolchain location # Default toolchain location
@ -157,7 +162,7 @@ XCODE_TOOLCHAIN="$XCODE_DEVELOPER/usr/bin"
if [ ! -d "$XCODE_TOOLCHAIN" ]; then if [ ! -d "$XCODE_TOOLCHAIN" ]; then
echo "ERROR: unable to find XCODE_TOOLCHAIN directory." echo "ERROR: unable to find XCODE_TOOLCHAIN directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# XCODE_DEVELOPER_TOP is the top of the development tools tree # XCODE_DEVELOPER_TOP is the top of the development tools tree
@ -165,7 +170,7 @@ XCODE_DEVELOPER_TOP="$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer"
if [ ! -d "$XCODE_DEVELOPER_TOP" ]; then if [ ! -d "$XCODE_DEVELOPER_TOP" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_TOP directory." echo "ERROR: unable to find XCODE_DEVELOPER_TOP directory."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# IOS_TOOLCHAIN is the location of the actual compiler tools. # IOS_TOOLCHAIN is the location of the actual compiler tools.
@ -177,7 +182,7 @@ fi
if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools." echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# #
@ -187,16 +192,16 @@ fi
unset XCODE_SDK unset XCODE_SDK
for i in $(seq -f "%.1f" 20.0 -0.1 1.0) for i in $(seq -f "%.1f" 20.0 -0.1 1.0)
do do
if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then
XCODE_SDK="$APPLE_SDK$i.sdk" XCODE_SDK="$APPLE_SDK$i.sdk"
break break
fi fi
done done
# Error checking # Error checking
if [ -z "$XCODE_SDK" ]; then if [ -z "$XCODE_SDK" ]; then
echo "ERROR: unable to find a SDK." echo "ERROR: unable to find a SDK."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# https://github.com/weidai11/cryptopp/issues/635 # https://github.com/weidai11/cryptopp/issues/635
@ -276,16 +281,16 @@ fi
# Only modify/export PATH if IOS_TOOLCHAIN good # Only modify/export PATH if IOS_TOOLCHAIN good
if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then
# And only modify PATH if IOS_TOOLCHAIN is not present # And only modify PATH if IOS_TOOLCHAIN is not present
TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN"
LEN=${#TOOL_PATH} LEN=${#TOOL_PATH}
SUBSTR=${PATH:0:$LEN} SUBSTR=${PATH:0:$LEN}
if [ "$SUBSTR" != "$TOOL_PATH" ]; then if [ "$SUBSTR" != "$TOOL_PATH" ]; then
export PATH="$TOOL_PATH":"$PATH" export PATH="$TOOL_PATH":"$PATH"
fi fi
else else
echo "ERROR: unable to set new PATH." echo "ERROR: unable to set new PATH."
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
######################################## ########################################
@ -300,14 +305,14 @@ FOUND_ALL=1
TOOLS=(clang clang++ libtool ld) TOOLS=(clang clang++ libtool ld)
for tool in ${TOOLS[@]} for tool in ${TOOLS[@]}
do do
if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then
echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN"
FOUND_ALL=0 FOUND_ALL=0
fi fi
done done
if [ "$FOUND_ALL" -eq "0" ]; then if [ "$FOUND_ALL" -eq "0" ]; then
[ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi fi
# Exports added for Autotools. GNUmakefile-cross does not use them. # Exports added for Autotools. GNUmakefile-cross does not use them.
@ -329,4 +334,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'"
echo "*******************************************************************************" echo "*******************************************************************************"
echo echo
[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0