android-build.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /bin/sh
  2. if [ -z "$NDK_PLATFORM" ]; then
  3. export NDK_PLATFORM="android-16"
  4. fi
  5. export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
  6. export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
  7. export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
  8. if [ -z "$ANDROID_NDK_HOME" ]; then
  9. echo "You should probably set ANDROID_NDK_HOME to the directory containing"
  10. echo "the Android NDK"
  11. exit
  12. fi
  13. if [ ! -f ./configure ]; then
  14. echo "Can't find ./configure. Wrong directory or haven't run autogen.sh?" >&2
  15. exit 1
  16. fi
  17. if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
  18. echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
  19. exit 1
  20. fi
  21. export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
  22. export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
  23. export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
  24. export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
  25. export CC=${CC:-"${HOST_COMPILER}-clang"}
  26. rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
  27. echo
  28. if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
  29. echo "Building for platform [${NDK_PLATFORM}], retaining compatibility with platform [${NDK_PLATFORM_COMPAT}]"
  30. else
  31. echo "Building for platform [${NDK_PLATFORM}]"
  32. fi
  33. echo
  34. env - PATH="$PATH" \
  35. "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
  36. --unified-headers --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
  37. ./configure \
  38. --disable-soname-versions \
  39. --enable-minimal \
  40. --host="${HOST_COMPILER}" \
  41. --prefix="${PREFIX}" \
  42. --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
  43. if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
  44. egrep '^#define ' config.log | sort -u > config-def-compat.log
  45. echo
  46. echo "Configuring again for platform [${NDK_PLATFORM}]"
  47. echo
  48. env - PATH="$PATH" \
  49. "$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
  50. --unified-headers --arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
  51. ./configure \
  52. --disable-soname-versions \
  53. --enable-minimal \
  54. --host="${HOST_COMPILER}" \
  55. --prefix="${PREFIX}" \
  56. --with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
  57. egrep '^#define ' config.log | sort -u > config-def.log
  58. if ! cmp config-def.log config-def-compat.log; then
  59. echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
  60. diff -u config-def.log config-def-compat.log >&2
  61. exit 1
  62. fi
  63. rm -f config-def.log config-def-compat.log
  64. fi
  65. make clean && \
  66. make -j3 install && \
  67. echo "libsodium has been installed into ${PREFIX}"