-
Notifications
You must be signed in to change notification settings - Fork 13
/
androidbuildlib
executable file
·183 lines (165 loc) · 5.55 KB
/
androidbuildlib
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash -e
print_help()
{
__text="
Configurable parameters
out_path - target installation path to install generated library files for all archs,
it need to be in relative path from the directory executing this script [default is libs]
host_tag - host value that will build the library (hint: you can take a look for this value
at your \$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/ [default is linux-x86_64]
minsdkversion - minimum sdk version to support, this is value of api level [default is 18]
target_abis - target abis to build for, separated by space [default is \"armeabi-v7a x86 arm64-v8a x86_64\"]
configure_params - additional params to pass to ./configure
fresh_build - whether or not this is a fresh build, user might be using this when repeatitively build the same project over and over i.e. while debugging, so there's no need to keep re-execute './configure' and 'make clean' again. [default is true]
no_host - whether ./configure should be called with the --host option [default is false]
silent - whether the compilation should be less verbose [default is false]
custom_silent - custom silent flag/option [default is \"--enable-silent-rules\"]
"
echo "$__text"
}
# print help
if [ "$1" == "--help" ]
then
print_help
exit
fi
# check for existence of configure, and Makefile
if [ ! -e configure ] && { [ ! -e Makefile ] || [ ! -e makefile ]; }
then
echo "Cannot find either configure or Makefile file"
exit 1
fi
out_path=libs
# check system is linux or darwin
if [ "$(uname)" == "Darwin" ]; then
host_tag=darwin-x86_64
else
host_tag=linux-x86_64
fi
minsdkversion=18
target_abis="armeabi-v7a x86 arm64-v8a x86_64"
configure_params=""
fresh_build=true
no_host=false
silent=false
custom_silent="--enable-silent-rules"
# support build zlib use the default value linux when build on macOS.
chost="linux"
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2- -d=)
case "$KEY" in
"no_host" ) no_host="${VALUE}" ;;
"out_path" ) out_path="${VALUE}" ;;
"host_tag" ) host_tag="${VALUE}" ;;
"minsdkversion" ) minsdkversion="${VALUE}" ;;
"target_abis" ) target_abis="${VALUE}" ;;
"configure_params" ) configure_params="${VALUE}" ;;
"fresh_build" ) fresh_build="${VALUE}" ;;
"silent" ) silent="${VALUE}" ;;
"custom_silent" ) custom_silent="${VALUE}" ;;
*)
echo ""
echo "Unknown '$KEY' parameter"
print_help
exit 1
;;
esac
done
echo ""
echo "-Will use following setting-"
echo "output = $out_path"
echo "host_tag = $host_tag"
echo "minsdkversion = $minsdkversion"
echo "target_abis = $target_abis"
echo "configure_params = $configure_params"
echo "fresh_build = $fresh_build"
echo "no_host = $no_host"
echo "silent = $silent"
echo "custom_silent = $custom_silent"
echo "chost = $chost"
echo ""
# check to create installation dir of built library files
if [ ! -d "$out_path" ]
then
mkdir "$out_path"
for dir in $target_abis
do
if [ ! -d "$out_path"/"$dir" ]
then
mkdir "$out_path"/"$dir"
fi
done
fi
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$host_tag
for target in $target_abis
do
if [ $target == "armeabi-v7a" ]
then
echo "prepare for armeabi-v7a"
cc_prefix=armv7a-linux-androideabi$minsdkversion-
support_prefix=arm-linux-androideabi-
host=armv7a-linux-androideabi
install_dir=`pwd`/"$out_path"/armeabi-v7a
CFLAGS="${CFLAGS} -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb"
elif [ $target == "x86" ]
then
echo "prepare for x86"
cc_prefix=i686-linux-android$minsdkversion-
support_prefix=i686-linux-android-
host=i686-linux-android
install_dir=`pwd`/"$out_path"/x86
CFLAGS="${CFLAGS} -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32"
elif [ $target == "arm64-v8a" ]
then
echo "prepare for arm64-v8a"
cc_prefix=aarch64-linux-android$minsdkversion-
support_prefix=aarch64-linux-android-
host=aarch64-linux-android
install_dir=`pwd`/"$out_path"/arm64-v8a
else
echo "prepare for x86_64"
cc_prefix=x86_64-linux-android$minsdkversion-
support_prefix=x86_64-linux-android-
host=x86_64-linux-android
install_dir=`pwd`/"$out_path"/x86_64
CFLAGS="${CFLAGS} -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
fi
echo ""
echo "cc_prefix = $cc_prefix"
echo "support_prefix = $support_prefix"
echo "host = $host"
echo "install_dir = $install_dir"
echo "CFLAGS = $CFLAGS"
echo ""
export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/${cc_prefix}clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/${cc_prefix}clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export CHOST=$chost
# only confiture and make clean when there's no flag telling to ignore
if [ "$fresh_build" == "true" ]
then
VERBOSE_FLAGS=""
if [ "$silent" == "true" ]
then
VERBOSE_FLAGS="-s V=0"
configure_params="$custom_silent $configure_params"
fi
if [ "$no_host" == "true" ]
then
./configure --prefix="$install_dir" $configure_params || exit
else
./configure --host="$host" --prefix="$install_dir" $configure_params || exit
fi
make $VERBOSE_FLAGS clean || exit
fi
make -j4 $VERBOSE_FLAGS || exit
make install || exit
echo "Done building $target"
done
echo "All done"