-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_zlib.sh
executable file
·130 lines (115 loc) · 3.47 KB
/
build_zlib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Compile curl & openssl & zlib for android with NDK.
# Copyright (C) 2018 shishuo <[email protected]>
#
# 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 arm64-v8a)
BASE_PATH=$(
cd "$(dirname $0)"
pwd
)
ZLIB_PATH="$BASE_PATH/zlib"
BUILD_PATH="$BASE_PATH/build"
checkExitCode() {
if [ $1 -ne 0 ]; then
echo "Error building zlib library"
cd $BASE_PATH
exit $1
fi
}
safeMakeDir() {
if [ ! -x "$1" ]; then
mkdir -p "$1"
fi
}
## Android NDK
export NDK_ROOT=/media/tanpan/a393d005-ebe5-42a0-8c6a-c86fdfb185c1/Android/android-ndk-r13b
export ANDROID_NDK_HOME=/media/tanpan/a393d005-ebe5-42a0-8c6a-c86fdfb185c1/Android/android-ndk-r13b
if [ -z "$NDK_ROOT" ]; then
echo "Please set your NDK_ROOT environment variable first"
exit 1
fi
## Clean build directory
rm -rf $BUILD_PATH/zlib
safeMakeDir $BUILD_PATH/zlib
## Build zlib
# backup config
cp $ZLIB_PATH/configure $ZLIB_PATH/configure.bak
checkExitCode $?
compatibleWithAndroid() {
sed 's/case \"$uname\" in/case "_" in/' $ZLIB_PATH/configure >$ZLIB_PATH/configure.temp
mv $ZLIB_PATH/configure.temp $ZLIB_PATH/configure
chmod 755 $ZLIB_PATH/configure
}
# compile $1 ABI $2 SYSROOT $3 TOOLCHAIN $4 TARGET $5 CFLAGS
compile() {
cd $ZLIB_PATH
ABI=$1
SYSROOT=$2
TOOLCHAIN=$3
TARGET=$4
CFLAGS=$5
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export CFLAGS="-I$SYSROOT/usr/include --sysroot=$SYSROOT $CFLAGS"
# zlib configure
export CROSS_PREFIX="$TOOLCHAIN/$TARGET-"
# config
safeMakeDir $BUILD_PATH/zlib/$ABI
compatibleWithAndroid
./configure --prefix=$BUILD_PATH/zlib/$ABI
checkExitCode $?
# clean
make clean
checkExitCode $?
# make
make -j4
checkExitCode $?
# install
make install
checkExitCode $?
cd $BASE_PATH
}
# 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 "$NDK_ROOT/platforms/android-12/arch-arm" "$NDK_ROOT/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 "$NDK_ROOT/platforms/android-12/arch-x86" "$NDK_ROOT/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 "$NDK_ROOT/platforms/android-21/arch-arm64" "$NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/$host-x86_64/bin" "aarch64-linux-android" "-march=armv8-a"
;;
*)
echo "Error APP_ABI"
exit 1
;;
esac
done
# resume config
mv $ZLIB_PATH/configure.bak $ZLIB_PATH/configure
checkExitCode $?
cd $BASE_PATH
exit 0