Path: blob/main/sys/contrib/libsodium/dist-build/android-build.sh
48260 views
#! /bin/sh12if [ -z "$NDK_PLATFORM" ]; then3export NDK_PLATFORM="android-16"4fi5export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"6export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')7export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')89if [ -z "$ANDROID_NDK_HOME" ]; then10echo "You should probably set ANDROID_NDK_HOME to the directory containing"11echo "the Android NDK"12exit13fi1415if [ ! -f ./configure ]; then16echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&217exit 118fi1920if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then21echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&222exit 123fi2425export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"2627export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"28export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"29export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"3031export CC=${CC:-"${HOST_COMPILER}-clang"}3233rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"3435echo36if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then37echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"38else39echo "Building for platform [${NDK_PLATFORM}]"40fi41echo4243env - PATH="$PATH" \44"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \45--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 14647if [ -z "$LIBSODIUM_FULL_BUILD" ]; then48export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"49else50export LIBSODIUM_ENABLE_MINIMAL_FLAG=""51fi5253./configure \54--disable-soname-versions \55${LIBSODIUM_ENABLE_MINIMAL_FLAG} \56--host="${HOST_COMPILER}" \57--prefix="${PREFIX}" \58--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 15960if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then61egrep '^#define ' config.log | sort -u > config-def-compat.log62echo63echo "Configuring again for platform [${NDK_PLATFORM}]"64echo65env - PATH="$PATH" \66"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \67--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 16869./configure \70--disable-soname-versions \71${LIBSODIUM_ENABLE_MINIMAL_FLAG} \72--host="${HOST_COMPILER}" \73--prefix="${PREFIX}" \74--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 17576egrep '^#define ' config.log | sort -u > config-def.log77if ! cmp config-def.log config-def-compat.log; then78echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&279diff -u config-def.log config-def-compat.log >&280exit 181fi82rm -f config-def.log config-def-compat.log83fi848586NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)87PROCESSORS=${NPROCESSORS:-3}8889make clean && \90make -j${PROCESSORS} install && \91echo "libsodium has been installed into ${PREFIX}"929394