From 19736747329bd217779b2aff70b6e7fb6e272fe1 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 21 May 2019 05:37:40 -0400 Subject: [PATCH] Add sanity check to setenv-*.sh scripts Prompt user to source the script when required. Whitespace check-in --- TestScripts/setenv-android-gcc.sh | 355 +++++++++++++++--------------- TestScripts/setenv-android-old.sh | 339 ++++++++++++++-------------- TestScripts/setenv-embedded.sh | 33 +-- TestScripts/setenv-ios.sh | 57 ++--- setenv-android-gcc.sh | 51 +++-- setenv-embedded.sh | 33 +-- setenv-ios.sh | 57 ++--- 7 files changed, 480 insertions(+), 445 deletions(-) diff --git a/TestScripts/setenv-android-gcc.sh b/TestScripts/setenv-android-gcc.sh index 69fb2f72..0922d2c7 100755 --- a/TestScripts/setenv-android-gcc.sh +++ b/TestScripts/setenv-android-gcc.sh @@ -18,6 +18,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + unset IS_CROSS_COMPILE unset IS_IOS @@ -38,8 +43,8 @@ unset CPP CC CXX LD AS AR RANLIB STRIP # Similar to a "make clean" if [ x"${1-}" = "xunset" ]; then - echo "Unsetting script variables. PATH may remain tainted" - [ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 + echo "Unsetting script variables. PATH may remain tainted" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 fi # 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.9 if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then - AOSP_TOOLCHAIN_SUFFIX=4.9 + AOSP_TOOLCHAIN_SUFFIX=4.9 fi # 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="23" # Android 6.0 and above if [ -z "${AOSP_API_VERSION-}" ]; then - AOSP_API_VERSION="21" + AOSP_API_VERSION="21" fi if [ -z "${AOSP_API-}" ]; then - AOSP_API="android-${AOSP_API_VERSION}" + AOSP_API="android-${AOSP_API_VERSION}" else - 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" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + 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" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### @@ -82,104 +87,104 @@ fi # like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e. 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 - ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) - fi - if [ -z "$ANDROID_NDK_ROOT" ]; then - ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) - fi - if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then - ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" - fi + if [ -z "$ANDROID_NDK_ROOT" ]; then + ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) + fi + if [ -z "$ANDROID_NDK_ROOT" ]; then + ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) + fi + if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then + ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" + fi fi # Error checking if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then - echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### if [ "$#" -lt 1 ]; then - THE_ARCH=armv7a-neon + THE_ARCH=armv7a-neon else - THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") + THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") fi # https://developer.android.com/ndk/guides/abis.html case "$THE_ARCH" in arm|armv5|armv6|armv7|armeabi) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi" - AOSP_ARCH="arch-arm" - AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi" + AOSP_ARCH="arch-arm" + AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" + ;; armv7a|armv7-a|armeabi-v7a) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi-v7a" - 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" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi-v7a" + 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" + ;; hard|armv7a-hard|armeabi-v7a-hard) - echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 - #TOOLCHAIN_ARCH="arm-linux-androideabi" - #TOOLCHAIN_NAME="arm-linux-androideabi" - #AOSP_ABI="armeabi-v7a" - #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" - ;; + echo hard, armv7a-hard and armeabi-v7a-hard are not supported, as android uses softfloats + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + #TOOLCHAIN_ARCH="arm-linux-androideabi" + #TOOLCHAIN_NAME="arm-linux-androideabi" + #AOSP_ABI="armeabi-v7a" + #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" + ;; neon|armv7a-neon) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi-v7a" - AOSP_ARCH="arch-arm" - AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi-v7a" + AOSP_ARCH="arch-arm" + AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" + ;; armv8|armv8a|aarch64|arm64|arm64-v8a) - TOOLCHAIN_ARCH="aarch64-linux-android" - TOOLCHAIN_NAME="aarch64-linux-android" - AOSP_ABI="arm64-v8a" - AOSP_ARCH="arch-arm64" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="aarch64-linux-android" + TOOLCHAIN_NAME="aarch64-linux-android" + AOSP_ABI="arm64-v8a" + AOSP_ARCH="arch-arm64" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; mips|mipsel) - TOOLCHAIN_ARCH="mipsel-linux-android" - TOOLCHAIN_NAME="mipsel-linux-android" - AOSP_ABI="mips" - AOSP_ARCH="arch-mips" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="mipsel-linux-android" + TOOLCHAIN_NAME="mipsel-linux-android" + AOSP_ABI="mips" + AOSP_ARCH="arch-mips" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; mips64|mipsel64|mips64el) - TOOLCHAIN_ARCH="mips64el-linux-android" - TOOLCHAIN_NAME="mips64el-linux-android" - AOSP_ABI="mips64" - AOSP_ARCH="arch-mips64" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="mips64el-linux-android" + TOOLCHAIN_NAME="mips64el-linux-android" + AOSP_ABI="mips64" + AOSP_ARCH="arch-mips64" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; x86) - TOOLCHAIN_ARCH="x86" - TOOLCHAIN_NAME="i686-linux-android" - AOSP_ABI="x86" - AOSP_ARCH="arch-x86" - AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="x86" + TOOLCHAIN_NAME="i686-linux-android" + AOSP_ABI="x86" + AOSP_ARCH="arch-x86" + AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" + ;; x86_64|x64) - TOOLCHAIN_ARCH="x86_64" - TOOLCHAIN_NAME="x86_64-linux-android" - AOSP_ABI="x86_64" - AOSP_ARCH="arch-x86_64" - AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="x86_64" + TOOLCHAIN_NAME="x86_64-linux-android" + AOSP_ABI="x86_64" + AOSP_ARCH="arch-x86_64" + AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" + ;; *) - echo "ERROR: Unknown architecture $1" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 - ;; + echo "ERROR: Unknown architecture $1" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + ;; esac ##################################################################### @@ -209,79 +214,79 @@ export AOSP_SYS_ARCH_INC="$ANDROID_NDK_ROOT/sysroot/usr/include/$TOOLCHAIN_NAME" AOSP_TOOLCHAIN_PATH="" for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86" do - 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" - break - fi + 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" + break + fi done # Error checking if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then - echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then - echo "ERROR: Failed to find Android cpp. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android cpp. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then - echo "ERROR: Failed to find Android gcc. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android gcc. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then - echo "ERROR: Failed to find Android g++. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android g++. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then - echo "ERROR: Failed to find Android ranlib. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ranlib. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then - echo "ERROR: Failed to find Android ar. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ar. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then - echo "ERROR: Failed to find Android as. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android as. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then - echo "ERROR: Failed to find Android ld. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ld. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then - # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present - LEN=${#AOSP_TOOLCHAIN_PATH} - SUBSTR=${PATH:0:$LEN} - if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then - export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" - fi + # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present + LEN=${#AOSP_TOOLCHAIN_PATH} + SUBSTR=${PATH:0:$LEN} + if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then + export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" + fi fi ##################################################################### # Error checking 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." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 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." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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. if [ "$#" -lt 2 ]; then - THE_STL=gnu-shared + THE_STL=gnu-shared else - THE_STL=$(tr [A-Z] [a-z] <<< "$2") + THE_STL=$(tr [A-Z] [a-z] <<< "$2") fi # 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" 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 case "$THE_STL" in stlport-static) - 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_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" + ;; stlport|stlport-shared) - 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_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" + ;; gabi++-static|gnu-static) - 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a" - ;; + 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_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) - 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" - ;; + 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" + ;; llvm-static) - echo WARNING: llvm is still in experimental state and migth not work as expected - if [ ! -d "$LLVM_INCLUDE_DIR" ]; then - 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 - fi - AOSP_STL_INC="$LLVM_INCLUDE_DIR" - AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" - ;; + echo WARNING: llvm is still in experimental state and migth not work as expected + if [ ! -d "$LLVM_INCLUDE_DIR" ]; then + echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + fi + AOSP_STL_INC="$LLVM_INCLUDE_DIR" + AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" + ;; llvm|llvm-shared) - echo WARNING: llvm is still in experimental state and migth not work as expected - if [ ! -d "$LLVM_INCLUDE_DIR" ]; then - 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 - fi - AOSP_STL_INC="$LLVM_INCLUDE_DIR" - AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" - ;; + echo WARNING: llvm is still in experimental state and migth not work as expected + if [ ! -d "$LLVM_INCLUDE_DIR" ]; then + echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + fi + AOSP_STL_INC="$LLVM_INCLUDE_DIR" + AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" + ;; *) - echo "ERROR: Unknown STL library $2" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unknown STL library $2" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 esac # Error checking if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then - echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_STL_LIB" ]; then - echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi export AOSP_STL_INC export AOSP_STL_LIB if [ ! -z "$AOSP_BITS_INC" ]; then - export AOSP_BITS_INC + export AOSP_BITS_INC fi # Now that we are using cpu-features from Android rather than CPU probing, we @@ -371,14 +376,14 @@ fi # directory and then build it. if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then - echo "ERROR: Unable to locate cpu-features.h" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unable to locate cpu-features.h" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then - echo "ERROR: Unable to locate cpu-features.c" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unable to locate cpu-features.c" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi 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\+\+') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "and STL library, then reconfigure with stlport or llvm. Also see" - echo "http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "and STL library, then reconfigure with stlport or llvm. Also see" + echo "http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi echo @@ -446,4 +451,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'" echo "*******************************************************************************" echo -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/TestScripts/setenv-android-old.sh b/TestScripts/setenv-android-old.sh index d93b568d..ade69bd0 100755 --- a/TestScripts/setenv-android-old.sh +++ b/TestScripts/setenv-android-old.sh @@ -20,6 +20,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + unset IS_CROSS_COMPILE unset IS_IOS @@ -38,8 +43,8 @@ unset CPP CC CXX LD AS AR RANLIB STRIP # Similar to a "make clean" if [ x"${1-}" = "xunset" ]; then - echo "Unsetting script variables. PATH may remain tainted" - [ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 + echo "Unsetting script variables. PATH may remain tainted" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 fi # 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.9 if [ -z "${AOSP_TOOLCHAIN_SUFFIX-}" ]; then - AOSP_TOOLCHAIN_SUFFIX=4.9 + AOSP_TOOLCHAIN_SUFFIX=4.9 fi # 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-23" # Android 6.0 and above if [ -z "${AOSP_API-}" ]; then - AOSP_API="android-21" + AOSP_API="android-21" fi ##################################################################### @@ -74,102 +79,102 @@ fi # like ANDROID_NDK_ROOT=/opt/android-ndk-r10e or ANDROID_NDK_ROOT=/usr/local/android-ndk-r10e. 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 - ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) - fi - if [ -z "$ANDROID_NDK_ROOT" ]; then - ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) - fi - if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then - ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" - fi + if [ -z "$ANDROID_NDK_ROOT" ]; then + ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) + fi + if [ -z "$ANDROID_NDK_ROOT" ]; then + ANDROID_NDK_ROOT=$(find $HOME -maxdepth 1 -type d -name android-ndk* 2>/dev/null | tail -1) + fi + if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then + ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" + fi fi # Error checking if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then - echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### if [ "$#" -lt 1 ]; then - THE_ARCH=armv7a-neon + THE_ARCH=armv7a-neon else - THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") + THE_ARCH=$(tr [A-Z] [a-z] <<< "$1") fi # https://developer.android.com/ndk/guides/abis.html case "$THE_ARCH" in arm|armv5|armv6|armv7|armeabi) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi" - AOSP_ARCH="arch-arm" - AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi" + AOSP_ARCH="arch-arm" + AOSP_FLAGS="-march=armv5te -mtune=xscale -mthumb -msoft-float -DCRYPTOPP_DISABLE_ASM -funwind-tables -fexceptions -frtti" + ;; armv7a|armv7-a|armeabi-v7a) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi-v7a" - 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" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi-v7a" + 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" + ;; hard|armv7a-hard|armeabi-v7a-hard) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi-v7a" - 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" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi-v7a" + 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" + ;; neon|armv7a-neon) - TOOLCHAIN_ARCH="arm-linux-androideabi" - TOOLCHAIN_NAME="arm-linux-androideabi" - AOSP_ABI="armeabi-v7a" - AOSP_ARCH="arch-arm" - AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="arm-linux-androideabi" + TOOLCHAIN_NAME="arm-linux-androideabi" + AOSP_ABI="armeabi-v7a" + AOSP_ARCH="arch-arm" + AOSP_FLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8 -funwind-tables -fexceptions -frtti" + ;; armv8|armv8a|aarch64|arm64|arm64-v8a) - TOOLCHAIN_ARCH="aarch64-linux-android" - TOOLCHAIN_NAME="aarch64-linux-android" - AOSP_ABI="arm64-v8a" - AOSP_ARCH="arch-arm64" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="aarch64-linux-android" + TOOLCHAIN_NAME="aarch64-linux-android" + AOSP_ABI="arm64-v8a" + AOSP_ARCH="arch-arm64" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; mips|mipsel) - TOOLCHAIN_ARCH="mipsel-linux-android" - TOOLCHAIN_NAME="mipsel-linux-android" - AOSP_ABI="mips" - AOSP_ARCH="arch-mips" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="mipsel-linux-android" + TOOLCHAIN_NAME="mipsel-linux-android" + AOSP_ABI="mips" + AOSP_ARCH="arch-mips" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; mips64|mipsel64|mips64el) - TOOLCHAIN_ARCH="mips64el-linux-android" - TOOLCHAIN_NAME="mips64el-linux-android" - AOSP_ABI="mips64" - AOSP_ARCH="arch-mips64" - AOSP_FLAGS="-funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="mips64el-linux-android" + TOOLCHAIN_NAME="mips64el-linux-android" + AOSP_ABI="mips64" + AOSP_ARCH="arch-mips64" + AOSP_FLAGS="-funwind-tables -fexceptions -frtti" + ;; x86) - TOOLCHAIN_ARCH="x86" - TOOLCHAIN_NAME="i686-linux-android" - AOSP_ABI="x86" - AOSP_ARCH="arch-x86" - AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="x86" + TOOLCHAIN_NAME="i686-linux-android" + AOSP_ABI="x86" + AOSP_ARCH="arch-x86" + AOSP_FLAGS="-mtune=intel -mssse3 -mfpmath=sse -funwind-tables -fexceptions -frtti" + ;; x86_64|x64) - TOOLCHAIN_ARCH="x86_64" - TOOLCHAIN_NAME="x86_64-linux-android" - AOSP_ABI="x86_64" - AOSP_ARCH="arch-x86_64" - AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" - ;; + TOOLCHAIN_ARCH="x86_64" + TOOLCHAIN_NAME="x86_64-linux-android" + AOSP_ABI="x86_64" + AOSP_ARCH="arch-x86_64" + AOSP_FLAGS="-march=x86-64 -msse4.2 -mpopcnt -mtune=intel -funwind-tables -fexceptions -frtti" + ;; *) - echo "ERROR: Unknown architecture $1" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 - ;; + echo "ERROR: Unknown architecture $1" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + ;; esac ##################################################################### @@ -195,79 +200,79 @@ export STRIP="$TOOLCHAIN_NAME-strip" AOSP_TOOLCHAIN_PATH="" for host in "linux-x86_64" "darwin-x86_64" "linux-x86" "darwin-x86" do - 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" - break - fi + 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" + break + fi done # Error checking if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then - echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_TOOLCHAIN_PATH is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then - echo "ERROR: Failed to find Android cpp. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android cpp. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then - echo "ERROR: Failed to find Android gcc. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android gcc. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then - echo "ERROR: Failed to find Android g++. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android g++. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then - echo "ERROR: Failed to find Android ranlib. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ranlib. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then - echo "ERROR: Failed to find Android ar. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ar. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then - echo "ERROR: Failed to find Android as. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android as. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then - echo "ERROR: Failed to find Android ld. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Failed to find Android ld. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good if [ -d "$AOSP_TOOLCHAIN_PATH" ]; then - # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present - LEN=${#AOSP_TOOLCHAIN_PATH} - SUBSTR=${PATH:0:$LEN} - if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then - export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" - fi + # And only modify PATH if AOSP_TOOLCHAIN_PATH is not present + LEN=${#AOSP_TOOLCHAIN_PATH} + SUBSTR=${PATH:0:$LEN} + if [ "$SUBSTR" != "$AOSP_TOOLCHAIN_PATH" ]; then + export PATH="$AOSP_TOOLCHAIN_PATH":"$PATH" + fi fi ##################################################################### # Error checking 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." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_API is not valid. Does the NDK support the API? Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 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." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_ARCH is not valid. Does the NDK support the architecture? Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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. if [ "$#" -lt 2 ]; then - THE_STL=gnu-shared + THE_STL=gnu-shared else - THE_STL=$(tr [A-Z] [a-z] <<< "$2") + THE_STL=$(tr [A-Z] [a-z] <<< "$2") fi # 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" 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 case "$THE_STL" in stlport-static) - 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_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" + ;; stlport|stlport-shared) - 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_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" + ;; gabi++-static|gnu-static) - 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_static.a" - ;; + 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_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) - 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" - ;; + 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_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$AOSP_TOOLCHAIN_SUFFIX/libs/$AOSP_ABI/libgnustl_shared.so" + ;; llvm-static) - if [ ! -d "$LLVM_INCLUDE_DIR" ]; then - 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 - fi - AOSP_STL_INC="$LLVM_INCLUDE_DIR" - AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" - ;; + if [ ! -d "$LLVM_INCLUDE_DIR" ]; then + echo "ERROR: Unable to locate include LLVM directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + fi + AOSP_STL_INC="$LLVM_INCLUDE_DIR" + AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_static.a" + ;; llvm|llvm-shared) - if [ ! -d "$LLVM_INCLUDE_DIR" ]; then - 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 - fi - AOSP_STL_INC="$LLVM_INCLUDE_DIR" - AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" - ;; + if [ ! -d "$LLVM_INCLUDE_DIR" ]; then + echo "ERROR: Unable to locate LLVM include directory at $LLVM_INCLUDE_DIR -- has it moved since NDK r16beta1?" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 + fi + AOSP_STL_INC="$LLVM_INCLUDE_DIR" + AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" + ;; *) - echo "ERROR: Unknown STL library $2" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unknown STL library $2" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 esac # Error checking if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then - echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_STL_INC is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Error checking if [ ! -e "$AOSP_STL_LIB" ]; then - echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: AOSP_STL_LIB is not valid. Please edit this script." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi export AOSP_STL_INC export AOSP_STL_LIB if [ ! -z "$AOSP_BITS_INC" ]; then - export AOSP_BITS_INC + export AOSP_BITS_INC fi # Now that we are using cpu-features from Android rather than CPU probing, we @@ -354,14 +359,14 @@ fi # directory and then build it. if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then - echo "ERROR: Unable to locate cpu-features.h" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unable to locate cpu-features.h" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then - echo "ERROR: Unable to locate cpu-features.c" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: Unable to locate cpu-features.c" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi 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\+\+') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "and STL library, then reconfigure with stlport or llvm. Also see" - echo "http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "and STL library, then reconfigure with stlport or llvm. Also see" + echo "http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi COUNT=$(echo -n "$AOSP_STL_LIB" | grep -i -c 'libstlport') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi COUNT=$(echo -n "$AOSP_STL_LIB" | egrep -i -c 'libc\+\+') if [[ ("$COUNT" -ne "0") ]]; then - echo - echo "*******************************************************************************" - 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" - echo "*******************************************************************************" + echo + echo "*******************************************************************************" + 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 "Also see http://code.google.com/p/android/issues/detail?id=216331" + echo "*******************************************************************************" fi echo @@ -427,4 +432,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'" echo "*******************************************************************************" echo -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/TestScripts/setenv-embedded.sh b/TestScripts/setenv-embedded.sh index 7e743ab8..d785574f 100755 --- a/TestScripts/setenv-embedded.sh +++ b/TestScripts/setenv-embedded.sh @@ -15,6 +15,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + # Unset old options unset IS_CROSS_COMPILE @@ -24,12 +29,12 @@ unset IS_ANDROID unset IS_ARM_EMBEDDED if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then - ARM_EMBEDDED_TOOLCHAIN="/usr/bin" + ARM_EMBEDDED_TOOLCHAIN="/usr/bin" fi if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then - echo "ARM_EMBEDDED_TOOLCHAIN is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ARM_EMBEDDED_TOOLCHAIN is not valid" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Fedora @@ -50,37 +55,37 @@ export RANLIB="$ARM_EMBEDDED_TOOLCHAIN/$TOOL_PREFIX-ranlib" # Test a few of the tools if [ ! -e "$CPP" ]; then echo "ERROR: CPP is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$CC" ]; then echo "ERROR: CC is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$CXX" ]; then echo "ERROR: CXX is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AR" ]; then echo "ERROR: AR is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AS" ]; then echo "ERROR: AS is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$RANLIB" ]; then echo "ERROR: RANLIB is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$LD" ]; then echo "ERROR: LD is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # The Crypto++ Makefile uses these to disable host settings like @@ -94,7 +99,7 @@ fi if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 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 if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then 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 # Finally, the flags... @@ -142,4 +147,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'" echo "*******************************************************************************" echo -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/TestScripts/setenv-ios.sh b/TestScripts/setenv-ios.sh index efd6a8b5..577ad055 100755 --- a/TestScripts/setenv-ios.sh +++ b/TestScripts/setenv-ios.sh @@ -13,6 +13,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + ######################################### ##### Clear old options ##### ######################################### @@ -131,12 +136,12 @@ done # Defaults if not set if [ -z "$APPLE_SDK" ]; then BACK_ARCH=armv7 - APPLE_SDK=iPhoneOS + APPLE_SDK=iPhoneOS fi # Defaults if not set if [ -z "$IOS_ARCH" ]; then - IOS_ARCH="$BACK_ARCH" + IOS_ARCH="$BACK_ARCH" fi # 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 echo "ERROR: unable to find XCODE_DEVELOPER directory." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Default toolchain location @@ -157,7 +162,7 @@ XCODE_TOOLCHAIN="$XCODE_DEVELOPER/usr/bin" if [ ! -d "$XCODE_TOOLCHAIN" ]; then echo "ERROR: unable to find XCODE_TOOLCHAIN directory." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 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 # IOS_TOOLCHAIN is the location of the actual compiler tools. @@ -177,7 +182,7 @@ fi if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then 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 # @@ -187,16 +192,16 @@ fi unset XCODE_SDK for i in $(seq -f "%.1f" 20.0 -0.1 1.0) do - if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then - XCODE_SDK="$APPLE_SDK$i.sdk" - break - fi + if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then + XCODE_SDK="$APPLE_SDK$i.sdk" + break + fi done # Error checking if [ -z "$XCODE_SDK" ]; then echo "ERROR: unable to find a SDK." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # https://github.com/weidai11/cryptopp/issues/635 @@ -276,16 +281,16 @@ fi # Only modify/export PATH if IOS_TOOLCHAIN good if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then - # And only modify PATH if IOS_TOOLCHAIN is not present - TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" - LEN=${#TOOL_PATH} - SUBSTR=${PATH:0:$LEN} - if [ "$SUBSTR" != "$TOOL_PATH" ]; then - export PATH="$TOOL_PATH":"$PATH" - fi + # And only modify PATH if IOS_TOOLCHAIN is not present + TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" + LEN=${#TOOL_PATH} + SUBSTR=${PATH:0:$LEN} + if [ "$SUBSTR" != "$TOOL_PATH" ]; then + export PATH="$TOOL_PATH":"$PATH" + fi else - echo "ERROR: unable to set new PATH." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: unable to set new PATH." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ######################################## @@ -300,14 +305,14 @@ FOUND_ALL=1 TOOLS=(clang clang++ libtool ld) for tool in ${TOOLS[@]} do - if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then - echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" - FOUND_ALL=0 - fi + if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then + echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" + FOUND_ALL=0 + fi done if [ "$FOUND_ALL" -eq "0" ]; then - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/setenv-android-gcc.sh b/setenv-android-gcc.sh index d49f2000..e115b2df 100755 --- a/setenv-android-gcc.sh +++ b/setenv-android-gcc.sh @@ -18,6 +18,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + unset IS_CROSS_COMPILE unset IS_IOS @@ -39,7 +44,7 @@ unset CPP CC CXX LD AS AR RANLIB STRIP # Similar to a "make clean" if [ x"${1-}" = "xunset" ]; then echo "Unsetting script variables. PATH may remain tainted" - [ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 fi # Set AOSP_TOOLCHAIN_SUFFIX to your preference of tools and STL library. @@ -71,7 +76,7 @@ if [ -z "${AOSP_API-}" ]; then else 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" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ##################################################################### @@ -98,7 +103,7 @@ fi # Error checking if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then 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 ##################################################################### @@ -127,7 +132,7 @@ case "$THE_ARCH" in ;; hard|armv7a-hard|armeabi-v7a-hard) 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_NAME="arm-linux-androideabi" #AOSP_ABI="armeabi-v7a" @@ -178,7 +183,7 @@ case "$THE_ARCH" in ;; *) echo "ERROR: Unknown architecture $1" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 ;; esac @@ -218,48 +223,48 @@ done # Error checking if [ -z "$AOSP_TOOLCHAIN_PATH" ] || [ ! -d "$AOSP_TOOLCHAIN_PATH" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CPP" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CC" ]; then 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 if [ ! -e "$AOSP_TOOLCHAIN_PATH/$CXX" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$RANLIB" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AR" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$AS" ]; then 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 # Error checking if [ ! -e "$AOSP_TOOLCHAIN_PATH/$LD" ]; then 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 # Only modify/export PATH if AOSP_TOOLCHAIN_PATH good @@ -278,10 +283,10 @@ fi # Error checking 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." - [ "$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 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 # 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 if [ ! -d "$LLVM_INCLUDE_DIR" ]; then 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 AOSP_STL_INC="$LLVM_INCLUDE_DIR" 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 if [ ! -d "$LLVM_INCLUDE_DIR" ]; then 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 AOSP_STL_INC="$LLVM_INCLUDE_DIR" AOSP_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$AOSP_ABI/libc++_shared.so" ;; *) echo "ERROR: Unknown STL library $2" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 esac # Error checking if [ ! -d "$AOSP_STL_INC" ] || [ ! -e "$AOSP_STL_INC/memory" ]; then 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 # Error checking if [ ! -e "$AOSP_STL_LIB" ]; then 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 export AOSP_STL_INC @@ -372,13 +377,13 @@ fi if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" ]]; then echo "ERROR: Unable to locate cpu-features.h" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi cp "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.h" . if [[ ! -e "$ANDROID_NDK_ROOT/sources/android/cpufeatures/cpu-features.c" ]]; then echo "ERROR: Unable to locate cpu-features.c" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi 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 -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/setenv-embedded.sh b/setenv-embedded.sh index 7e743ab8..d785574f 100755 --- a/setenv-embedded.sh +++ b/setenv-embedded.sh @@ -15,6 +15,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + # Unset old options unset IS_CROSS_COMPILE @@ -24,12 +29,12 @@ unset IS_ANDROID unset IS_ARM_EMBEDDED if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then - ARM_EMBEDDED_TOOLCHAIN="/usr/bin" + ARM_EMBEDDED_TOOLCHAIN="/usr/bin" fi if [ ! -d "$ARM_EMBEDDED_TOOLCHAIN" ]; then - echo "ARM_EMBEDDED_TOOLCHAIN is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ARM_EMBEDDED_TOOLCHAIN is not valid" + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Fedora @@ -50,37 +55,37 @@ export RANLIB="$ARM_EMBEDDED_TOOLCHAIN/$TOOL_PREFIX-ranlib" # Test a few of the tools if [ ! -e "$CPP" ]; then echo "ERROR: CPP is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$CC" ]; then echo "ERROR: CC is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$CXX" ]; then echo "ERROR: CXX is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AR" ]; then echo "ERROR: AR is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$AS" ]; then echo "ERROR: AS is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$RANLIB" ]; then echo "ERROR: RANLIB is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi if [ ! -e "$LD" ]; then echo "ERROR: LD is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # The Crypto++ Makefile uses these to disable host settings like @@ -94,7 +99,7 @@ fi if [ ! -d "$ARM_EMBEDDED_SYSROOT" ]; then echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid" - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 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 if [ ! -d "$ARM_EMBEDDED_CXX_HEADERS/arm-linux-gnueabi" ]; then 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 # Finally, the flags... @@ -142,4 +147,4 @@ echo "shared object using 'HAS_SOLIB_VERSION=1 make -f GNUmakefile-cross'" echo "*******************************************************************************" echo -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0 diff --git a/setenv-ios.sh b/setenv-ios.sh index efd6a8b5..577ad055 100755 --- a/setenv-ios.sh +++ b/setenv-ios.sh @@ -13,6 +13,11 @@ # set -eu +# Sanity check +if [ "$0" != "${BASH_SOURCE[0]}" ]; then + echo "Please source this setenv script" +fi + ######################################### ##### Clear old options ##### ######################################### @@ -131,12 +136,12 @@ done # Defaults if not set if [ -z "$APPLE_SDK" ]; then BACK_ARCH=armv7 - APPLE_SDK=iPhoneOS + APPLE_SDK=iPhoneOS fi # Defaults if not set if [ -z "$IOS_ARCH" ]; then - IOS_ARCH="$BACK_ARCH" + IOS_ARCH="$BACK_ARCH" fi # 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 echo "ERROR: unable to find XCODE_DEVELOPER directory." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # Default toolchain location @@ -157,7 +162,7 @@ XCODE_TOOLCHAIN="$XCODE_DEVELOPER/usr/bin" if [ ! -d "$XCODE_TOOLCHAIN" ]; then echo "ERROR: unable to find XCODE_TOOLCHAIN directory." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 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 # IOS_TOOLCHAIN is the location of the actual compiler tools. @@ -177,7 +182,7 @@ fi if [ -z "$IOS_TOOLCHAIN" ] || [ ! -d "$IOS_TOOLCHAIN" ]; then 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 # @@ -187,16 +192,16 @@ fi unset XCODE_SDK for i in $(seq -f "%.1f" 20.0 -0.1 1.0) do - if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then - XCODE_SDK="$APPLE_SDK$i.sdk" - break - fi + if [ -d "$XCODE_DEVELOPER/Platforms/$APPLE_SDK.platform/Developer/SDKs/$APPLE_SDK$i.sdk" ]; then + XCODE_SDK="$APPLE_SDK$i.sdk" + break + fi done # Error checking if [ -z "$XCODE_SDK" ]; then echo "ERROR: unable to find a SDK." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # https://github.com/weidai11/cryptopp/issues/635 @@ -276,16 +281,16 @@ fi # Only modify/export PATH if IOS_TOOLCHAIN good if [ ! -z "$IOS_TOOLCHAIN" ] && [ ! -z "$XCODE_TOOLCHAIN" ]; then - # And only modify PATH if IOS_TOOLCHAIN is not present - TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" - LEN=${#TOOL_PATH} - SUBSTR=${PATH:0:$LEN} - if [ "$SUBSTR" != "$TOOL_PATH" ]; then - export PATH="$TOOL_PATH":"$PATH" - fi + # And only modify PATH if IOS_TOOLCHAIN is not present + TOOL_PATH="$IOS_TOOLCHAIN:$XCODE_TOOLCHAIN" + LEN=${#TOOL_PATH} + SUBSTR=${PATH:0:$LEN} + if [ "$SUBSTR" != "$TOOL_PATH" ]; then + export PATH="$TOOL_PATH":"$PATH" + fi else - echo "ERROR: unable to set new PATH." - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + echo "ERROR: unable to set new PATH." + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi ######################################## @@ -300,14 +305,14 @@ FOUND_ALL=1 TOOLS=(clang clang++ libtool ld) for tool in ${TOOLS[@]} do - if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then - echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" - FOUND_ALL=0 - fi + if [ ! -e "$IOS_TOOLCHAIN/$tool" ] && [ ! -e "$XCODE_TOOLCHAIN/$tool" ]; then + echo "ERROR: unable to find $tool at IOS_TOOLCHAIN or XCODE_TOOLCHAIN" + FOUND_ALL=0 + fi done if [ "$FOUND_ALL" -eq "0" ]; then - [ "$0" = "$BASH_SOURCE" ] && exit 1 || return 1 + [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1 fi # 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 -[ "$0" = "$BASH_SOURCE" ] && exit 0 || return 0 +[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0