TubeLab-App-Android/frostwire-jlibtorrent/swig/build-utils.shinc

254 lines
8.8 KiB
Bash

#!/usr/bin/env bash
unset_env_variables() {
# The user's build environment might already have pre-set
# flags that can interfere with the compilation process
echo "unset_env_variables()"
unset CPPFLAGS
unset BOOST_LIB_PATH
unset BOOST_ROOT
unset BOOST_LIB_SUFFIX #BOOST_LIB_SUFFIX=-mt
unset OPENSSL_ROOT_DIR
unset OPENSSL_BIN_PATH
unset OPENSSL_INCLUDE_PATH
unset OPENSSL_LIB_PATH
}
unset_env_variables
LIBRARY_VERSION=`cat ../build.gradle | grep "version '" | awk '{ print $2 }' | sed "s/'//g"`
LIBRARY_NAME=jlibtorrent
LIBTORRENT_REVISION=77172672c8db2f6bcef17d867d9a81faae77ec1e # bump version to 1.2.12 (branch:RC_1_2) Jan 7, 2021 correct condition in Jamfile when building against OpenSSL on windows
OPENSSL_VERSION="1.1.1i"
BOOST_VERSION="73"
# TEMP NOTES ON BOOST ISSUES, DEC 13 2020
# Reverting to boost 1.73.
# To build on macOS you need to comment the following line on ${BOOST_ROOT}/tools/build/src/tools/darwin.jam
# 'flags darwin.compile.c++ OPTIONS $(condition) : -fcoalesce-templates ;'
# We might have to do this in Travis CI
# 1.74 seems to require -frtti linking
#In file included from /Users/gubatron/src/libtorrent/src/announce_entry.cpp:34:
#In file included from /Users/gubatron/src/libtorrent/include/libtorrent/announce_entry.hpp:41:
#In file included from /Users/gubatron/src/libtorrent/include/libtorrent/socket.hpp:53:
#In file included from /Users/gubatron/src/boost_1_74_0/boost/asio/ip/tcp.hpp:19:
#In file included from /Users/gubatron/src/boost_1_74_0/boost/asio/basic_socket_acceptor.hpp:19:
#In file included from /Users/gubatron/src/boost_1_74_0/boost/asio/any_io_executor.hpp:22:
#In file included from /Users/gubatron/src/boost_1_74_0/boost/asio/execution.hpp:19:
#/Users/gubatron/src/boost_1_74_0/boost/asio/execution/any_executor.hpp:811:12: error: use of typeid requires -frtti
# return typeid(void);
# 1.75 causes swig to not generate error_code.java and other error handling classes
# With boost 1.75 swig will issue these boost related warnings, something must have changed
# Warning 315: Nothing known about 'boost::system::generic_category'
# 'boost::system::system_category'
BOOST_MAJOR="1"
BOOST_MINOR="0"
SWIG=`pwd`
SRC="${HOME}/src"
BOOST_ROOT="${SRC}/boost_${BOOST_MAJOR}_${BOOST_VERSION}_${BOOST_MINOR}"
LIBTORRENT_ROOT="${SRC}/libtorrent"
OPENSSL_SOURCE="${SRC}/openssl-${OPENSSL_VERSION}"
OPENSSL_ROOT="${SRC}/openssl"
export OPENSSL_NO_OPTS="no-afalgeng no-async no-autoalginit no-autoerrinit no-capieng no-cms no-comp no-deprecated no-dgram no-dso no-dtls no-dynamic-engine no-egd no-engine no-err no-filenames no-gost no-hw no-makedepend no-multiblock no-nextprotoneg no-posix-io no-psk no-rdrand no-sctp no-shared no-sock no-srp no-srtp no-static-engine no-stdio no-threads no-ui-console no-zlib no-zlib-dynamic -fno-strict-aliasing -fvisibility=hidden -Os"
prompt_msg() {
echo
echo "============================================================================="
echo $1
echo "============================================================================="
echo
}
create_folder_if_it_doesnt_exist() {
if [[ ! -d $1 ]]; then mkdir -p $1; fi;
}
abort_if_var_unset() {
var_name=${1}
var_value=${2}
if [[ ! -n ${var_value} ]]; then
prompt_msg "Error ${var_name} not set. Aborting"
exit 1
fi
echo ${var_name} set to ${var_value}
}
check_min_req_vars() {
abort_if_var_unset "LIBTORRENT_REVISION" ${LIBTORRENT_REVISION}
abort_if_var_unset "LIBRARY_VERSION" ${LIBRARY_VERSION}
abort_if_var_unset "LIBRARY_NAME" ${LIBRARY_NAME}
abort_if_var_unset "OPENSSL_VERSION" ${OPENSSL_VERSION}
abort_if_var_unset "BOOST_VERSION" ${BOOST_VERSION}
abort_if_var_unset "BOOST_MAJOR" ${BOOST_MAJOR}
abort_if_var_unset "BOOST_MINOR" ${BOOST_MINOR}
abort_if_var_unset "SWIG" ${SWIG}
abort_if_var_unset "SRC" ${SRC}
abort_if_var_unset "BOOST_ROOT" ${BOOST_ROOT}
abort_if_var_unset "LIBTORRENT_ROOT" ${LIBTORRENT_ROOT}
abort_if_var_unset "OPENSSL_SOURCE" ${OPENSSL_SOURCE}
abort_if_var_unset "OPENSSL_ROOT" ${OPENSSL_ROOT}
abort_if_var_unset "OPENSSL_NO_OPTS" ${OPENSSL_NO_OPTS}
}
prepare_boost() {
echo "***** PREPARE BOOST ******"
abort_if_var_unset "BOOST_ROOT" ${BOOST_ROOT}
abort_if_var_unset "BOOST_VERSION" ${BOOST_VERSION}
abort_if_var_unset "BOOST_MAJOR" ${BOOST_MAJOR}
abort_if_var_unset "BOOST_MINOR" ${BOOST_MINOR}
if ! [ -x "$(command -v wget)" ]; then
echo "Error: wget is not installed."
exit 1
fi
pushd ${SRC}
echo "Checking for ${BOOST_ROOT}..."
if [ ! -d ${BOOST_ROOT} ]; then
prompt_msg "Downloading BOOST ${BOOST_MAJOR}_${BOOST_VERSION}_${BOOST_MINOR}"
wget -4 -O boost.zip https://dl.bintray.com/boostorg/release/${BOOST_MAJOR}.${BOOST_VERSION}.${BOOST_MINOR}/source/boost_${BOOST_MAJOR}_${BOOST_VERSION}_${BOOST_MINOR}.zip
unzip -qq boost.zip
rm -f boost.zip
fi
pushd ${BOOST_ROOT}
pwd
./bootstrap.sh
./b2
./b2 /headers
popd
popd
echo "-------- PREPARE BOOST DONE --------"
}
download_android_ndk() {
abort_if_var_unset "NDK_VERSION" ${NDK_VERSION}
if [ ! -f android-ndk-${NDK_VERSION}.zip ]; then
prompt_msg "download_android_ndk: Downloading android-ndk-${NDK_VERSION}"
wget -4 -O android-ndk-${NDK_VERSION}.zip https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-${host_os}-x86_64.zip;
prompt_msg "download_android_ndk: Extracting NDK...wait";
unzip -qq android-ndk-${NDK_VERSION}.zip;
fi
}
prepare_android_toolchain() {
abort_if_var_unset "SRC" ${SRC}
abort_if_var_unset "NDK_VERSION" ${NDK_VERSION}
abort_if_var_unset "os_arch" ${os_arch}
abort_if_var_unset "android_api" ${android_api}
pushd ${SRC}
host_os="linux"
if [[ "$OSTYPE" == "darwin"* ]]; then
host_os="darwin"
fi
download_android_ndk
export NDK=$PWD/android-ndk-${NDK_VERSION}
prompt_msg "prepare_android_toolchain: NDK=${NDK}"
# Use the prebuilt toolchain path
export ANDROID_TOOLCHAIN=${NDK}/toolchains/llvm/prebuilt/linux-x86_64
echo "ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN}"
popd
}
prepare_openssl() {
echo "***** PREPARE OPENSSL ******"
abort_if_var_unset "SRC" ${SRC}
abort_if_var_unset "OPENSSL_VERSION" ${OPENSSL_VERSION}
abort_if_var_unset "OPENSSL_SOURCE" ${OPENSSL_SOURCE}
if [ ! -d ${OPENSSL_SOURCE} ]; then
prompt_msg "Downloading OPENSSL ${OPENSSL_VERSION} to '{$OPENSSL_SOURCE}'"
pushd ${SRC}
#wget -nv -4 -O openssl.tar.gz https://www.openssl.org/source/openssl-1.1.1i.tar.gz
wget -4 --no-check-certificate -O openssl.tar.gz https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
tar xvfz openssl.tar.gz
rm -f openssl.tar.gz
popd
fi
echo "----- PREPARE OPENSSL DONE -----"
}
build_openssl() {
abort_if_var_unset "OPENSSL_SOURCE" ${OPENSSL_SOURCE}
abort_if_var_unset "run_openssl_configure" ${run_openssl_configure}
prompt_msg "build_openssl: run_openssl_configure=[${run_openssl_configure}]"
if [ -d ${OPENSSL_ROOT} ]; then
rm -fr ${OPENSSL_ROOT}
fi
if [ -d ${OPENSSL_SOURCE} ]; then
pushd ${OPENSSL_SOURCE}
make clean
$run_openssl_configure
make -j 8
make install_sw
popd
fi
}
prepare_libtorrent() {
echo "prepare_libtorrent started..."
abort_if_var_unset "SRC" ${SRC}
abort_if_var_unset "LIBTORRENT_ROOT" ${LIBTORRENT_ROOT}
abort_if_var_unset "LIBTORRENT_REVISION" ${LIBTORRENT_REVISION}
if [ ! -d ${LIBTORRENT_ROOT} ]; then
pushd ${SRC}
git clone https://github.com/arvidn/libtorrent
popd
fi
pushd ${LIBTORRENT_ROOT}
prompt_msg "Checking if you have any uncommited changes"
git status
prompt_msg "Abort with Ctrl-C if there's pending changes above or you will lose them"
git fetch origin RC_1_2
git reset --hard ${LIBTORRENT_REVISION}
git submodule init
git submodule update
make clean
popd
echo "prepare_libtorrent finished."
}
build_libraries() {
abort_if_var_unset "OPENSSL_ROOT" ${OPENSSL_ROOT}
abort_if_var_unset "SWIG" ${SWIG}
abort_if_var_unset "os_build" ${os_build}
abort_if_var_unset "os_arch" ${os_arch}
abort_if_var_unset "SHARED_LIB" ${SHARED_LIB}
abort_if_var_unset "run_bjam" ${run_bjam}
abort_if_var_unset "run_objcopy" ${run_objcopy}
abort_if_var_unset "run_strip" ${run_strip}
abort_if_var_unset "run_readelf" ${run_readelf}
set -x
cd ${SWIG}
export PATH=${PATH}:${BOOST_ROOT}/tools/build/src/engine
echo "Added boost tools to PATH:"
echo ${PATH}
export OPENSSL_ROOT=${OPENSSL_ROOT}
export LIBTORRENT_ROOT=${LIBTORRENT_ROOT}
export BOOST_ROOT=${BOOST_ROOT}
export BOOST_BUILD_PATH=${BOOST_ROOT}
$run_bjam
$run_objcopy
$run_strip
}
cleanup_objects() {
abort_if_var_unset "SWIG" ${SWIG}
# cleanup (when it's finally working, enable this)
if [ -d ${SWIG}/bin ]; then
cd ${SWIG}/bin
find . -type f | egrep -v '.*\.so$|.*\.dll$|.*\.dylib$|.*\.debug$' | xargs rm
find . -empty -type d | xargs rm -r
else
echo ${SWIG}/bin folder not found, nothing to clean
fi
cd ${SWIG}
cd ..
find . -type f | egrep '\d.\d.\d.\d\d.jar$'
cd ${SWIG}
}