Created
November 7, 2019 08:10
-
-
Save LinArcX/1c8529946c6317da8153805dac519ac8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Compile curl for android with NDK. | |
# Copyright (C) 2019 linarcx <linarcx@gmail.com> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <https://www.gnu.org/licenses/>. | |
APP_ABI=(armeabi-v7a x86 arm64-v8a) | |
BASE_PATH=$(pwd) | |
BUILD_PATH="$BASE_PATH/build" | |
## Android NDK | |
export ANDROID_NDK_HOME="$ANDROID_NDK_HOME" | |
if [ -z "$ANDROID_NDK_HOME" ]; then | |
echo "Please set your ANDROID_NDK_HOME environment variable first" | |
exit 1 | |
fi | |
safeMakeDir() { | |
if [ ! -x "$1" ]; then | |
mkdir -p "$1" | |
fi | |
} | |
# compile $1 ABI $2 SYSROOT $3 TOOLCHAIN $4 TARGET $5 CFLAGS | |
compile() { | |
ABI=$1 | |
SYSROOT=$2 | |
TOOLCHAIN=$3 | |
TARGET=$4 | |
CFLAGS=$5 | |
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html | |
export SYSROOT="$SYSROOT" | |
export CFLAGS="$CFLAGS --sysroot=$SYSROOT" | |
export CPPFLAGS="-I$SYSROOT/usr/include --sysroot=$SYSROOT" | |
export CC="$TOOLCHAIN/$TARGET-gcc" | |
export CPP="$TOOLCHAIN/$TARGET-cpp" | |
export CXX="$TOOLCHAIN/$TARGET-g++" | |
export LD="$TOOLCHAIN/$TARGET-ld" | |
export AS="$TOOLCHAIN/$TARGET-as" | |
export AR="$TOOLCHAIN/$TARGET-ar" | |
export NM="$TOOLCHAIN/$TARGET-nm" | |
export STRIP="$TOOLCHAIN/$TARGET-strip" | |
export RANLIB="$TOOLCHAIN/$TARGET-ranlib" | |
# config | |
./buildconf | |
safeMakeDir $BUILD_PATH/curl/$ABI | |
# https://stackoverflow.com/questions/12636536/install-curl-with-openssl | |
./configure --host=$TARGET \ | |
--prefix=$BUILD_PATH/curl/$ABI \ | |
--enable-static \ | |
--enable-shared \ | |
--disable-verbose \ | |
--enable-threaded-resolver \ | |
--enable-libgcc \ | |
--enable-ipv6 | |
} | |
# check system | |
host=$(uname | tr 'A-Z' 'a-z') | |
if [ $host = "darwin" ] || [ $host = "linux" ]; then | |
echo "system: $host" | |
else | |
echo "unsupport system, only support Mac OS X and Linux now." | |
exit 1 | |
fi | |
for abi in ${APP_ABI[*]}; do | |
case $abi in | |
armeabi-v7a) | |
# https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#ARM-Options | |
compile $abi "$ANDROID_NDK_HOME/platforms/android-21/arch-arm" "$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/$host-x86_64/bin" "arm-linux-androideabi" "-march=armv7-a -mfloat-abi=softfp -mfpu=neon" | |
;; | |
x86) | |
# http://gcc.gnu.org/onlinedocs/gcc/x86-Options.html | |
compile $abi "$ANDROID_NDK_HOME/platforms/android-21/arch-x86" "$ANDROID_NDK_HOME/toolchains/x86-4.9/prebuilt/$host-x86_64/bin" "i686-linux-android" "-march=i686" | |
;; | |
arm64-v8a) | |
# https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#AArch64-Options | |
compile $abi "$ANDROID_NDK_HOME/platforms/android-21/arch-arm64" "$ANDROID_NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/$host-x86_64/bin" "aarch64-linux-android" "-march=armv8-a" | |
;; | |
*) | |
echo "Error APP_ABI" | |
;; | |
esac | |
done | |
echo "== build success ==" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment