forked from EasyRPG/buildscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.sh
More file actions
412 lines (331 loc) · 8.75 KB
/
Copy pathcommon.sh
File metadata and controls
412 lines (331 loc) · 8.75 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/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 $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 --fail -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"
fi
}
# color check
HAVE_COLORS=0
if [ -t 1 ] ; then
HAVE_COLORS=1
fi
function colormsg {
if [ $HAVE_COLORS -eq 1 ]; then
printf "\033[$2$1\033[0m\n"
else
echo "$1"
fi
}
function headermsg {
echo ""
colormsg "$1" "34;1m"
}
function errormsg {
echo ""
colormsg "$1" "31m"
exit 1
}
function msg {
colormsg "$1" "32m"
}
function verbosemsg {
colormsg "$1" "33m"
}
function test_tool {
hash $1 >/dev/null 2>&1
}
function require_tool {
if ! test_tool $1; then
errormsg "The required tool $1 is missing!"
fi
}
ENABLE_CCACHE=0
function test_ccache {
if [ -z ${NO_CCACHE+x} ]; then
if test_tool ccache; then
ENABLE_CCACHE=1
echo "CCACHE enabled"
fi
fi
}
function ccachify_compiler {
if [ $ENABLE_CCACHE -eq 1 ]; then
if [ -n "$CC" ]; then
saved_CC=$CC
export CC="ccache $CC"
fi
if [ -n "$CXX" ]; then
saved_CXX=$CXX
export CXX="ccache $CXX"
fi
fi
}
function unccachify_compiler {
if [ $ENABLE_CCACHE -eq 1 ]; then
[ -n "$saved_CC" ] && export CC=$saved_CC
[ -n "$saved_CXX" ] && export CXX=$saved_CXX
fi
}
function make_meson_cross {
ccachify_compiler
$SCRIPT_DIR/../shared/mk-meson-cross.sh $@
unccachify_compiler
}
function test_dkp {
platform=$1
envvar=${platform^^}
if [ -z "$DEVKITPRO" ] || [ -z "${!envvar}" ]; then
errormsg "Setup ${platform} properly. \$DEVKITPRO and \$${envvar} need to be set."
fi
}
# generic autotools library installer
function install_lib {
headermsg "**** Building ${1%-*} ****"
ccachify_compiler
(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
)
unccachify_compiler
}
# generic cmake library installer
function install_lib_cmake {
headermsg "**** Building ${1%-*} ****"
(cd $1
shift
rm -rf build
# cmake 3.17+, but this only reports unused options on older versions,
# so users unwilling to update cmake will not get ccache acceleration
CMAKE_CCACHE=
if [ $ENABLE_CCACHE -eq 1 ]; then
CMAKE_CCACHE="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
fi
CMAKE_AR=
if [ -n "$AR" ]; then
CMAKE_AR="-DCMAKE_AR=$AR"
fi
CMAKE_NM=
if [ -n "$NM" ]; then
CMAKE_NM="-DCMAKE_NM=$NM"
fi
CMAKE_RANLIB=
if [ -n "$RANLIB" ]; then
CMAKE_RANLIB="-DCMAKE_RANLIB=$RANLIB"
fi
$CMAKE_WRAPPER cmake . -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 $CMAKE_CCACHE \
-DCMAKE_INSTALL_PREFIX=$PLATFORM_PREFIX -DCMAKE_SYSTEM_NAME=$CMAKE_SYSTEM_NAME \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_PREFIX_PATH=$PLATFORM_PREFIX $CMAKE_EXTRA_ARGS $@
cmake --build build --target clean
cmake --build build
cmake --build build --target install
)
}
# generic meson library installer
function install_lib_meson {
headermsg "**** Building ${1%-*} ****"
MESON_CROSS=""
if [ -f "$PLATFORM_PREFIX/meson-cross.txt" ]; then
MESON_CROSS="--cross-file $PLATFORM_PREFIX/meson-cross.txt"
fi
(cd $1
shift
rm -rf build
$MESON_WRAPPER meson setup build --prefix $PLATFORM_PREFIX --buildtype=plain \
-Ddefault_library=static --libdir=lib $MESON_CROSS $@
meson compile -C build
meson install -C build
)
}
function install_lib_liblcf {
if [ "$BUILD_LIBLCF" == "1" ]; then
install_lib_cmake liblcf -DLIBLCF_UPDATE_MIMEDB=OFF -DLIBLCF_ENABLE_TOOLS=OFF -DLIBLCF_ENABLE_TESTS=OFF
fi
}
function install_lib_icu_native {
headermsg "**** Building ICU (native) ****"
# do not use cross environment
unset CC
unset CXX
unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS
# ICU's configure will always check clang and then gcc first. Since they
# are used on many of our platforms, we can accelerate with ccache
if test_tool clang && test_tool clang++; then
export CC=clang
export CXX=clang++
elif test_tool gcc && test_tool g++; then
export CC=gcc
export CXX=g++
fi
if [ $ENABLE_CCACHE -eq 1 ]; then
export CC="ccache $CC"
export CXX="ccache $CXX"
fi
mkdir -p icu-native
(cd icu-native
../icu/source/configure --enable-static --disable-shared $ICU_ARGS
make clean
make
)
# reset
unset CC
unset CXX
}
function install_lib_icu_cross {
headermsg "**** Building ICU (cross) ****"
ICU_CROSS_BUILD=$PWD/icu-native
ccachify_compiler
mkdir -p icu-cross
(cd icu-cross
$CONFIGURE_WRAPPER ../icu/source/configure \
--enable-static --disable-shared --prefix=$PLATFORM_PREFIX \
--host=$TARGET_HOST --with-cross-build=$ICU_CROSS_BUILD \
--disable-tools $ICU_ARGS
make clean
make
make install
)
unccachify_compiler
}
# Use this when crosscompiling but configure assumes we are building native
# (required by emscripten)
function icu_force_data_install {
headermsg "**** Force install ICU data file ****"
# Disable assembly
export PKGDATA_OPTS="-w -v -O $PWD/icu-cross/config/pkgdata.inc"
(cd icu-cross/data
make clean
make
cp ../lib/libicudata.a "$PLATFORM_PREFIX/lib/"
)
}
function patches_common {
_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# png: move cmake configuration, fix using compiler with arguments
if [ -d "$LIBPNG_DIR" ]; then
verbosemsg "libpng"
(cd $LIBPNG_DIR
perl -pi -e 's#DESTINATION lib/libpng#DESTINATION lib/cmake/libpng#' CMakeLists.txt
patch -Np1 < $_SCRIPT_DIR/libpng-custom-cc.patch
)
fi
# disable unsupported compiler flags by clang in libvorbis
if [ -d "$LIBVORBIS_DIR" ]; then
verbosemsg "libvorbis"
perl -pi -e 's/-mno-ieee-fp//' $LIBVORBIS_DIR/configure
# Invalid since macOS Sonoma
perl -pi -e 's/-force_cpusubtype_ALL//' $LIBVORBIS_DIR/configure
fi
# disable libsndfile examples and tests
if [ -d "$LIBSNDFILE_DIR" ]; then
verbosemsg "libsndfile"
(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
verbosemsg "tremor"
(cd $TREMOR_DIR
perl -pi -e 's/XIPH_PATH_OGG.*//' configure.ac
autoreconf -fi
)
fi
# Expat: Disable error when high entropy randomness is unavailable
if [ -d "$EXPAT_DIR" ]; then
verbosemsg "expat"
(cd $EXPAT_DIR
perl -pi -e 's/# error/#warning/' lib/xmlparse.c
)
fi
# nlohmann json: Install pkgconfig/cmake into lib (share is deleted by us)
if [ -d "$NLOHMANNJSON_DIR" ]; then
verbosemsg "nlohmann_json"
(cd $NLOHMANNJSON_DIR
perl -pi -e 's/CMAKE_INSTALL_DATADIR/CMAKE_INSTALL_LIBDIR/' CMakeLists.txt
)
fi
# lhasa: disable binary and tests
if [ -d "$LHASA_DIR" ]; then
verbosemsg "lhasa"
(cd $LHASA_DIR
perl -pi -e 's/ src test//' Makefile.am
autoreconf -fi
)
fi
verbosemsg "ICU"
cp icudt*.dat $ICU_DIR/source/data/in
(cd $ICU_DIR/source
chmod u+x configure
cp config/mh-linux config/mh-unknown
perl -pi -e 's/SMALL_BUFFER_MAX_SIZE 512/SMALL_BUFFER_MAX_SIZE 2048/' tools/toolutil/pkg_genc.h
# Disable icu components not required for encoding
perl -pi -e 's/LIBCPPFLAGS =/LIBCPPFLAGS = -DUCONFIG_ONLY_COLLATION/' config/mh-unknown
)
}
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/ icu-cross/ \
SDL2-*/ SDL3-*/ fmt-*/ FluidLite-*/ fluidsynth-*/ json-*/ inih-*/ \
lhasa-*/ freeimage-* liblcf/
rm -f *.zip *.bz2 *.gz *.xz *.tgz icudt* .patches-applied config.cache meson-cross.txt
rm -rf sbin/ share/
rm -f lib/*.la
}