2014-11-02 17:33:23 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-10-02 02:27:12 +02:00
|
|
|
set -e
|
|
|
|
|
2022-10-21 11:55:33 +02:00
|
|
|
# Use directory of current script as the working directory
|
|
|
|
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Configuration & tuning options.
|
|
|
|
########################################################################
|
|
|
|
# Set default values used in ci builds
|
|
|
|
export NDK_VERSION="${NDK_VERSION:-android-ndk-r25}"
|
|
|
|
|
|
|
|
# Set default path to find Android NDK.
|
|
|
|
# Must be of the form <path>/${NDK_VERSION} !!
|
|
|
|
export ANDROID_NDK_ROOT="${ANDROID_NDK_ROOT:-/tmp/${NDK_VERSION}}"
|
|
|
|
|
|
|
|
# With NDK r22b, the minimum SDK version range is [16, 31].
|
|
|
|
# Since NDK r24, the minimum SDK version range is [19, 31].
|
|
|
|
# SDK version 21 is the minimum version for 64-bit builds.
|
|
|
|
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
|
|
|
|
|
|
|
|
# Use directory of current script as the build directory
|
|
|
|
# ${ANDROID_BUILD_DIR}/prefix/<build_arch>/lib will contain produced libraries
|
|
|
|
export ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-${PWD}}"
|
|
|
|
|
|
|
|
# Clean before processing
|
|
|
|
export ANDROID_BUILD_CLEAN="${ANDROID_BUILD_CLEAN:-}"
|
|
|
|
|
|
|
|
# Select CURVE implementation:
|
|
|
|
# - "" # Do not use any CURVE implementation.
|
|
|
|
# - "libsodium" # Use LIBSODIUM implementation.
|
|
|
|
# - "tweetnacl" # Use internal TWEETNACL implementation.
|
|
|
|
export CURVE="${CURVE:-}"
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Utilities
|
|
|
|
########################################################################
|
2020-02-12 12:14:32 +01:00
|
|
|
function usage {
|
2022-10-21 11:55:33 +02:00
|
|
|
echo "LIBZMQ - Usage:"
|
|
|
|
echo " export XXX=yyy"
|
|
|
|
echo " ./build.sh [ arm | arm64 | x86 | x86_64 ]"
|
|
|
|
echo ""
|
|
|
|
echo "See this file (configuration & tuning options) for details"
|
|
|
|
echo "on variables XXX and their values xxx"
|
|
|
|
exit 1
|
2020-02-12 12:14:32 +01:00
|
|
|
}
|
|
|
|
|
2022-10-21 11:55:33 +02:00
|
|
|
########################################################################
|
|
|
|
# Sanity checks
|
|
|
|
########################################################################
|
|
|
|
BUILD_ARCH="$1"
|
|
|
|
[ -z "${BUILD_ARCH}" ] && usage
|
2014-11-02 17:33:23 -08:00
|
|
|
|
2022-10-21 11:55:33 +02:00
|
|
|
########################################################################
|
|
|
|
# Compilation
|
|
|
|
########################################################################
|
2014-11-02 17:33:23 -08:00
|
|
|
# Get access to android_build functions and variables
|
2020-02-12 16:20:27 +01:00
|
|
|
source ./android_build_helper.sh
|
2014-11-02 17:33:23 -08:00
|
|
|
|
2022-05-10 15:21:06 +02:00
|
|
|
# Choose a C++ standard library implementation from the ndk
|
2022-10-11 22:40:13 +02:00
|
|
|
export ANDROID_BUILD_CXXSTL="gnustl_shared_49"
|
|
|
|
|
|
|
|
# Additional flags for LIBTOOL, for LIBZMQ and other dependencies.
|
|
|
|
export LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
|
2022-05-10 15:21:06 +02:00
|
|
|
|
2022-10-11 16:20:14 +02:00
|
|
|
platform="$(uname | tr '[:upper:]' '[:lower:]')"
|
|
|
|
case "${platform}" in
|
|
|
|
linux*) export HOST_PLATFORM=linux-x86_64 ;;
|
|
|
|
darwin*) export HOST_PLATFORM=darwin-x86_64 ;;
|
|
|
|
*) echo "LIBZMQ (${BUILD_ARCH}) - Unsupported platform ('${platform}')" ; exit 1 ;;
|
2020-02-12 12:14:32 +01:00
|
|
|
esac
|
|
|
|
|
2014-11-02 17:33:23 -08:00
|
|
|
# Set up android build environment and set ANDROID_BUILD_OPTS array
|
2022-10-21 11:55:33 +02:00
|
|
|
android_build_set_env "${BUILD_ARCH}"
|
2014-11-02 17:33:23 -08:00
|
|
|
android_build_env
|
|
|
|
android_build_opts
|
|
|
|
|
2014-11-04 12:57:39 -08:00
|
|
|
# Use a temporary build directory
|
2020-02-12 12:14:32 +01:00
|
|
|
cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
|
2015-01-28 17:30:35 -08:00
|
|
|
rm -rf "${cache}"
|
2014-11-02 17:33:23 -08:00
|
|
|
mkdir -p "${cache}"
|
|
|
|
|
2015-01-28 17:30:35 -08:00
|
|
|
# Check for environment variable to clear the prefix and do a clean build
|
|
|
|
if [[ $ANDROID_BUILD_CLEAN ]]; then
|
2022-10-11 16:20:14 +02:00
|
|
|
echo "LIBZMQ (${BUILD_ARCH}) - Doing a clean build (removing previous build and dependencies)..."
|
2022-10-21 11:55:33 +02:00
|
|
|
rm -rf "${ANDROID_BUILD_PREFIX:-android-build-prefix-not-set}"/*
|
|
|
|
|
|
|
|
# Called shells MUST not clean after ourselves !
|
|
|
|
export ANDROID_BUILD_CLEAN=""
|
2015-01-28 17:30:35 -08:00
|
|
|
fi
|
|
|
|
|
2022-10-12 02:42:28 +02:00
|
|
|
VERIFY=("libzmq.so")
|
2022-10-21 11:55:33 +02:00
|
|
|
if [ -z "${CURVE}" ]; then
|
2016-02-11 22:06:33 +00:00
|
|
|
CURVE="--disable-curve"
|
2022-10-21 11:55:33 +02:00
|
|
|
elif [ "${CURVE}" == "libsodium" ]; then
|
2016-02-11 22:06:33 +00:00
|
|
|
CURVE="--with-libsodium=yes"
|
2022-10-12 02:42:28 +02:00
|
|
|
VERIFY+=("libsodium.so")
|
2016-02-11 22:06:33 +00:00
|
|
|
##
|
2022-10-21 11:55:33 +02:00
|
|
|
# Build LIBSODIUM from latest STABLE branch
|
2014-11-04 12:57:39 -08:00
|
|
|
|
2016-02-11 22:06:33 +00:00
|
|
|
(android_build_verify_so "libsodium.so" &> /dev/null) || {
|
|
|
|
rm -rf "${cache}/libsodium"
|
2022-10-21 11:55:33 +02:00
|
|
|
(
|
|
|
|
echo "LIBZMQ (${BUILD_ARCH}) - Cloning 'https://github.com/jedisct1/libsodium.git' (branch 'stable') under '${cache}/libsodium}'." \
|
|
|
|
&& cd "${cache}" \
|
|
|
|
&& git clone --quiet -b stable --depth 1 https://github.com/jedisct1/libsodium.git \
|
|
|
|
&& cd "${cache}/libsodium" \
|
|
|
|
&& git log --oneline -n 1
|
|
|
|
) || exit 1
|
2022-10-05 18:17:46 +02:00
|
|
|
(
|
|
|
|
CONFIG_OPTS=()
|
|
|
|
CONFIG_OPTS+=("--quiet")
|
|
|
|
CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}")
|
2022-10-21 11:55:33 +02:00
|
|
|
CONFIG_OPTS+=("--disable-soname-versions")
|
2022-10-05 18:17:46 +02:00
|
|
|
|
|
|
|
cd "${cache}/libsodium" \
|
|
|
|
&& ./autogen.sh \
|
|
|
|
&& android_show_configure_opts "LIBSODIUM" "${CONFIG_OPTS[@]}" \
|
|
|
|
&& ./configure "${CONFIG_OPTS[@]}" \
|
2016-02-11 22:06:33 +00:00
|
|
|
&& make -j 4 \
|
2022-10-05 18:17:46 +02:00
|
|
|
&& make install
|
|
|
|
) || exit 1
|
2016-02-11 22:06:33 +00:00
|
|
|
}
|
|
|
|
elif [ $CURVE == "tweetnacl" ]; then
|
|
|
|
# Default
|
|
|
|
CURVE=""
|
|
|
|
fi
|
2014-11-04 12:57:39 -08:00
|
|
|
|
|
|
|
##
|
|
|
|
# Build libzmq from local source
|
|
|
|
|
2022-10-12 02:42:28 +02:00
|
|
|
(android_build_verify_so "${VERIFY[@]}" &> /dev/null) || {
|
2014-11-04 12:57:39 -08:00
|
|
|
rm -rf "${cache}/libzmq"
|
2022-10-02 02:27:12 +02:00
|
|
|
(cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && ( make clean || : ))
|
2020-02-12 12:14:32 +01:00
|
|
|
|
2022-10-05 18:17:46 +02:00
|
|
|
(
|
|
|
|
CONFIG_OPTS=()
|
|
|
|
CONFIG_OPTS+=("--quiet")
|
|
|
|
CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}")
|
|
|
|
CONFIG_OPTS+=("${CURVE}")
|
|
|
|
CONFIG_OPTS+=("--without-docs")
|
2022-10-21 11:55:33 +02:00
|
|
|
|
2022-10-05 18:17:46 +02:00
|
|
|
cd "${cache}/libzmq" \
|
|
|
|
&& ./autogen.sh \
|
|
|
|
&& android_show_configure_opts "LIBZMQ" "${CONFIG_OPTS[@]}" \
|
|
|
|
&& ./configure "${CONFIG_OPTS[@]}" \
|
2016-01-05 17:31:17 +01:00
|
|
|
&& make -j 4 \
|
2022-10-05 18:17:46 +02:00
|
|
|
&& make install
|
|
|
|
) || exit 1
|
2014-11-04 12:57:39 -08:00
|
|
|
}
|
|
|
|
|
2022-10-11 22:40:13 +02:00
|
|
|
##
|
|
|
|
# Fetch the STL as well.
|
|
|
|
|
|
|
|
cp "${ANDROID_STL_ROOT}/${ANDROID_STL}" "${ANDROID_BUILD_PREFIX}/lib/."
|
|
|
|
|
2014-11-04 12:57:39 -08:00
|
|
|
##
|
|
|
|
# Verify shared libraries in prefix
|
2014-11-02 17:33:23 -08:00
|
|
|
|
2022-10-12 02:42:28 +02:00
|
|
|
android_build_verify_so "${VERIFY[@]}" "${ANDROID_STL}"
|
2022-10-11 16:20:14 +02:00
|
|
|
echo "LIBZMQ (${BUILD_ARCH}) - Android build successful"
|