android-build.sh (3024B)
1 #! /bin/sh 2 3 if [ -z "$NDK_PLATFORM" ]; then 4 echo "No NDK_PLATFORM specified, set to value such as \"android-{Min_SDK_VERSION}\" or just use android-aar.sh" 5 exit 6 fi 7 SDK_VERSION=$(echo "$NDK_PLATFORM" | cut -f2 -d"-") 8 export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}" 9 export NDK_API_VERSION="$(echo "$NDK_PLATFORM" | sed 's/^android-//')" 10 export NDK_API_VERSION_COMPAT="$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')" 11 12 if [ -z "$ANDROID_NDK_HOME" ]; then 13 echo "ANDROID_NDK_HOME must be set to the directory containing the Android NDK." 14 exit 1 15 fi 16 17 if [ ! -f ./configure ]; then 18 echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2 19 exit 1 20 fi 21 22 if [ -z "$TARGET_ARCH" ] || [ -z "$ARCH" ] || [ -z "$HOST_COMPILER" ]; then 23 echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2 24 exit 1 25 fi 26 27 export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}" 28 export TOOLCHAIN_OS_DIR="$(uname | tr '[:upper:]' '[:lower:]')-x86_64/" 29 export TOOLCHAIN_DIR="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}" 30 31 export PATH="${PATH}:${TOOLCHAIN_DIR}/bin" 32 33 export CC=${CC:-"${HOST_COMPILER}${SDK_VERSION}-clang"} 34 35 echo 36 echo "Warnings related to headers being present but not usable are due to functions" 37 echo "that didn't exist in the specified minimum API version level." 38 echo "They can be safely ignored." 39 echo 40 41 echo 42 if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then 43 echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]" 44 else 45 echo "Building for platform [${NDK_PLATFORM}]" 46 fi 47 echo 48 49 if [ -z "$LIBSODIUM_FULL_BUILD" ]; then 50 export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal" 51 else 52 export LIBSODIUM_ENABLE_MINIMAL_FLAG="" 53 fi 54 55 ./configure \ 56 --disable-soname-versions \ 57 --disable-pie \ 58 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 59 --host="${HOST_COMPILER}" \ 60 --prefix="${PREFIX}" \ 61 --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1 62 63 if [ -z "$NDK_PLATFORM" ]; then 64 echo "Aborting" 65 exit 1 66 fi 67 if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then 68 grep -E '^#define ' config.log | sort -u >config-def-compat.log 69 echo 70 echo "Configuring again for platform [${NDK_PLATFORM}]" 71 echo 72 73 ./configure \ 74 --disable-soname-versions \ 75 --disable-pie \ 76 ${LIBSODIUM_ENABLE_MINIMAL_FLAG} \ 77 --host="${HOST_COMPILER}" \ 78 --prefix="${PREFIX}" \ 79 --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1 80 81 grep -E '^#define ' config.log | sort -u >config-def.log 82 if ! cmp config-def.log config-def-compat.log; then 83 echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2 84 diff -u config-def.log config-def-compat.log >&2 85 exit 1 86 fi 87 rm -f config-def.log config-def-compat.log 88 fi 89 90 NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null) 91 PROCESSORS=${NPROCESSORS:-3} 92 93 make clean && 94 make -j"${PROCESSORS}" install && 95 echo "libsodium has been installed into ${PREFIX}"