2015-02-08 09:04:15 -07:00
|
|
|
#! /bin/sh
|
2014-02-17 02:07:47 -07:00
|
|
|
|
2016-06-05 13:00:56 -07:00
|
|
|
if [ -z "$NDK_PLATFORM" ]; then
|
2017-05-20 10:16:05 -07:00
|
|
|
export NDK_PLATFORM="android-16"
|
2016-06-05 13:00:56 -07:00
|
|
|
fi
|
2017-05-20 10:16:05 -07:00
|
|
|
export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
|
2017-03-06 02:06:24 -07:00
|
|
|
export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
|
|
|
|
export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
|
2016-06-05 13:00:56 -07:00
|
|
|
|
2014-02-17 02:07:47 -07:00
|
|
|
if [ -z "$ANDROID_NDK_HOME" ]; then
|
2016-12-17 10:52:52 -07:00
|
|
|
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
|
|
|
|
echo "the Android NDK"
|
2020-06-06 00:36:57 -07:00
|
|
|
exit 1
|
2014-02-17 02:07:47 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f ./configure ]; then
|
2017-03-06 02:54:00 -07:00
|
|
|
echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
|
2016-12-17 10:52:52 -07:00
|
|
|
exit 1
|
2014-02-17 02:07:47 -07:00
|
|
|
fi
|
|
|
|
|
2015-02-08 02:34:39 -07:00
|
|
|
if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
|
2017-03-06 02:54:00 -07:00
|
|
|
echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
|
2016-12-17 10:52:52 -07:00
|
|
|
exit 1
|
2014-02-17 02:07:47 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
|
2021-12-28 14:15:08 -07:00
|
|
|
export TOOLCHAIN_OS_DIR="$(uname | tr '[:upper:]' '[:lower:]')-x86_64/"
|
2021-12-28 14:12:52 -07:00
|
|
|
export TOOLCHAIN_DIR="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}"
|
|
|
|
echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}/${HOST_COMPILER}"
|
2014-02-17 02:07:47 -07:00
|
|
|
|
2021-12-28 14:12:52 -07:00
|
|
|
export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
|
2021-12-28 14:15:08 -07:00
|
|
|
SDK_VERSION_NUM=$(echo $NDK_PLATFORM | cut -d'-' -f2)
|
2021-12-28 14:12:52 -07:00
|
|
|
export CC=${CC:-"${HOST_COMPILER}${SDK_VERSION_NUM}-clang"}
|
2014-02-17 02:07:47 -07:00
|
|
|
|
2019-04-18 15:54:59 -07:00
|
|
|
echo
|
|
|
|
echo "Warnings related to headers being present but not usable are due to functions"
|
|
|
|
echo "that didn't exist in the specified minimum API version level."
|
|
|
|
echo "They can be safely ignored."
|
|
|
|
echo
|
|
|
|
|
2016-06-05 13:04:10 -07:00
|
|
|
echo
|
2017-05-20 10:16:05 -07:00
|
|
|
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
|
|
|
echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"
|
|
|
|
else
|
|
|
|
echo "Building for platform [${NDK_PLATFORM}]"
|
|
|
|
fi
|
2016-06-05 13:00:56 -07:00
|
|
|
echo
|
|
|
|
|
|
|
|
|
2018-03-06 13:10:05 -07:00
|
|
|
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
|
2018-03-06 12:36:39 -07:00
|
|
|
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
|
2018-03-06 13:20:17 -07:00
|
|
|
else
|
|
|
|
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
|
2018-03-06 12:27:47 -07:00
|
|
|
fi
|
|
|
|
|
2015-08-05 10:46:36 -07:00
|
|
|
./configure \
|
2020-07-04 06:32:13 -07:00
|
|
|
--disable-soname-versions \
|
|
|
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
|
|
|
--host="${HOST_COMPILER}" \
|
|
|
|
--prefix="${PREFIX}" \
|
|
|
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
2016-06-05 13:00:56 -07:00
|
|
|
|
|
|
|
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
2020-07-04 06:32:13 -07:00
|
|
|
egrep '^#define ' config.log | sort -u >config-def-compat.log
|
2016-06-05 13:00:56 -07:00
|
|
|
echo
|
|
|
|
echo "Configuring again for platform [${NDK_PLATFORM}]"
|
|
|
|
echo
|
|
|
|
|
|
|
|
./configure \
|
2020-07-04 06:32:13 -07:00
|
|
|
--disable-soname-versions \
|
|
|
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
|
|
|
--host="${HOST_COMPILER}" \
|
|
|
|
--prefix="${PREFIX}" \
|
|
|
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
2016-06-05 13:00:56 -07:00
|
|
|
|
2021-12-28 14:15:08 -07:00
|
|
|
grep -E '^#define ' config.log | sort -u >config-def.log
|
2016-06-05 13:00:56 -07:00
|
|
|
if ! cmp config-def.log config-def-compat.log; then
|
|
|
|
echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
|
|
|
|
diff -u config-def.log config-def-compat.log >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm -f config-def.log config-def-compat.log
|
|
|
|
fi
|
|
|
|
|
2018-03-07 02:14:01 -07:00
|
|
|
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
|
2018-03-07 00:15:01 -07:00
|
|
|
PROCESSORS=${NPROCESSORS:-3}
|
|
|
|
|
2020-07-04 06:32:13 -07:00
|
|
|
make clean &&
|
|
|
|
make -j${PROCESSORS} install &&
|
|
|
|
echo "libsodium has been installed into ${PREFIX}"
|