build.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env bash
  2. function usage {
  3. echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
  4. }
  5. # Use directory of current script as the build directory and working directory
  6. cd "$( dirname "${BASH_SOURCE[0]}" )"
  7. ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
  8. # Get access to android_build functions and variables
  9. source ./android_build_helper.sh
  10. # Choose a C++ standard library implementation from the ndk
  11. ANDROID_BUILD_CXXSTL="gnustl_shared_49"
  12. BUILD_ARCH=$1
  13. if [ -z $BUILD_ARCH ]; then
  14. usage
  15. exit 1
  16. fi
  17. case $(uname | tr '[:upper:]' '[:lower:]') in
  18. linux*)
  19. export HOST_PLATFORM=linux-x86_64
  20. ;;
  21. darwin*)
  22. export HOST_PLATFORM=darwin-x86_64
  23. ;;
  24. *)
  25. echo "Unsupported platform"
  26. exit 1
  27. ;;
  28. esac
  29. # Set default values used in ci builds
  30. export NDK_VERSION=${NDK_VERSION:-android-ndk-r20}
  31. # With NDK r20, the minimum SDK version range is [16, 29].
  32. # SDK version 21 is the minimum version for 64-bit builds.
  33. export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
  34. # Set up android build environment and set ANDROID_BUILD_OPTS array
  35. android_build_set_env $BUILD_ARCH
  36. android_build_env
  37. android_build_opts
  38. # Use a temporary build directory
  39. cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
  40. rm -rf "${cache}"
  41. mkdir -p "${cache}"
  42. # Check for environment variable to clear the prefix and do a clean build
  43. if [[ $ANDROID_BUILD_CLEAN ]]; then
  44. echo "Doing a clean build (removing previous build and depedencies)..."
  45. rm -rf "${ANDROID_BUILD_PREFIX}"/*
  46. fi
  47. if [ -z $CURVE ]; then
  48. CURVE="--disable-curve"
  49. VERIFY="libzmq.so"
  50. elif [ $CURVE == "libsodium" ]; then
  51. CURVE="--with-libsodium=yes"
  52. VERIFY="libzmq.so libsodium.so"
  53. ##
  54. # Build libsodium from latest master branch
  55. (android_build_verify_so "libsodium.so" &> /dev/null) || {
  56. rm -rf "${cache}/libsodium"
  57. (cd "${cache}" && git clone -b stable --depth 1 git://github.com/jedisct1/libsodium.git) || exit 1
  58. (cd "${cache}/libsodium" && ./autogen.sh \
  59. && ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" --disable-soname-versions \
  60. && make -j 4 \
  61. && make install) || exit 1
  62. }
  63. elif [ $CURVE == "tweetnacl" ]; then
  64. # Default
  65. CURVE=""
  66. VERIFY="libzmq.so"
  67. fi
  68. ##
  69. # Build libzmq from local source
  70. LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
  71. (android_build_verify_so ${VERIFY} &> /dev/null) || {
  72. rm -rf "${cache}/libzmq"
  73. (cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean)
  74. (cd "${cache}/libzmq" && ./autogen.sh \
  75. && ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \
  76. && make -j 4 \
  77. && make install) || exit 1
  78. }
  79. ##
  80. # Verify shared libraries in prefix
  81. android_build_verify_so ${VERIFY}
  82. echo "libzmq android build succeeded"