From 6fb3a58ca83dfde0eed3ed2dc2f9e4a4faf5a336 Mon Sep 17 00:00:00 2001 From: "Stephan Guilloux (cos)" Date: Mon, 24 Oct 2022 17:34:27 +0200 Subject: [PATCH] Problem: Android helpers must provide build/clone functions. Reason: Code factorisation & code sharing. Solution: Create more functions in helper file: - android_clone_library # Clone a library source tree. - android_build_library # Build a library in its source tree. --- builds/android/android_build_helper.sh | 42 ++++++++++++++++++++++++++ builds/android/build.sh | 28 ++--------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/builds/android/android_build_helper.sh b/builds/android/android_build_helper.sh index fa25d757..7867782d 100644 --- a/builds/android/android_build_helper.sh +++ b/builds/android/android_build_helper.sh @@ -445,6 +445,48 @@ function android_show_configure_opts { echo "" } +function android_clone_library { + local tag="$1" ; shift + local clone_root="$1" ; shift + local clone_url="$1" ; shift + local clone_branch="$1" ; shift + + mkdir -p "$(dirname "${clone_root}")" + if [ -n "${clone_branch}" ] ; then + android_build_trace "Cloning '${clone_url}' (branch '${clone_branch}') under '${clone_root}'." + git clone --quiet --depth 1 -b "${clone_branch}" "${clone_url}" "${clone_root}" + else + android_build_trace "Cloning '${clone_url}' (default branch) under '${clone_root}'." + git clone --quiet --depth 1 "${clone_url}" "${clone_root}" + fi + ( cd "${clone_root}" && git log --oneline -n 1) || exit 1 +} + +# Caller must set CONFIG_OPTS before call. +function android_build_library { + local tag=$1 ; shift + local clone_root=$1 ; shift + + android_build_trace "Cleaning library '${tag}'." + ( + cd "${clone_root}" \ + && ( make clean || : ) && \ + rm -f config.status + ) || exit 1 + + ( + # Remove *.la files as they might cause errors with cross compiled libraries + find "${ANDROID_BUILD_PREFIX}" -name '*.la' -exec rm {} + + + cd "${clone_root}" \ + && ./autogen.sh \ + && android_show_configure_opts "${tag}" "${CONFIG_OPTS[@]}" \ + && ./configure "${CONFIG_OPTS[@]}" \ + && make -j 4 \ + && make install + ) || exit 1 +} + ######################################################################## # Initialization ######################################################################## diff --git a/builds/android/build.sh b/builds/android/build.sh index 4d515264..8f2ce485 100755 --- a/builds/android/build.sh +++ b/builds/android/build.sh @@ -126,13 +126,7 @@ elif [ "${CURVE}" == "libsodium" ]; then (android_build_verify_so "libsodium.so" &> /dev/null) || { if [ ! -d "${LIBSODIUM_ROOT}" ] ; then - android_build_trace "Cloning 'https://github.com/jedisct1/libsodium.git' (branch 'stable') under '${LIBSODIUM_ROOT}'." - mkdir -p "$(dirname "${LIBSODIUM_ROOT}")" - git clone --quiet -b stable --depth 1 https://github.com/jedisct1/libsodium.git "${LIBSODIUM_ROOT}" - ( cd "${LIBSODIUM_ROOT}" && git log --oneline -n 1) || exit 1 - else - android_build_trace "Cleaning LIBSODIUM folder '${LIBSODIUM_ROOT}'." - ( cd "${LIBSODIUM_ROOT}" && (make clean || :) && rm -f config.status ) || exit 1 + android_clone_library "LIBSODIUM" "${LIBSODIUM_ROOT}" "https://github.com/jedisct1/libsodium.git" "stable" fi ( @@ -141,15 +135,7 @@ elif [ "${CURVE}" == "libsodium" ]; then CONFIG_OPTS+=("${ANDROID_BUILD_OPTS[@]}") CONFIG_OPTS+=("--disable-soname-versions") - # Remove *.la files as they might cause errors with cross compiled libraries - find "${ANDROID_BUILD_PREFIX}" -name '*.la' -exec rm {} + - - cd "${LIBSODIUM_ROOT}" \ - && ./autogen.sh \ - && android_show_configure_opts "LIBSODIUM" "${CONFIG_OPTS[@]}" \ - && ./configure "${CONFIG_OPTS[@]}" \ - && make -j 4 \ - && make install + android_build_library "LIBSODIUM" "${LIBSODIUM_ROOT}" ) || exit 1 } elif [ $CURVE == "tweetnacl" ]; then @@ -170,15 +156,7 @@ fi CONFIG_OPTS+=("${CURVE}") CONFIG_OPTS+=("--without-docs") - # Remove *.la files as they might cause errors with cross compiled libraries - find "${ANDROID_BUILD_PREFIX}" -name '*.la' -exec rm {} + - - cd "${LIBZMQ_ROOT}" \ - && ./autogen.sh \ - && android_show_configure_opts "LIBZMQ" "${CONFIG_OPTS[@]}" \ - && ./configure "${CONFIG_OPTS[@]}" \ - && make -j 4 \ - && make install + android_build_library "LIBZMQ" "${LIBZMQ_ROOT}" ) || exit 1 }