Skip to content

Commit e39d2a3

Browse files
authored
Merge pull request leenjewel#3 from davidshen84/master
Fix Android build script
2 parents 8f5d3db + 17e1bb5 commit e39d2a3

File tree

4 files changed

+73
-85
lines changed

4 files changed

+73
-85
lines changed

tools/_shared.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
TOOLS_ROOT=`pwd`
4+
ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64" "android-mips" "android-mips64")
5+
ABIS=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64" "mips" "mips64")
6+
# Default to API 21 for it is the minimum requirement for 64 bit archs.
7+
ANDROID_API=${ANDROID_API:-21}
8+
NDK=${ANDROID_NDK}
9+
310
configure() {
411
ARCH=$1; OUT=$2; CLANG=${3:-""};
512

@@ -48,6 +55,7 @@ configure() {
4855
--stl libc++ \
4956
--install-dir=${TOOLCHAIN_ROOT} \
5057
$NDK_FLAGS
58+
5159
export TOOLCHAIN_PATH=${TOOLCHAIN_ROOT}/bin
5260
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
5361
export SYSROOT=${TOOLCHAIN_ROOT}/sysroot
@@ -68,8 +76,10 @@ configure() {
6876
export LIBS=${LIBS:-""}
6977
export CFLAGS="${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64"
7078
export CXXFLAGS="${CFLAGS} -std=c++11 -frtti -fexceptions"
71-
export LDFLAGS="${ARCH_LINK} ${LDFLAGS:-""}"
79+
export LDFLAGS="${ARCH_LINK}"
7280
echo "**********************************************"
81+
echo "use ANDROID_API=${ANDROID_API}"
82+
echo "use NDK=${NDK}"
7383
echo "export ARCH=${ARCH}"
7484
echo "export NDK_TOOLCHAIN_BASENAME=${NDK_TOOLCHAIN_BASENAME}"
7585
echo "export SYSROOT=${SYSROOT}"

tools/build-curl4android.sh

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,63 @@
1616

1717
set -u
1818

19-
SOURCE="$0"
20-
while [ -h "$SOURCE" ]; do
21-
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
22-
SOURCE="$(readlink "$SOURCE")"
23-
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
24-
done
25-
pwd_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
26-
2719
source ./_shared.sh
2820

2921
# Setup architectures, library name and other vars + cleanup from previous runs
30-
ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64" "android-mips" "android-mips64")
31-
OUTNAME=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64" "mips" "mips64")
32-
TOOLS_ROOT="${pwd_path}"
22+
TOOLS_ROOT=`pwd`
3323
LIB_NAME="curl-7.51.0"
34-
LIB_DEST_DIR=${TOOLS_ROOT}/../output/android
35-
NDK=$ANDROID_NDK_ROOT
36-
ANDROID_PLATFORM="android-23"
37-
ANDROID_API="23"
24+
LIB_DEST_DIR=${TOOLS_ROOT}/libs
3825
[ -f ${LIB_NAME}.tar.gz ] || wget https://curl.haxx.se/download/${LIB_NAME}.tar.gz
3926
# Unarchive library, then configure and make for specified architectures
40-
configure_make()
41-
{
42-
ARCH=$1; OUT=$2;
27+
configure_make() {
28+
ARCH=$1; ABI=$2;
4329
[ -d "${LIB_NAME}" ] && rm -rf "${LIB_NAME}"
4430
tar xfz "${LIB_NAME}.tar.gz"
4531
pushd "${LIB_NAME}";
4632

4733
configure $*
4834
# fix me
49-
cp ${TOOLS_ROOT}/../output/android/openssl-android-${OUT}/lib/libssl.a ${SYSROOT}/usr/lib
50-
cp ${TOOLS_ROOT}/../output/android/openssl-android-${OUT}/lib/libcrypto.a ${SYSROOT}/usr/lib
51-
cp -r ${TOOLS_ROOT}/../output/android/openssl-android-${OUT}/include/openssl ${SYSROOT}/usr/include
35+
cp ${TOOLS_ROOT}/../output/android/openssl-${ABI}/lib/libssl.a ${SYSROOT}/usr/lib
36+
cp ${TOOLS_ROOT}/../output/android/openssl-${ABI}/lib/libcrypto.a ${SYSROOT}/usr/lib
37+
cp -r ${TOOLS_ROOT}/../output/android/openssl-${ABI}/include/openssl ${SYSROOT}/usr/include
5238

53-
PREFIX_DIR=${LIB_DEST_DIR}/curl-android-${OUT}
54-
if [ -d "${PREFIX_DIR}" ]; then
55-
rm -fr ${PREFIX_DIR}
56-
fi
57-
./configure --prefix=${PREFIX_DIR} \
39+
mkdir -p ${LIB_DEST_DIR}/${ABI}
40+
./configure --prefix=${LIB_DEST_DIR}/${ABI} \
5841
--with-sysroot=${SYSROOT} \
5942
--host=${TOOL} \
6043
--with-ssl=/usr \
44+
--enable-ipv6 \
6145
--enable-static \
62-
--disable-shared \
63-
--disable-verbose \
6446
--enable-threaded-resolver \
65-
--enable-ipv6
47+
--disable-dict \
48+
--disable-gopher \
49+
--disable-ldap --disable-ldaps \
50+
--disable-manual \
51+
--disable-pop3 --disable-smtp --disable-imap \
52+
--disable-rtsp \
53+
--disable-shared \
54+
--disable-smb \
55+
--disable-telnet \
56+
--disable-verbose
6657
PATH=$TOOLCHAIN_PATH:$PATH
6758
if make -j4
6859
then
6960
make install
61+
62+
OUTPUT_ROOT=${TOOLS_ROOT}/../output/android/curl-${ABI}
63+
[ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/include
64+
cp -r ${LIB_DEST_DIR}/${ABI}/include/curl ${OUTPUT_ROOT}/include
65+
66+
[ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/lib
67+
cp ${LIB_DEST_DIR}/${ABI}/lib/libcurl.a ${OUTPUT_ROOT}/lib
7068
fi;
7169
popd;
7270
}
7371

7472
for ((i=0; i < ${#ARCHS[@]}; i++))
7573
do
7674
if [[ $# -eq 0 ]] || [[ "$1" == "${ARCHS[i]}" ]]; then
77-
configure_make "${ARCHS[i]}" "${OUTNAME[i]}"
75+
[[ ${ANDROID_API} < 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;
76+
configure_make "${ARCHS[i]}" "${ABIS[i]}"
7877
fi
7978
done

tools/build-openssl4android.sh

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,23 @@
1616

1717
set -u
1818

19-
SOURCE="$0"
20-
while [ -h "$SOURCE" ]; do
21-
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
22-
SOURCE="$(readlink "$SOURCE")"
23-
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
24-
done
25-
pwd_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
26-
2719
source ./_shared.sh
2820

2921
# Setup architectures, library name and other vars + cleanup from previous runs
30-
ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64" "android-mips" "android-mips64")
31-
OUTNAME=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64" "mips" "mips64")
32-
TOOLS_ROOT="${pwd_path}"
3322
LIB_NAME="openssl-1.1.0c"
34-
LIB_DEST_DIR=${TOOLS_ROOT}/../output/android
35-
NDK=$ANDROID_NDK_ROOT
36-
ANDROID_API="23"
23+
LIB_DEST_DIR=${TOOLS_ROOT}/libs
24+
[ -d ${LIB_DEST_DIR} ] && rm -rf ${LIB_DEST_DIR}
3725
[ -f "${LIB_NAME}.tar.gz" ] || wget https://www.openssl.org/source/${LIB_NAME}.tar.gz;
3826
# Unarchive library, then configure and make for specified architectures
3927
configure_make() {
40-
ARCH=$1; OUT=$2;
28+
ARCH=$1; ABI=$2;
4129
rm -rf "${LIB_NAME}"
4230
tar xfz "${LIB_NAME}.tar.gz"
43-
pushd "${LIB_NAME}";
44-
45-
PREFIX_DIR=${LIB_DEST_DIR}/openssl-android-${OUT}
46-
if [ -d "${PREFIX_DIR}" ]; then
47-
rm -fr ${PREFIX_DIR}
48-
fi
31+
pushd "${LIB_NAME}"
4932

5033
configure $*
5134
./Configure $ARCH \
52-
--prefix=${PREFIX_DIR} \
35+
--prefix=${LIB_DEST_DIR}/${ABI} \
5336
--with-zlib-include=$SYSROOT/usr/include \
5437
--with-zlib-lib=$SYSROOT/usr/lib \
5538
zlib \
@@ -58,20 +41,27 @@ configure_make() {
5841
no-unit-test
5942
PATH=$TOOLCHAIN_PATH:$PATH
6043

61-
if make -j4
62-
then
44+
if make -j4; then
6345
make install
64-
# [ -d ${TOOLS_ROOT}/../include/$OUT ] || mkdir -p ${TOOLS_ROOT}/../include/$OUT
65-
# cp -r include/openssl ${TOOLS_ROOT}/../include/$OUT
6646

67-
# [ -d ${TOOLS_ROOT}/../lib/$OUT ] || mkdir -p ${TOOLS_ROOT}/../lib/$OUT
68-
# find . -type f -iname \( 'libssl.a' -or -iname 'libcrypto.a' \) -exec cp {} ${TOOLS_ROOT}/../lib/$OUT \;
47+
OUTPUT_ROOT=${TOOLS_ROOT}/../output/android/openssl-${ABI}
48+
[ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/include
49+
cp -r ${LIB_DEST_DIR}/${ABI}/include/openssl ${OUTPUT_ROOT}/include
50+
51+
[ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/lib
52+
cp ${LIB_DEST_DIR}/${ABI}/lib/libcrypto.a ${OUTPUT_ROOT}/lib
53+
cp ${LIB_DEST_DIR}/${ABI}/lib/libssl.a ${OUTPUT_ROOT}/lib
6954
fi;
55+
popd
56+
7057
}
7158

7259
for ((i=0; i < ${#ARCHS[@]}; i++))
7360
do
7461
if [[ $# -eq 0 ]] || [[ "$1" == "${ARCHS[i]}" ]]; then
75-
configure_make "${ARCHS[i]}" "${OUTNAME[i]}"
62+
# Do not build 64 bit arch if ANDROID_API is less than 21 which is
63+
# the minimum supported API level for 64 bit.
64+
[[ ${ANDROID_API} < 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;
65+
configure_make "${ARCHS[i]}" "${ABIS[i]}"
7666
fi
7767
done

tools/build-protobuf4android.sh

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,30 @@
1616

1717
set -u
1818

19-
SOURCE="$0"
20-
while [ -h "$SOURCE" ]; do
21-
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
22-
SOURCE="$(readlink "$SOURCE")"
23-
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
24-
done
25-
pwd_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
26-
2719
source ./_shared.sh
2820

2921
# Setup architectures, library name and other vars + cleanup from previous runs
30-
ARCHS=("android" "android-armeabi" "android64-aarch64" "android-x86" "android64" "android-mips" "android-mips64")
31-
OUTNAME=("armeabi" "armeabi-v7a" "arm64-v8a" "x86" "x86_64" "mips" "mips64")
32-
TOOLS_ROOT=${pwd_path}
3322
LIB_NAME="protobuf"
3423
LIB_VERSION="3.1.0"
3524
LIB_FILENAME=${LIB_NAME}-${LIB_VERSION}
36-
LIB_DEST_DIR=${TOOLS_ROOT}/../output/android
37-
NDK=$ANDROID_NDK_ROOT
38-
ANDROID_API="23"
25+
LIB_DEST_DIR=${TOOLS_ROOT}/libs
3926
# rm -rf ${LIB_DEST_DIR}
4027
[ -f ${LIB_FILENAME}.tar.gz ] || wget https://github.com/google/${LIB_NAME}/archive/v${LIB_VERSION}.tar.gz -O ${LIB_FILENAME}.tar.gz
4128
# Unarchive library, then configure and make for specified architectures
4229
configure_make() {
43-
ARCH=$1; OUT=$2;
30+
ARCH=$1; ABI=$2;
4431

4532
[ -d ${LIB_FILENAME} ] && rm -rf "${LIB_FILENAME}"
4633
tar xfz "${LIB_FILENAME}.tar.gz"
4734
pushd "${LIB_FILENAME}";
4835

49-
PREFIX_DIR=${LIB_DEST_DIR}/protobuf-android-${OUT}
50-
if [ -d "${PREFIX_DIR}" ]; then
51-
rm -fr ${PREFIX_DIR}
52-
fi
53-
54-
export LDFLAGS="-static-libstdc++"
55-
export LIBS="-lc++_static -latomic"
5636
configure $* "clang"
37+
export LDFLAGS="${LDFLAGS} -static-libstdc++"
38+
export LIBS="${LIBS:-""} -lc++_static -latomic"
5739
# fix CXXFLAGS
5840
export CXXFLAGS=${CXXFLAGS/"-finline-limit=64"/""}
5941
./autogen.sh
60-
./configure --prefix=${PREFIX_DIR} \
42+
./configure --prefix=${LIB_DEST_DIR}/${ABI} \
6143
--with-sysroot=${SYSROOT} \
6244
--with-protoc=`which protoc` \
6345
--with-zlib \
@@ -68,8 +50,14 @@ configure_make() {
6850
PATH=$TOOLCHAIN_PATH:$PATH
6951
if make -j4
7052
then
71-
mkdir -p ${LIB_DEST_DIR}/${OUT}
7253
make install
54+
55+
OUTPUT_ROOT=${TOOLS_ROOT}/../output/android/protobuf-${ABI}
56+
[ -d ${OUTPUT_ROOT}/include ] || mkdir -p ${OUTPUT_ROOT}/include
57+
cp -r ${LIB_DEST_DIR}/$ABI/include/ ${OUTPUT_ROOT}/include
58+
59+
[ -d ${OUTPUT_ROOT}/lib ] || mkdir -p ${OUTPUT_ROOT}/lib
60+
find ${LIB_DEST_DIR}/${ABI}/lib -type f -iname '*.a' -exec cp {} ${OUTPUT_ROOT}/lib \;
7361
fi;
7462
popd;
7563
}
@@ -79,6 +67,7 @@ configure_make() {
7967
for ((i=0; i < ${#ARCHS[@]}; i++))
8068
do
8169
if [[ $# -eq 0 ]] || [[ "$1" == "${ARCHS[i]}" ]]; then
82-
configure_make "${ARCHS[i]}" "${OUTNAME[i]}"
70+
[[ ${ANDROID_API} < 21 ]] && ( echo "${ABIS[i]}" | grep 64 > /dev/null ) && continue;
71+
configure_make "${ARCHS[i]}" "${ABIS[i]}"
8372
fi
8473
done

0 commit comments

Comments
 (0)