1#!/usr/bin/env bash
2################################################################################
3#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
4#  Read the zproject/README.md for information about making permanent changes. #
5################################################################################
6
7# Set this to enable verbose profiling
8[ -n "${CI_TIME-}" ] || CI_TIME=""
9case "$CI_TIME" in
10    [Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
11        CI_TIME="time -p " ;;
12    [Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
13        CI_TIME="" ;;
14esac
15
16# Set this to enable verbose tracing
17[ -n "${CI_TRACE-}" ] || CI_TRACE="no"
18case "$CI_TRACE" in
19    [Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
20        set +x ;;
21    [Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
22        set -x ;;
23esac
24
25function usage {
26    echo "Usage ./build.sh [ arm | arm64 | x86 | x86_64 ]"
27}
28
29# Use directory of current script as the build directory and working directory
30cd "$( dirname "${BASH_SOURCE[0]}" )"
31ANDROID_BUILD_DIR="${ANDROID_BUILD_DIR:-`pwd`}"
32
33# Get access to android_build functions and variables
34source ./android_build_helper.sh
35
36BUILD_ARCH=$1
37if [ -z $BUILD_ARCH ]; then
38    usage
39    exit 1
40fi
41
42case $(uname | tr '[:upper:]' '[:lower:]') in
43  linux*)
44    export HOST_PLATFORM=linux-x86_64
45    ;;
46  darwin*)
47    export HOST_PLATFORM=darwin-x86_64
48    ;;
49  *)
50    echo "Unsupported platform"
51    exit 1
52    ;;
53esac
54
55# Set default values used in ci builds
56export NDK_VERSION=${NDK_VERSION:-android-ndk-r21d}
57# With NDK r21d, the minimum SDK version range is [16, 29].
58# SDK version 21 is the minimum version for 64-bit builds.
59export MIN_SDK_VERSION=${MIN_SDK_VERSION:-21}
60
61# Set up android build environment and set ANDROID_BUILD_OPTS array
62android_build_set_env $BUILD_ARCH
63android_build_env
64android_build_opts
65
66# Use a temporary build directory
67cache="/tmp/android_build/${TOOLCHAIN_ARCH}"
68rm -rf "${cache}"
69mkdir -p "${cache}"
70
71# Check for environment variable to clear the prefix and do a clean build
72if [[ $ANDROID_BUILD_CLEAN ]]; then
73    echo "Doing a clean build (removing previous build and depedencies)..."
74    rm -rf "${ANDROID_BUILD_PREFIX}"/*
75fi
76
77##
78# Make sure czmq is built and copy the prefix
79
80(android_build_verify_so "libczmq.so" &> /dev/null) || {
81    # Use a default value assuming the czmq project sits alongside this one
82    test -z "$CZMQ_ROOT" && CZMQ_ROOT="$(cd ../../../czmq && pwd)"
83
84    if [ ! -d "$CZMQ_ROOT" ]; then
85        echo "The CZMQ_ROOT directory does not exist"
86        echo "  ${CZMQ_ROOT}" run run
87        exit 1
88    fi
89    echo "Building czmq in ${CZMQ_ROOT}..."
90
91    (bash ${CZMQ_ROOT}/builds/android/build.sh $BUILD_ARCH) || exit 1
92    UPSTREAM_PREFIX=${CZMQ_ROOT}/builds/android/prefix/${TOOLCHAIN_ARCH}
93    cp -rn ${UPSTREAM_PREFIX}/* ${ANDROID_BUILD_PREFIX}
94}
95
96##
97[ -z "$CI_TIME" ] || echo "`date`: Build zyre from local source"
98
99(android_build_verify_so "libzyre.so" "libczmq.so" &> /dev/null) || {
100    rm -rf "${cache}/zyre"
101    (cp -r ../.. "${cache}/zyre" && cd "${cache}/zyre" \
102        && make clean && rm -f configure config.status)
103
104    # Remove *.la files as they might cause errors with cross compiled libraries
105    find ${ANDROID_BUILD_PREFIX} -name '*.la' -exec rm {} +
106
107    export LIBTOOL_EXTRA_LDFLAGS='-avoid-version'
108
109    (cd "${cache}/zyre" && $CI_TIME ./autogen.sh 2> /dev/null \
110        && $CI_TIME ./configure --quiet "${ANDROID_BUILD_OPTS[@]}" --without-docs \
111        && $CI_TIME make -j 4 \
112        && $CI_TIME make install) || exit 1
113}
114
115##
116# Verify shared libraries in prefix
117
118android_build_verify_so "libczmq.so"
119android_build_verify_so "libzyre.so" "libczmq.so"
120echo "Android (${TOOLCHAIN_ARCH}) build successful"
121################################################################################
122#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
123#  Read the zproject/README.md for information about making permanent changes. #
124################################################################################
125