Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/libsodium/dist-build/android-build.sh
48260 views
1
#! /bin/sh
2
3
if [ -z "$NDK_PLATFORM" ]; then
4
export NDK_PLATFORM="android-16"
5
fi
6
export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
7
export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
8
export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
9
10
if [ -z "$ANDROID_NDK_HOME" ]; then
11
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
12
echo "the Android NDK"
13
exit
14
fi
15
16
if [ ! -f ./configure ]; then
17
echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
18
exit 1
19
fi
20
21
if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
22
echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
23
exit 1
24
fi
25
26
export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
27
28
export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
29
export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
30
export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
31
32
export CC=${CC:-"${HOST_COMPILER}-clang"}
33
34
rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
35
36
echo
37
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
38
echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"
39
else
40
echo "Building for platform [${NDK_PLATFORM}]"
41
fi
42
echo
43
44
env - PATH="$PATH" \
45
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
46
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
47
48
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
49
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
50
else
51
export LIBSODIUM_ENABLE_MINIMAL_FLAG=""
52
fi
53
54
./configure \
55
--disable-soname-versions \
56
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
57
--host="${HOST_COMPILER}" \
58
--prefix="${PREFIX}" \
59
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
60
61
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
62
egrep '^#define ' config.log | sort -u > config-def-compat.log
63
echo
64
echo "Configuring again for platform [${NDK_PLATFORM}]"
65
echo
66
env - PATH="$PATH" \
67
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
68
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
69
70
./configure \
71
--disable-soname-versions \
72
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
73
--host="${HOST_COMPILER}" \
74
--prefix="${PREFIX}" \
75
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
76
77
egrep '^#define ' config.log | sort -u > config-def.log
78
if ! cmp config-def.log config-def-compat.log; then
79
echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
80
diff -u config-def.log config-def-compat.log >&2
81
exit 1
82
fi
83
rm -f config-def.log config-def-compat.log
84
fi
85
86
87
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
88
PROCESSORS=${NPROCESSORS:-3}
89
90
make clean && \
91
make -j${PROCESSORS} install && \
92
echo "libsodium has been installed into ${PREFIX}"
93
94