forked from mpv-android/mpv-android
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildall.sh
executable file
·153 lines (140 loc) · 3.16 KB
/
buildall.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
#!/bin/bash -e
cd "$( dirname "${BASH_SOURCE[0]}" )"
. ./include/depinfo.sh
cleanbuild=0
nodeps=0
clang=1
target=mpv-android
arch=armv7l
getdeps () {
varname="dep_${1//-/_}[*]"
echo ${!varname}
}
loadarch () {
unset CC CXX CPATH LIBRARY_PATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH
apilvl=21
# ndk_triple: what the toolchain actually is
# cc_triple: what Google pretends the toolchain is
if [ "$1" == "armv7l" ]; then
export ndk_suffix=
export ndk_triple=arm-linux-androideabi
cc_triple=armv7a-linux-androideabi$apilvl
prefix_name=armv7l
elif [ "$1" == "arm64" ]; then
export ndk_suffix=-arm64
export ndk_triple=aarch64-linux-android
cc_triple=$ndk_triple$apilvl
prefix_name=arm64
elif [ "$1" == "x86" ]; then
export ndk_suffix=-x86
export ndk_triple=i686-linux-android
cc_triple=$ndk_triple$apilvl
prefix_name=x86
elif [ "$1" == "x86_64" ]; then
export ndk_suffix=-x64
export ndk_triple=x86_64-linux-android
cc_triple=$ndk_triple$apilvl
prefix_name=x86_64
else
echo "Invalid architecture"
exit 1
fi
export prefix_dir="$PWD/prefix/$prefix_name"
if [ $clang -eq 1 ]; then
export CC=$cc_triple-clang
export CXX=$cc_triple-clang++
else
export CC=$cc_triple-gcc
export CXX=$cc_triple-g++
fi
}
setup_prefix () {
if [ ! -d "$prefix_dir" ]; then
mkdir -p "$prefix_dir"
# enforce flat structure (/usr/local -> /)
ln -s . "$prefix_dir/usr"
ln -s . "$prefix_dir/local"
fi
# meson wants to be spoonfed this file, so create it ahead of time
# also define: release build, static libs and no source downloads at runtime(!!!)
cat >"$prefix_dir/crossfile.txt" <<CROSSFILE
[built-in options]
buildtype = 'release'
default_library = 'static'
wrap_mode = 'nodownload'
[binaries]
c = '$CC'
cpp = '$CXX'
ar = 'llvm-ar'
strip = '$ndk_triple-strip'
pkgconfig = 'pkg-config'
[host_machine]
system = 'android'
cpu_family = '${ndk_triple%%-*}'
cpu = '${CC%%-*}'
endian = 'little'
CROSSFILE
}
build () {
if [ $1 != "mpv-android" ] && [ ! -d deps/$1 ]; then
echo >&2 -e "\033[1;31mTarget $1 not found\033[m"
return 1
fi
echo >&2 -e "\033[1;34mBuilding $1...\033[m"
if [ $nodeps -eq 0 ]; then
deps=$(getdeps $1)
echo >&2 "Dependencies: $deps"
for dep in $deps; do
build $dep
done
fi
if [ "$1" == "mpv-android" ]; then
pushd ..
BUILDSCRIPT=buildscripts/scripts/$1.sh
else
pushd deps/$1
BUILDSCRIPT=../../scripts/$1.sh
fi
[ $cleanbuild -eq 1 ] && $BUILDSCRIPT clean
$BUILDSCRIPT build
popd
}
usage () {
echo "Usage: buildall.sh [options] [target]"
echo "Builds the specified target (default: $target)"
echo "--clean Clean build dirs before compiling"
echo "--no-deps Do not build dependencies"
echo "--gcc Use gcc compiler (not officially supported!)"
echo "--arch <arch> Build for specified architecture (default: $arch; supported: armv7l, arm64, x86_64)"
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--clean)
cleanbuild=1
;;
--no-deps)
nodeps=1
;;
--gcc)
clang=0
;;
--arch)
shift
arch=$1
;;
-h|--help)
usage
;;
*)
target=$1
;;
esac
shift
done
loadarch $arch
setup_prefix
build $target
[ "$target" == "mpv-android" ] && \
ls -lh ../app/build/outputs/apk/{debug,release}/*.apk
exit 0