-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_for_android.sh
executable file
·202 lines (162 loc) · 4.62 KB
/
build_for_android.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/sh
# directories
SOURCE="transmission-2.84"
CURL_SOURCE="curl-7.40.0"
LIBEVENT_SOURCE="libevent-2.0.21-stable"
OPENSSL_SOURCE="openssl-1.0.1l"
FAT="TS-Android"
SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"
NDK="/opt/google/android-ndk-r9"
SYSROOT_PREFIX="$NDK/platforms/android-14/arch-"
CONFIGURE_FLAGS="--enable-largefile --enable-utp --enable-lightweight --build=x86_64-unknown-linux-gnu"
ARCHS="arm"
COMPILE="y"
#LIPO="y"
DEPLOYMENT_TARGET="6.0"
build_openssl() {
ARCH=$1
PLATFROM=$2
if [ $ARCH = "arm64" ]
then
ACT_ARCH="aarch64"
else
ACT_ARCH=$ARCH
fi
if [ -z $PLATFROM ]
then
PLATFROM=linux-androideabi
fi
SYSROOT=${SYSROOT_PREFIX}${ARCH}
export CC="$NDK/toolchains/${ACT_ARCH}-${PLATFROM}-4.6/prebuilt/linux-x86_64/bin/${ACT_ARCH}-${PLATFROM}-gcc --sysroot=${SYSROOT}"
CWD=`pwd`
echo "building openssl for $ARCH..."
#mkdir -p "$SCRATCH/$ARCH"
cd "$CWD/$OPENSSL_SOURCE"
export CFLGAS="-I$SYSROOT/usr/include -I$CWD/$OPENSSL_SOURCE"
export LDFLAGS="-L$SYSROOT/usr/lib"
$CWD/$OPENSSL_SOURCE/Configure android \
--prefix=$THIN/$ARCH #\
# --cross-compile-prefix=${ACT_ARCH}-${PLATFROM}
make -j4 install
}
#build_openssl "arm"
#exit 1
build_libevent() {
ARCH="$1"
PLATFROM="$2"
if [ -z $PLATFROM ]
then
PLATFROM="linux-androideabi"
fi
if [ $ARCH = "arm64" ]
then
PLATFROM="linux-android"
ACT_ARCH="aarch64"
else
ACT_ARCH=$ARCH
fi
SYSROOT=${SYSROOT_PREFIX}${ARCH}
CC="$NDK/toolchains/${ACT_ARCH}-${PLATFROM}-4.6/prebuilt/linux-x86_64/bin/${ACT_ARCH}-${PLATFROM}-gcc --sysroot=${SYSROOT}"
export CC="$CC"
CWD=`pwd`
echo "building curl for $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH-libevent"
CFLAGS="-I${SYSROOT_PREFIX}${ARCH}/usr/include"
export CFLAGS="$CFLAGS"
$CWD/$LIBEVENT_SOURCE/configure --host=$ACT_ARCH-$PLATFROM \
--prefix=$THIN/$ARCH
make -j4 install
}
#build_libevent "arm"
build_Curl() {
ARCH="$1"
PLATFROM="$2"
if [ -z $PLATFROM ]
then
PLATFROM="linux-androideabi"
fi
if [ $ARCH = "arm64" ]
then
PLATFROM="linux-android"
ACT_ARCH="aarch64"
else
ACT_ARCH=$ARCH
fi
SYSROOT=${SYSROOT_PREFIX}${ARCH}
CC="$NDK/toolchains/${ACT_ARCH}-${PLATFROM}-4.6/prebuilt/linux-x86_64/bin/${ACT_ARCH}-${PLATFROM}-gcc --sysroot=${SYSROOT}"
export CC="$CC"
CWD=`pwd`
echo "building curl for $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH-curl"
CFLAGS="-I${SYSROOT_PREFIX}${ARCH}/usr/include"
export CFLAGS="$CFLAGS -Din_addr_t=uint32_t"
$CWD/$CURL_SOURCE/configure --host=$ACT_ARCH-$PLATFROM \
--with-ssl \
--prefix=$THIN/$ARCH
make -j4 install
}
#build_Curl "arm"
NEED_RECONFIGURE=no
if [ "$COMPILE" ]
then
CWD=`pwd`
for ARCH in $ARCHS
do
ACT_ARCH=$ARCH
PLATFROM="linux-androideabi"
if [ $ARCH = "arm64" ]
then
ACT_ARCH="aarch64"
PLATFROM="linux-android"
fi
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-I${SYSROOT_PREFIX}${ARCH}/usr/include -I${THIN}/$ARCH/include"
export LIBCURL_CFLAGS="-I${THIN}/$ARCH/include"
export LIBCURL_LIBS="-L${THIN}/$ARCH/lib"
export LIBEVENT_CFLAGS="-I${THIN}/$ARCH/include"
export LIBEVENT_LIBS="-L${THIN}/$ARCH/lib"
export LIBS="-lcrypto -levent -lssl -lcurl"
export PATH=$PATH:"$NDK/toolchains/${ACT_ARCH}-${PLATFROM}-4.6/prebuilt/linux-x86_64/bin/"
SYSROOT=${SYSROOT_PREFIX}${ARCH}
CC="$NDK/toolchains/${ACT_ARCH}-${PLATFROM}-4.6/prebuilt/linux-x86_64/bin/${ACT_ARCH}-${PLATFROM}-gcc --sysroot=${SYSROOT}"
export CC="${CC}"
CXXFLAGS="$CFLAGS"
LDFLAGS="-L${SYSROOT_PREFIX}${ARCH}/usr/lib -L${THIN}/$ARCH/lib"
export CFLAGS="$CFLAGS -Din_addr_t=uint32_t -D__android__ -Din_port_t=uint16_t"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="$LDFLAGS"
if [ $NEED_RECONFIGURE = "yes" ]
then
$CWD/$SOURCE/configure \
$CONFIGURE_FLAGS \
--host=arm-linux-androideabi \
--prefix=$THIN/$ARCH || exit 1;
fi
make clean;
make -j4; make install || exit 1
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi
echo Done