2020-05-23 01:59:04 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Configure the following variables according to your needs
|
|
|
|
|
|
|
|
NDK_VERSION="21.1.6352462"
|
|
|
|
OPENSSL_TAG_VERSION="OpenSSL_1_1_1g "
|
2021-08-21 02:30:34 +00:00
|
|
|
CURL_TAG_VERSION="curl-7_78_0"
|
2020-05-23 01:59:04 +00:00
|
|
|
JSONC_TAG_VERSION="master"
|
|
|
|
ANDROID_ARCHS="arm arm64 x86 x86_64"
|
|
|
|
NDK=$HOME/Android/Sdk/ndk/$NDK_VERSION
|
|
|
|
MIN_SDK_VERSION=23 # Can't go any lower unfortunately. See the cURL docs for more info.
|
|
|
|
TARGET_SDK_VERSION=29
|
|
|
|
|
|
|
|
# Edit below at your own risk
|
|
|
|
|
|
|
|
get_abi() {
|
|
|
|
case $1 in
|
|
|
|
"arm")
|
|
|
|
echo -n "armeabi-v7a"
|
|
|
|
;;
|
|
|
|
"arm64")
|
|
|
|
echo -n "arm64-v8a"
|
|
|
|
;;
|
|
|
|
"x86")
|
|
|
|
echo -n "x86"
|
|
|
|
;;
|
|
|
|
"x86_64")
|
|
|
|
echo -n "x86_64"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
make_openssl() {
|
|
|
|
test -d openssl || git clone --branch $OPENSSL_TAG_VERSION https://github.com/openssl/openssl.git
|
|
|
|
for ARCH in $ANDROID_ARCHS; do
|
|
|
|
(
|
|
|
|
export PREFIX="$BUILD_DIR/android/$ARCH"
|
|
|
|
mkdir -p "$PREFIX"
|
|
|
|
cd openssl
|
|
|
|
git checkout $OPENSSL_TAG_VERSION
|
|
|
|
make clean
|
|
|
|
export ANDROID_NDK_HOME=$NDK
|
|
|
|
export ANDROID_NDK_ROOT=$NDK
|
|
|
|
export PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
|
|
|
|
./Configure \
|
|
|
|
--prefix="$PREFIX" \
|
|
|
|
-D__ANDROID_API__=$TARGET_SDK_VERSION \
|
|
|
|
no-shared \
|
|
|
|
android-$ARCH
|
2021-08-21 02:30:34 +00:00
|
|
|
make -j24 install_dev
|
2020-05-23 01:59:04 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
make_curl() {
|
|
|
|
test -d curl || git clone --branch $CURL_TAG_VERSION https://github.com/curl/curl.git
|
|
|
|
for ARCH in $ANDROID_ARCHS; do
|
|
|
|
(
|
|
|
|
export PREFIX="$BUILD_DIR/android/$ARCH"
|
|
|
|
mkdir -p "$PREFIX"
|
|
|
|
cd curl
|
|
|
|
git checkout $CURL_TAG_VERSION
|
2021-08-21 02:30:34 +00:00
|
|
|
test -f configure || autoreconf -fi
|
2020-05-23 01:59:04 +00:00
|
|
|
export HOST_TAG=linux-x86_64
|
|
|
|
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
|
|
|
|
case $ARCH in
|
|
|
|
"arm")
|
|
|
|
export CURL_ARCH="arm-linux-androideabi"
|
|
|
|
export CLANG="armv7a-linux-androideabi"
|
|
|
|
;;
|
|
|
|
"arm64")
|
|
|
|
export CURL_ARCH="aarch64-linux-android"
|
|
|
|
export CLANG=$CURL_ARCH
|
|
|
|
;;
|
|
|
|
"x86")
|
|
|
|
export CURL_ARCH="i686-linux-android"
|
|
|
|
export CLANG=$CURL_ARCH
|
|
|
|
;;
|
|
|
|
"x86_64")
|
|
|
|
export CURL_ARCH="x86_64-linux-android"
|
|
|
|
export CLANG=$CURL_ARCH
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
export AR=$TOOLCHAIN/bin/$CURL_ARCH-ar
|
|
|
|
export AS=$TOOLCHAIN/bin/$CURL_ARCH-as
|
|
|
|
export CC=$TOOLCHAIN/bin/${CLANG}${MIN_SDK_VERSION}-clang
|
|
|
|
export CXX=$TOOLCHAIN/bin/${CLANG}${MIN_SDK_VERSION}-clang++
|
|
|
|
export LD=$TOOLCHAIN/bin/$CURL_ARCH-ld
|
|
|
|
export RANLIB=$TOOLCHAIN/bin/$CURL_ARCH-ranlib
|
|
|
|
export STRIP=$TOOLCHAIN/bin/$CURL_ARCH-strip
|
|
|
|
make clean
|
|
|
|
./configure --prefix="$PREFIX" \
|
|
|
|
--host $CURL_ARCH \
|
|
|
|
--with-pic \
|
|
|
|
--disable-shared \
|
|
|
|
--with-ssl="$PREFIX"
|
2021-08-21 02:30:34 +00:00
|
|
|
make -j24 install
|
2020-05-23 01:59:04 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
make_jsonc() {
|
|
|
|
test -d json-c || git clone --branch $JSONC_TAG_VERSION https://github.com/json-c/json-c.git
|
|
|
|
for ARCH in $ANDROID_ARCHS; do
|
|
|
|
(
|
|
|
|
export PREFIX="$BUILD_DIR/android/$ARCH"
|
|
|
|
mkdir -p "$PREFIX"
|
|
|
|
cd json-c
|
|
|
|
git checkout $JSONC_TAG_VERSION
|
|
|
|
test -d $ARCH && rm -rf $ARCH
|
|
|
|
mkdir $ARCH
|
|
|
|
pushd $ARCH
|
|
|
|
export ABI="$(get_abi $ARCH)"
|
|
|
|
cmake \
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
|
|
|
|
-DANDROID_ABI=$ABI \
|
|
|
|
-DANDROID_NATIVE_API_LEVEL=$MIN_SDK_VERSION \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=$PREFIX \
|
|
|
|
-DBUILD_SHARED_LIBS=OFF \
|
|
|
|
-DBUILD_STATIC_LIBS=ON \
|
|
|
|
..
|
2021-08-21 02:30:34 +00:00
|
|
|
make -j24
|
2020-05-23 01:59:04 +00:00
|
|
|
make install
|
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
make_pihelper() {
|
|
|
|
for ARCH in $ANDROID_ARCHS; do
|
|
|
|
(
|
|
|
|
export PREFIX="$BUILD_DIR/android/$ARCH"
|
|
|
|
mkdir -p "$PREFIX"
|
|
|
|
cd "$BUILD_DIR"
|
|
|
|
test -d $ARCH && rm -rf $ARCH
|
|
|
|
mkdir $ARCH
|
|
|
|
pushd $ARCH
|
|
|
|
cmake \
|
|
|
|
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
|
|
|
|
-DCMAKE_INCLUDE_PATH=$PREFIX/include \
|
|
|
|
-DCMAKE_PREFIX_PATH=$PREFIX \
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
|
|
|
|
-DANDROID_ABI=$ABI \
|
|
|
|
-DANDROID_NATIVE_API_LEVEL=$MIN_SDK_VERSION \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=$PREFIX \
|
|
|
|
-DPIHELPER_SHARED=OFF \
|
|
|
|
-DPIHELPER_STATIC=ON \
|
|
|
|
-DPIHELPER_DEV=ON \
|
|
|
|
../..
|
2021-08-21 02:30:34 +00:00
|
|
|
make -j24
|
2020-05-23 01:59:04 +00:00
|
|
|
make install
|
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
package() {
|
|
|
|
for ARCH in $ANDROID_ARCHS; do
|
|
|
|
(
|
|
|
|
export ABI="$(get_abi $ARCH)"
|
2020-05-26 14:52:09 +00:00
|
|
|
cd $BUILD_DIR/android
|
2020-05-23 01:59:04 +00:00
|
|
|
cp -r $ARCH/include .
|
|
|
|
mv $ARCH/lib/*.a $ARCH/lib/*.la $ARCH/
|
|
|
|
rm -rf $ARCH/{bin,lib,include,share}
|
|
|
|
if [ "$ARCH" != "$ABI" ]; then
|
|
|
|
mv $ARCH $ABI
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
(
|
|
|
|
if [ "$(dirname $0)" == "." ]; then
|
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
test -d deps || mkdir deps
|
|
|
|
export BUILD_DIR="$PWD/build"
|
|
|
|
test -d "$BUILD_DIR" || mkdir -p "$BUILD_DIR"
|
2021-08-21 02:30:34 +00:00
|
|
|
cd deps
|
2020-05-23 01:59:04 +00:00
|
|
|
make_openssl
|
|
|
|
make_curl
|
|
|
|
make_jsonc
|
|
|
|
make_pihelper
|
|
|
|
package
|
|
|
|
)
|
|
|
|
|