xref: /netbsd-src/sys/external/isc/libsodium/dist/dist-build/android-build.sh (revision aef5eb5f59cdfe8314f1b5f78ac04eb144e44010)
1#! /bin/sh
2
3if [ -z "$NDK_PLATFORM" ]; then
4  export NDK_PLATFORM="android-16"
5fi
6export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
7export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
8export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
9
10if [ -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
14fi
15
16if [ ! -f ./configure ]; then
17  echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
18  exit 1
19fi
20
21if [ "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
24fi
25
26export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
27
28export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
29export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
30export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
31
32export CC=${CC:-"${HOST_COMPILER}-clang"}
33
34rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
35
36echo
37if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
38  echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"
39else
40  echo "Building for platform [${NDK_PLATFORM}]"
41fi
42echo
43
44env - PATH="$PATH" \
45    "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
46    --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
47
48./configure \
49    --disable-soname-versions \
50    --enable-minimal \
51    --host="${HOST_COMPILER}" \
52    --prefix="${PREFIX}" \
53    --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
54
55if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
56  egrep '^#define ' config.log | sort -u > config-def-compat.log
57  echo
58  echo "Configuring again for platform [${NDK_PLATFORM}]"
59  echo
60  env - PATH="$PATH" \
61      "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
62      --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
63
64  ./configure \
65      --disable-soname-versions \
66      --enable-minimal \
67      --host="${HOST_COMPILER}" \
68      --prefix="${PREFIX}" \
69      --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
70
71  egrep '^#define ' config.log | sort -u > config-def.log
72  if ! cmp config-def.log config-def-compat.log; then
73    echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
74    diff -u config-def.log config-def-compat.log >&2
75    exit 1
76  fi
77  rm -f config-def.log config-def-compat.log
78fi
79
80make clean && \
81make -j3 install && \
82echo "libsodium has been installed into ${PREFIX}"
83