-
Notifications
You must be signed in to change notification settings - Fork 16
/
common.sh
330 lines (269 loc) · 7.19 KB
/
common.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
function extract {
file=$1
shift
[ $# -ne 0 ] && msg "Extracting $file..."
if [ ${file: -4} == ".zip" ]; then
unzip -q $file $@
else
tar xf $file $@
fi
}
function download {
url=$1
shift
[ $# -ne 0 ] && msg "Downloading $url..."
file=${url##*/}
# Try cache folder first
if [ "x$EASYRPG_PATH_DOWNLOADCACHE" != "x" ]; then
if [ -e $EASYRPG_PATH_DOWNLOADCACHE/$file ]; then
cp -rup $EASYRPG_PATH_DOWNLOADCACHE/$file $file
echo "[copied from cache]"
return
fi
fi
# Fallback to easyrpg.org when <100KB/s for >3s
if [ "x$USE_EASYRPG_MIRROR" == "x1" ] || \
! curl -sSLOR -y3 -Y102400 --connect-timeout 3 $url; then
curl -sSLOR https://easyrpg.org/downloads/sources/$file
fi
[ $? -eq 0 ] && echo "done."
}
function download_and_extract {
url=$1
file=${url##*/}
msg "Downloading and extracting $file..."
download $url
extract $file
}
function git_clone {
url=$1
path=$2
file=${url##*/}
msg "Cloning $file..."
git clone $url $path
}
function download_liblcf {
if [ "$BUILD_LIBLCF" == "1" ]; then
git_clone "https://github.com/easyrpg/liblcf"
(cd liblcf
autoreconf -fi
)
fi
}
function msg {
echo ""
echo "$1"
}
function test_ccache {
if [ -z ${NO_CCACHE+x} ]; then
if hash ccache >/dev/null 2>&1; then
ENABLE_CCACHE=1
echo "CCACHE enabled"
fi
fi
}
# generic autotools library installer
function install_lib {
msg "**** Building ${1%-*} ****"
(cd $1
shift
$CONFIGURE_WRAPPER ./configure --prefix=$PLATFORM_PREFIX --disable-shared --enable-static \
--disable-dependency-tracking --enable-silent-rules \
--host=$TARGET_HOST --cache-file="$PLATFORM_PREFIX/config.cache" $@
make clean
make
make install
)
}
# generic cmake library installer
function install_lib_cmake {
msg "**** Building ${1%-*} ****"
(cd $1
shift
rm -rf build
if [ -n "$AR" ]; then
export CMAKE_AR="-DCMAKE_AR=$AR"
else
CMAKE_AR=
fi
if [ -n "$NM" ]; then
export CMAKE_NM="-DCMAKE_NM=$NM"
else
CMAKE_NM=
fi
if [ -n "$RANLIB" ]; then
export CMAKE_RANLIB="-DCMAKE_RANLIB=$RANLIB"
else
CMAKE_RANLIB=
fi
$CMAKE_WRAPPER cmake . -GNinja -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS $CPPFLAGS" \
-DCMAKE_INSTALL_LIBDIR=lib $CMAKE_AR $CMAKE_NM $CMAKE_RANLIB \
-DCMAKE_INSTALL_PREFIX=$PLATFORM_PREFIX -DCMAKE_SYSTEM_NAME=$CMAKE_SYSTEM_NAME \
-DCMAKE_PREFIX_PATH=$PLATFORM_PREFIX $CMAKE_EXTRA_ARGS $@
cmake --build build --target clean
cmake --build build --target install
)
}
# generic meson library installer
function install_lib_meson {
msg "**** Building ${1%-*} ****"
if [ -f "$PLATFORM_PREFIX/meson-cross.txt" ]; then
MESON_CROSS="$PLATFORM_PREFIX/meson-cross.txt"
else
MESON_CROSS="/dev/null"
fi
(cd $1
shift
rm -rf build
meson setup build --prefix $PLATFORM_PREFIX --buildtype=plain \
-Ddefault_library=static --cross-file $MESON_CROSS $@
meson compile -C build
meson install -C build
)
}
function install_lib_zlib {
msg "**** Building zlib ****"
(cd $ZLIB_DIR
CHOST=$TARGET_HOST $CONFIGURE_WRAPPER ./configure --static --prefix=$PLATFORM_PREFIX
make clean
# only build static library, no tests/examples
make libz.a
make install
)
}
function install_lib_liblcf {
if [ "$BUILD_LIBLCF" == "1" ]; then
install_lib liblcf --disable-update-mimedb --disable-tools
fi
}
function install_lib_icu_native {
msg "**** Building ICU (native) ****"
(cd icu-native/source
unset CC
unset CXX
unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS
chmod u+x configure
./configure --enable-static --enable-shared=no $ICU_ARGS
make
)
}
# Only needed for a mixed endian compile, on other platforms use
# install_lib_icu_native
function install_lib_icu_native_without_assembly {
msg "**** Building ICU (native without ASM) ****"
(cd icu-native/source
unset CC
unset CXX
unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS
chmod u+x configure
CPPFLAGS="-DBUILD_DATA_WITHOUT_ASSEMBLY -DU_DISABLE_OBJ_CODE" ./configure --enable-static --enable-shared=no $ICU_ARGS
make
)
}
function install_lib_icu_cross {
msg "**** Building ICU (cross) ****"
export ICU_CROSS_BUILD=$PWD/icu-native/source
(cd icu/source
cp config/mh-linux config/mh-unknown
chmod u+x configure
$CONFIGURE_WRAPPER ./configure --enable-static --enable-shared=no --prefix=$PLATFORM_PREFIX \
--host=$TARGET_HOST --with-cross-build=$ICU_CROSS_BUILD \
--enable-tools=no $ICU_ARGS
make clean
make
make install
)
}
# Use this when crosscompiling but configure assumes we are building native
# (required by emscripten)
function icu_force_data_install {
msg "**** Force install ICU data file ****"
# Disable assembly
export PKGDATA_OPTS="-w -v -O $PWD/icu/source/config/pkgdata.inc"
(cd icu/source/data
make clean
make
cp ../lib/libicudata.a "$PLATFORM_PREFIX/lib/"
)
}
function patches_common {
_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# disable png utils
(cd $LIBPNG_DIR
perl -pi -e 's/^check_PROGRAMS.*//' Makefile.am
perl -pi -e 's/^bin_PROGRAMS.*//' Makefile.am
autoreconf -fi
)
# disable unsupported compiler flags by clang in libvorbis
if [ -d "$LIBVORBIS_DIR" ]; then
perl -pi -e 's/-mno-ieee-fp//' $LIBVORBIS_DIR/configure
fi
# disable libsndfile examples and tests
if [ -d "$LIBSNDFILE_DIR" ]; then
(cd $LIBSNDFILE_DIR
perl -pi -e 's/ examples tests//' Makefile.am
perl -pi -e 's/ examples regtest tests programs//' Makefile.am
autoreconf -fi
)
fi
# Tremor: Generate configure & Makefile, fix build
if [ -d "$TREMOR_DIR" ]; then
(cd $TREMOR_DIR
perl -pi -e 's/XIPH_PATH_OGG.*//' configure.in
autoreconf -fi
)
fi
# libsamplerate: disable examples
if [ -d "$LIBSAMPLERATE_DIR" ]; then
(cd $LIBSAMPLERATE_DIR
patch -Np1 < $_SCRIPT_DIR/libsamplerate-no-examples.patch
autoreconf -fi
)
fi
# Expat: Disable error when high entropy randomness is unavailable
if [ -d "$EXPAT_DIR" ]; then
(cd $EXPAT_DIR
perl -pi -e 's/# error/#warning/' lib/xmlparse.c
)
fi
# FluidSynth: Shim glib and disable all optional features
if [ -d "$FLUIDSYNTH_DIR" ]; then
(cd $FLUIDSYNTH_DIR
patch -Np1 < $_SCRIPT_DIR/fluidsynth-no-glib.patch
patch -Np1 < $_SCRIPT_DIR/fluidsynth-no-deps.patch
)
fi
# nlohmann json: Install pkgconfig/cmake into lib (share is deleted by us)
if [ -d "$NLOHMANNJSON_DIR" ]; then
(cd $NLOHMANNJSON_DIR
perl -pi -e 's/CMAKE_INSTALL_DATADIR/CMAKE_INSTALL_LIBDIR/' CMakeLists.txt
)
fi
# lhasa: disable binary and tests
(cd $LHASA_DIR
perl -pi -e 's/ src test//' Makefile.am
autoreconf -fi
)
cp icudt*.dat $ICU_DIR/source/data/in
(cd $ICU_DIR/source
chmod u+x configure
perl -pi -e 's/SMALL_BUFFER_MAX_SIZE 512/SMALL_BUFFER_MAX_SIZE 2048/' tools/toolutil/pkg_genc.h
)
}
function cleanup {
rm -rf zlib-*/ libpng-*/ freetype-*/ harfbuzz-*/ pixman-*/ expat-*/ libogg-*/ \
libvorbis-*/ tremor-*/ mpg123-*/ libsndfile-*/ libxmp-lite-*/ speexdsp-*/ \
libsamplerate-*/ wildmidi-*/ opus-*/ opusfile-*/ icu/ icu-native/ \
SDL2-*/ SDL2_image-*/ fmt-*/ FluidLite-*/ fluidsynth-*/ json-*/ inih-*/ \
lhasa-*/ liblcf/
rm -f *.zip *.bz2 *.gz *.xz *.tgz icudt* *.pl .patches-applied config.cache
rm -rf sbin/ share/
}