forked from mpv-android/mpv-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildall.sh
More file actions
executable file
·198 lines (181 loc) · 4.18 KB
/
Copy pathbuildall.sh
File metadata and controls
executable file
·198 lines (181 loc) · 4.18 KB
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
#!/bin/bash -e
cd "$( dirname "${BASH_SOURCE[0]}" )"
. ./include/depinfo.sh
cleanbuild=0
nodeps=0
onlydeps=0
target=mpv-android
arch=armv7l
getdeps () {
varname="dep_${1//-/_}[*]"
echo ${!varname}
}
wasbuilt () {
# don't use associative arrays to support bash 3 on macOS (thanks Tim Apple)
varname="built_${1//-/_}"
return "${!varname:-1}"
}
markbuilt () {
varname="built_${1//-/_}"
declare -g "$varname=0"
}
loadarch () {
unset CC CXX CPATH LIBRARY_PATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
local 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" >&2
exit 1
fi
export prefix_dir="$PWD/prefix/$prefix_name"
export CC=$cc_triple-clang
export CXX=$cc_triple-clang++
export LDFLAGS="-Wl,-O1,--icf=safe -Wl,-z,max-page-size=16384"
export AR=llvm-ar
export RANLIB=llvm-ranlib
}
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
local cpu_family=${ndk_triple%%-*}
[[ "$cpu_family" == "i686" ]] && cpu_family=x86
if ! command -v pkg-config >/dev/null; then
echo "pkg-config is missing!" >&2
return 1
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.tmp" <<CROSSFILE
[built-in options]
buildtype = 'release'
default_library = 'static'
wrap_mode = 'nodownload'
prefix = '/usr/local'
[binaries]
c = '$CC'
cpp = '$CXX'
ar = 'llvm-ar'
nm = 'llvm-nm'
strip = 'llvm-strip'
pkgconfig = 'pkg-config'
pkg-config = 'pkg-config'
[host_machine]
system = 'android'
cpu_family = '$cpu_family'
cpu = '${CC%%-*}'
endian = 'little'
CROSSFILE
# also avoid rewriting it needlessly
if cmp -s "$prefix_dir"/crossfile.{tmp,txt}; then
rm "$prefix_dir/crossfile.tmp"
else
mv "$prefix_dir"/crossfile.{tmp,txt}
fi
}
build () {
if [[ $1 != "mpv-android" && ! -d deps/$1 ]]; then
printf >&2 '\e[1;31m%s\e[m\n' "Target $1 not found"
return 1
fi
wasbuilt "$1" && return 0
if [ $nodeps -eq 0 ]; then
printf >&2 '\e[1;34m%s\e[m\n' "Preparing $1..."
local deps=$(getdeps $1)
echo >&2 "Dependencies: $deps"
for dep in $deps; do
build $dep
done
fi
printf >&2 '\e[1;34m%s\e[m\n' "Building $1..."
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
markbuilt $1
}
usage () {
printf '%s\n' \
"Usage: buildall.sh [options] [target]" \
"Builds the specified target (default: $target)" \
"" \
"-n Do not build dependencies" \
"--only-deps Build only dependencies of the specified target" \
"--clean Clean build dirs before compiling" \
"--arch <arch> Build for specified architecture (default: $arch; supported: armv7l, arm64, x86, x86_64)"
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--clean)
cleanbuild=1
;;
-n|--no-deps)
nodeps=1
;;
--only-deps)
onlydeps=1
;;
--arch)
shift
arch=$1
;;
-h|--help)
usage
;;
-*)
echo "Unknown flag $1" >&2
exit 1
;;
*)
target=$1
;;
esac
shift
done
loadarch $arch
setup_prefix
if [ $onlydeps -eq 1 ]; then
deps=$(getdeps $target)
for dep in $deps; do
build $dep
done
else
build $target
fi
# be helpful and list the output APKs (if they exist)
if wasbuilt "mpv-android"; then
ls -lh ../app/build/outputs/apk/{default,api29}/*/*.apk || :
fi
exit 0