forked from mpv-android/mpv-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildall.sh
executable file
·166 lines (152 loc) · 3.51 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
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/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
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"
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
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
# 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'
[binaries]
c = '$CC'
cpp = '$CXX'
ar = 'llvm-ar'
strip = 'llvm-strip'
pkgconfig = '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
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
}
usage () {
printf '%s\n' \
"Usage: buildall.sh [options] [target]" \
"Builds the specified target (default: $target)" \
"-n Do not build dependencies" \
"--clean Clean build dirs before compiling" \
"--gcc Use gcc compiler (unsupported!)" \
"--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
;;
--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/{default,api29}/*/*.apk
exit 0