-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild_aria2.sh
executable file
·166 lines (144 loc) · 4.24 KB
/
build_aria2.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
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
#!/bin/bash -e
LIBS_DIR=$(pwd)/libs
INSTALL_DIR=$(pwd)/bin
mkdir -p $INSTALL_DIR
cd aria2
autoreconf -i
print_help()
{
__text="
Configurable parameters
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\"]
silent - whether the compilation should be less verbose
"
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
# 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"
silent=false
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2- -d=)
case "$KEY" in
"host_tag" ) host_tag="${VALUE}" ;;
"minsdkversion" ) minsdkversion="${VALUE}" ;;
"target_abis" ) target_abis="${VALUE}" ;;
"silent" ) silent="${VALUE}" ;;
*)
echo ""
echo "Unknown '$KEY' parameter"
print_help
exit 1
;;
esac
done
echo ""
echo "-Will use following setting-"
echo "host_tag = $host_tag"
echo "minsdkversion = $minsdkversion"
echo "target_abis = $target_abis"
echo "silent = $silent"
echo ""
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=$INSTALL_DIR/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=$INSTALL_DIR/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=$INSTALL_DIR/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=$INSTALL_DIR/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
configure_params=""
make_params=""
if [ "$silent" == "true" ]
then
make_params="-s V=0"
configure_params="--silent"
fi
LIBS_TARGET_DIR=$LIBS_DIR/$target
./configure \
--host="$host" \
--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
--prefix="$install_dir" \
--disable-nls \
--without-gnutls \
--with-openssl \
--without-sqlite3 \
--without-libxml2 \
--with-libexpat \
--with-libcares \
--with-libz \
--with-libssh2 \
$configure_params \
CXXFLAGS="-Os -g" \
CFLAGS="-Os -g" \
CPPFLAGS="-fPIE" \
LDFLAGS="-fPIE -pie -L$LIBS_TARGET_DIR/lib -static-libstdc++" \
PKG_CONFIG_LIBDIR="$LIBS_TARGET_DIR/lib/pkgconfig" || exit
make $make_params clean || exit
make -j `nproc` $make_params || exit
make install || exit
echo "Done building $target"
done
echo "All done"