forked from BellerophonMobile/xmp3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_android.sh
executable file
·315 lines (258 loc) · 7.62 KB
/
build_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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/bin/bash
# build_android.sh - Compiles dependencies for Android
if [ -z "$ANDROID_TOOLCHAIN" -o ! -d "$ANDROID_TOOLCHAIN" ]
then
echo "Please set the ANDROID_TOOLCHAIN environment variable."
echo "See 'docs/STANDALONE-TOOLCHAIN in Android NDK."
exit 1
fi
# Get the directory of where this script is located
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TOP_DIR="$SCRIPT_DIR/android"
# Directory where the dependencies will be built
BUILD_DIR="$TOP_DIR/build"
# Directory where the dependencies will be installed
PREFIX_BASE="$TOP_DIR/prefix"
# Flags to pass to Make
MAKEFLAGS=""
# Version of ARM to compile for, 5 or 7
ARM_VERSION="7"
##############################################
# Shouldn't need to change anything below here
##############################################
TARGETS="util_linux expat openssl libev xmp3"
build_util_linux() {
local base_ver=2.22
local ver=2.22.2
local dir="util-linux-$ver"
local pkg="$dir.tar.xz"
local url="http://www.kernel.org/pub/linux/utils/util-linux/v$base_ver/$pkg"
download_package "$pkg" "$url"
cd "$dir"
./configure --host=arm-linux-androideabi --prefix="$PREFIX" \
--disable-agetty \
--disable-chsh-only-listed \
--disable-cramfs \
--disable-eject \
--disable-fallocate \
--disable-fsck \
--disable-kill \
--disable-libblkid \
--disable-libmount \
--disable-login \
--disable-losetup \
--disable-mount \
--disable-mountpoint \
--disable-nls \
--disable-partx \
--disable-pg-bell \
--disable-pivot_root \
--disable-rename \
--disable-require-password \
--disable-schedutils \
--disable-su \
--disable-sulogin \
--disable-switch_root \
--disable-unshare \
--disable-use-tty-group \
--disable-utmpdump \
--disable-uuidd \
--disable-wall \
--disable-wdctl \
--disable-write \
--disable-shared --without-ncurses
make libuuid.la
install -D .libs/libuuid.a "$PREFIX/lib/libuuid.a"
install -D libuuid/src/uuid.h "$PREFIX/include/uuid/uuid.h"
}
build_expat() {
local ver=2.1.0
local dir="expat-$ver"
local pkg="$dir.tar.gz"
local url="http://downloads.sourceforge.net/project/expat/expat/$ver/$pkg"
download_package "$pkg" "$url"
cd "$dir"
./configure --host=arm-linux-androideabi --prefix="$PREFIX" \
--disable-shared
make
make install
}
build_openssl() {
local ver=1.0.1e
local dir="openssl-$ver"
local pkg="$dir.tar.gz"
local url="http://www.openssl.org/source/$pkg"
download_package "$pkg" "$url"
cd "$dir"
if [ "$ARCH" = "arm" ]
then
./Configure --prefix="$PREFIX" android-armv7
else
./Configure --prefix="$PREFIX" android-x86
fi
# Force -j1 since parallel builds seem totally unreliable
unset MAKEFLAGS
make -j1
make install
}
build_libev() {
local ver=4.15
local dir="libev-$ver"
local pkg="$dir.tar.gz"
local url="http://dist.schmorp.de/libev/$pkg"
download_package "$pkg" "$url"
cd "$dir"
update_autotools .
./configure --host=arm-linux-androideabi --prefix="$PREFIX" \
--disable-shared --enable-static
make CFLAGS="$CFLAGS -DEV_SELECT_USE_FD_SET"
make install
}
build_xmp3() {
cd "$SCRIPT_DIR"
./waf configure build
}
# Simple function to download (if they haven't been already) and extract
# packages if they don't exist.
download_package() {
local pkg="$1"; shift
local url="$1"; shift
pushd "$TOP_DIR"
if [ ! -f "$pkg" ]
then
curl -LO --disable-epsv "$url"
fi
popd
tar -xf "$TOP_DIR/$pkg"
}
# For packages with outdated autotools scripts which don't have Android support
update_autotools() {
local dest="$1"; shift
pushd "$TOP_DIR"
if [ ! -f "config.guess" ]
then
curl -L -o config.guess "http://git.savannah.gnu.org/cgit/automake.git/plain/lib/config.guess?h=maint"
fi
if [ ! -f "config.sub" ]
then
curl -L -o config.sub "http://git.savannah.gnu.org/cgit/automake.git/plain/lib/config.sub?h=maint"
fi
popd
cp "$TOP_DIR/config.guess" "$TOP_DIR/config.sub" "$dest"
}
export_environment() {
ABI=$(ls "$ANDROID_TOOLCHAIN/bin" | grep 'gcc$' | sed 's/-gcc//')
ARCH=$(echo $ABI | awk -F- '{print $1}')
if [ "$ARCH" = "arm" ]
then
PREFIX="$PREFIX_BASE/$ABI-$ARM_VERSION"
else
PREFIX="$PREFIX_BASE/$ABI"
fi
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
LD_LIBRARY_PATH="$PREFIX/lib"
LDFLAGS="-L$PREFIX/lib"
CPPFLAGS="-I$PREFIX/include"
if [ "$ARCH" = "arm" ]
then
CFLAGS+=" -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes"
LDFLAGS+=" -no-canonical-prefixes"
# For thumb release mode
CPPFLAGS+=" -DNDEBUG"
CFLAGS+=" -mthumb -Os -g -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64"
# For arm release mode
#CPPFLAGS+=" -DNDEBUG"
#CFLAGS+=" -O2 -g -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300"
if [ "$ARM_VERSION" = "7" ]
then
CFLAGS+=" -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16"
LDFLAGS+=" -march=armv7-a -Wl,--fix-cortex-a8"
else
CFLAGS+=" -march=armv5te -mtune=xscale -msoft-float"
fi
elif [ "$ARCH" = "mipsel" ]
then
CPPFLAGS+=" -DNDEBUG"
CFLAGS+=" -fpic -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -no-canonical-prefixes -O2 -g -fomit-frame-pointer -funswitch-loops -finline-limit=300"
LDFLAGS+=" -no-canonical-prefixes"
elif [ "$ARCH" = "i686" ]
then
CPPFLAGS+=" -DNDEBUG"
CFLAGS+=" -ffunction-sections -funwind-tables -no-canonical-prefixes -fstack-protector -O2 -g -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300"
LDFLAGS+=" -no-canonical-prefixes"
fi
CXXFLAGS="$CFLAGS"
export PATH="$ANDROID_TOOLCHAIN/bin:$PATH"
export CC="$ABI-gcc"
export CXX="$ABI-g++"
export ARCH
export ABI
export PREFIX
export MAKEFLAGS
export PKG_CONFIG_PATH
export LD_LIBRARY_PATH
export LDFLAGS
export CPPFLAGS
export CFLAGS
export CXXFLAGS
}
build_target() {
export_environment
local targets
if [ "$#" -eq 0 ]
then
targets="$TARGETS"
else
targets="$@"
fi
if [ "$ARCH" = "arm" ]
then
mkdir -p "$BUILD_DIR/$ABI-$ARM_VERSION"
pushd "$BUILD_DIR/$ABI-$ARM_VERSION"
else
mkdir -p "$BUILD_DIR/$ABI"
pushd "$BUILD_DIR/$ABI"
fi
for t in $targets
do
(set -x; eval "build_$t")
done
}
get_help() {
cat << EOF
Usage: $0 [options] [targets...]
Options:
-a <5|7> When building for ARM, which version to build for.
-m "<args>" Quoted flags to pass to make
-j <n> Shortcut to add "-j <n>" to MAKEFLAGS
-h This help output
Targets: $TARGETS
EOF
}
# Exit if any command fails
set -e
while getopts "a:m:j:h" flag
do
case "$flag" in
a)
ARM_VERSION="$OPTARG"
;;
m)
MAKEFLAGS="$OPTARG"
;;
j)
MAKEFLAGS="$MAKEFLAGS -j$OPTARG"
;;
h)
get_help
exit 0
;;
*)
get_help
exit 1
;;
esac
done
# Clear all option flags
shift $(( OPTIND - 1 ))
build_target $@