2015-02-08 11:04:15 -05:00
|
|
|
#! /bin/sh
|
2014-02-17 04:07:47 -05:00
|
|
|
|
2016-06-05 16:00:56 -04:00
|
|
|
if [ -z "$NDK_PLATFORM" ]; then
|
2017-05-20 13:16:05 -04:00
|
|
|
export NDK_PLATFORM="android-16"
|
2016-06-05 16:00:56 -04:00
|
|
|
fi
|
2017-05-20 13:16:05 -04:00
|
|
|
export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
|
2017-03-06 04:06:24 -05: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 16:00:56 -04:00
|
|
|
|
2014-02-17 04:07:47 -05:00
|
|
|
if [ -z "$ANDROID_NDK_HOME" ]; then
|
2016-12-17 12:52:52 -05:00
|
|
|
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
|
|
|
|
echo "the Android NDK"
|
|
|
|
exit
|
2014-02-17 04:07:47 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f ./configure ]; then
|
2017-03-06 04:54:00 -05:00
|
|
|
echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
|
2016-12-17 12:52:52 -05:00
|
|
|
exit 1
|
2014-02-17 04:07:47 -05:00
|
|
|
fi
|
|
|
|
|
2015-02-08 04:34:39 -05:00
|
|
|
if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
|
2017-03-06 04:54:00 -05:00
|
|
|
echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
|
2016-12-17 12:52:52 -05:00
|
|
|
exit 1
|
2014-02-17 04:07:47 -05:00
|
|
|
fi
|
|
|
|
|
2017-03-06 04:06:24 -05:00
|
|
|
export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
|
2014-02-17 04:07:47 -05:00
|
|
|
|
|
|
|
export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
|
|
|
|
export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
|
|
|
|
export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
|
|
|
|
|
2017-03-06 10:53:08 -05:00
|
|
|
export CC=${CC:-"${HOST_COMPILER}-clang"}
|
|
|
|
|
2014-02-17 04:07:47 -05:00
|
|
|
rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
|
|
|
|
|
2016-06-05 16:04:10 -04:00
|
|
|
echo
|
2017-05-20 13:16:05 -04: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 16:00:56 -04:00
|
|
|
echo
|
|
|
|
|
2017-03-06 04:06:24 -05:00
|
|
|
env - PATH="$PATH" \
|
2017-03-06 07:33:25 -05:00
|
|
|
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
|
2017-11-22 08:53:52 -05:00
|
|
|
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
|
2016-06-05 16:00:56 -04:00
|
|
|
|
2018-03-06 15:10:05 -05:00
|
|
|
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
|
2018-03-06 14:36:39 -05:00
|
|
|
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
|
2018-03-06 15:20:17 -05:00
|
|
|
else
|
|
|
|
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
|
2018-03-06 14:27:47 -05:00
|
|
|
fi
|
|
|
|
|
2015-08-05 13:46:36 -04:00
|
|
|
./configure \
|
2018-03-06 14:36:39 -05:00
|
|
|
--disable-soname-versions \
|
|
|
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
2015-08-05 13:46:36 -04:00
|
|
|
--host="${HOST_COMPILER}" \
|
|
|
|
--prefix="${PREFIX}" \
|
2016-06-05 16:00:56 -04:00
|
|
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
|
|
|
|
|
|
|
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
|
|
|
egrep '^#define ' config.log | sort -u > config-def-compat.log
|
|
|
|
echo
|
|
|
|
echo "Configuring again for platform [${NDK_PLATFORM}]"
|
|
|
|
echo
|
2017-03-06 04:06:24 -05:00
|
|
|
env - PATH="$PATH" \
|
2017-03-06 07:33:25 -05:00
|
|
|
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
|
2017-11-22 08:53:52 -05:00
|
|
|
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
|
2016-06-05 16:00:56 -04:00
|
|
|
|
|
|
|
./configure \
|
2018-03-06 14:36:39 -05:00
|
|
|
--disable-soname-versions \
|
|
|
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
2016-06-05 16:00:56 -04:00
|
|
|
--host="${HOST_COMPILER}" \
|
|
|
|
--prefix="${PREFIX}" \
|
|
|
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
|
|
|
|
|
|
|
egrep '^#define ' config.log | sort -u > config-def.log
|
|
|
|
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:15:01 -05:00
|
|
|
|
|
|
|
NPROCESSORS=$(getconf _NPROCESSORS_ONLN)
|
|
|
|
PROCESSORS=${NPROCESSORS:-3}
|
|
|
|
|
2014-02-17 04:07:47 -05:00
|
|
|
make clean && \
|
2018-03-07 02:15:01 -05:00
|
|
|
make -j${PROCESSORS} install && \
|
2015-08-05 14:00:15 -04:00
|
|
|
echo "libsodium has been installed into ${PREFIX}"
|