2014-11-02 17:33:23 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-02-12 12:14:32 +01:00
|
|
|
function usage {
|
|
|
|
echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
|
|
|
|
}
|
|
|
|
|
2014-11-04 12:57:39 -08:00
|
|
|
# Use directory of current script as the build directory and working directory
|
|
|
|
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
2020-02-12 16:20:27 +01:00
|
|
|
ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
|
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
|
|
|
|
|
|
|
# Choose a C++ standard library implementation from the ndk
|
2016-06-07 23:40:04 +01:00
|
|
|
ANDROID_BUILD_CXXSTL="gnustl_shared_49"
|
2014-11-02 17:33:23 -08:00
|
|
|
|
2020-02-12 12:14:32 +01:00
|
|
|
BUILD_ARCH=$1
|
|
|
|
if [ -z $BUILD_ARCH ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $(uname | tr '[:upper:]' '[:lower:]') in
|
|
|
|
linux*)
|
|
|
|
export HOST_PLATFORM=linux-x86_64
|
|
|
|
;;
|
|
|
|
darwin*)
|
|
|
|
export HOST_PLATFORM=darwin-x86_64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported platform"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Set default values used in ci builds
|
|
|
|
|
2021-10-18 11:05:10 +02:00
|
|
|
export NDK_VERSION=${NDK_VERSION:-android-ndk-r22b}
|
2021-06-07 11:34:13 +02:00
|
|
|
# With NDK r21e, the minimum SDK version range is [16, 29].
|
2020-02-12 12:14:32 +01:00
|
|
|
# SDK version 21 is the minimum version for 64-bit builds.
|
|
|
|
export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
|
|
|
|
|
2014-11-02 17:33:23 -08:00
|
|
|
# Set up android build environment and set ANDROID_BUILD_OPTS array
|
2020-02-12 21:36:41 +01: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
|
|
|
|
echo "Doing a clean build (removing previous build and depedencies)..."
|
|
|
|
rm -rf "${ANDROID_BUILD_PREFIX}"/*
|
|
|
|
fi
|
|
|
|
|
2016-02-11 22:06:33 +00:00
|
|
|
if [ -z $CURVE ]; then
|
|
|
|
CURVE="--disable-curve"
|
|
|
|
VERIFY="libzmq.so"
|
|
|
|
elif [ $CURVE == "libsodium" ]; then
|
|
|
|
CURVE="--with-libsodium=yes"
|
|
|
|
VERIFY="libzmq.so libsodium.so"
|
|
|
|
##
|
|
|
|
# Build libsodium from latest master 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"
|
|
|
|
(cd "${cache}" && git clone -b stable --depth 1 git://github.com/jedisct1/libsodium.git) || exit 1
|
|
|
|
(cd "${cache}/libsodium" && ./autogen.sh \
|
|
|
|
&& ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" --disable-soname-versions \
|
|
|
|
&& make -j 4 \
|
|
|
|
&& make install) || exit 1
|
|
|
|
}
|
|
|
|
elif [ $CURVE == "tweetnacl" ]; then
|
|
|
|
# Default
|
|
|
|
CURVE=""
|
|
|
|
VERIFY="libzmq.so"
|
|
|
|
fi
|
2014-11-04 12:57:39 -08:00
|
|
|
|
|
|
|
##
|
|
|
|
# Build libzmq from local source
|
|
|
|
|
|
|
|
LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
|
|
|
|
|
2016-02-11 22:06:33 +00:00
|
|
|
(android_build_verify_so ${VERIFY} &> /dev/null) || {
|
2014-11-04 12:57:39 -08:00
|
|
|
rm -rf "${cache}/libzmq"
|
|
|
|
(cp -r ../.. "${cache}/libzmq" && cd "${cache}/libzmq" && make clean)
|
2020-02-12 12:14:32 +01:00
|
|
|
|
2014-11-04 12:57:39 -08:00
|
|
|
(cd "${cache}/libzmq" && ./autogen.sh \
|
2016-02-11 22:06:33 +00:00
|
|
|
&& ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" ${CURVE} --without-docs \
|
2016-01-05 17:31:17 +01:00
|
|
|
&& make -j 4 \
|
2014-11-04 12:57:39 -08:00
|
|
|
&& make install) || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
# Verify shared libraries in prefix
|
2014-11-02 17:33:23 -08:00
|
|
|
|
2016-02-11 22:06:33 +00:00
|
|
|
android_build_verify_so ${VERIFY}
|
2015-12-16 11:58:44 +01:00
|
|
|
echo "libzmq android build succeeded"
|