forked from visualboyadvance-m/visualboyadvance-m
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installdeps
executable file
·1294 lines (1036 loc) · 38.7 KB
/
installdeps
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
CMAKE=cmake
ENABLE_OPENAL=1
ENABLE_FFMPEG=1
main() {
cd "$(dirname $0)"
check_command_line_args "$@"
mktmp
check_os
${os}_installdeps
quit 0
}
check_command_line_args() {
while [ $# -gt 0 ]; do
case "$1" in
-h|--help|--usage)
usage
quit 0
;;
--no-openal)
ENABLE_OPENAL=
shift
;;
--no-ffmpeg)
ENABLE_FFMPEG=
shift
;;
*)
target=$1
break
;;
esac
done
if [ $# -gt 1 ]; then
usage
quit 1
fi
}
check_os() {
case "$(uname -s)" in
Linux)
os=linux
;;
Darwin)
os=mac
;;
FreeBSD)
os=freebsd
;;
MINGW*|MSYS*)
os=windows
;;
*)
error "Don't know how to install deps on your OS"
;;
esac
}
mktmp() {
tmp="/tmp/installdeps_$$"
mkdir "$tmp" || quit 1
chmod 700 "$tmp" 2>/dev/null
trap "quit 1" PIPE HUP INT QUIT ILL TRAP KILL BUS TERM
}
quit() {
[ -n "$tmp" ] && rm -rf "$tmp" 2>/dev/null
exit ${1:-0}
}
usage() {
cat <<'EOF'
Usage: [32m./installdeps [1;35m[TARGET][0m
Try to install the dependencies needed for this project appropriately on the host OS.
This program may require [1;35msudo[0m.
A cross-compile target may be specified as the only parameter, of either [1;35mm32[0m which targets the host in 32 bit mode (e.g. x86 on an amd64 host) or [1;35mwin32[0m, [1;35mMinGW-w64-i686[0m or [1;35mMinGW-w64-x86_64[0m. [1;35mwin32[0m is an alias for [1;35mMinGW-w64-i686[0m to target Windows via MinGW. Cross compiling for Windows is only supported on Debian/Ubuntu, Fedora, Arch Linux and MSYS2.
On MSYS2 the [1;35mMinGW-w64-clang-x86_64[0m target for CLANG64 and the [1;35mMinGW-w64-clang-i686[0m target for CLANG32 are also supported, as well as [1;35mMinGW-w64-ucrt-x86_64[0m for UCRT64.
On MSYS2 dependencies are installed for 32 or 64 bit native Windows targets based on which shell you started (the value of $MSYSTEM) unless you specify one or the other. You can specify a cross target of [1;35mm32[0m or [1;35mm64[0m as aliases for the 32 bit or 64 bit MinGW gcc targets respectively. MSYS2 POSIX layer builds are not supported.
[1m-h, --help, --usage[0m Show this help screen and exit.
[1m--no-openal[0m Do not install OpenAL dependencies.
[1m--no-ffmpeg[0m Do not install ffmpeg dependencies.
Examples:
[32m./installdeps[0m # install dependencies for a host build
[32m./installdeps [1;35mm32[0m # make a 32 bit binary for the host OS
[32m./installdeps [1;35mwin32[0m # cross-compile for 32 bit windows (Debian/Ubuntu, Arch Linux or MSYS2)
[32m./installdeps [1;35mMinGW-w64-i686[0m # likewise
[32m./installdeps [1;35mwin64[0m # cross-compile for 64 bit windows (Debian/Ubuntu, Arch Linux or MSYS2)
[32m./installdeps [1;35mMinGW-w64-x86_64[0m # likewise
EOF
}
error() {
printf '\n[31mERROR[0m: %s.\n\n' "$1" >&2
[ -z "$2" ] && quit 1
}
warning() {
[ -z "$1" ] && return 0
printf '\n[35mWARNING[0m: %s.\n\n' "$1" >&2
}
info_msg() {
[ -z "$1" ] && return 0
printf '\n[32mINFO[0m: %s.\n\n' "$1" >&2
}
installing() {
echo '[32mInstalling deps...[0m'
echo
}
check() {
"$@"
if [ $? -ne 0 ]; then
error 'command failed' NOQUIT
echo 'The failing command was:'
echo "$@"
quit 1
fi
}
countdown() {
secs=$1
echo
while [ "$secs" -ne 0 ]; do
printf '%s\r' "Starting in $secs seconds..."
sleep 1
secs=$((secs-1))
done
printf '\n\n'
}
linux_installdeps() {
# detect host architecture
case "$(uname -a)" in
*x86_64*)
amd64=1
;;
*i686*)
i686=1
;;
esac
if [ -f /etc/debian_version ]; then
debian_installdeps
elif [ -f /etc/fedora-release ]; then
fedora_installdeps
elif [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]; then
rhel_installdeps
elif [ -f /etc/solus-release ]; then
solus_installdeps
elif [ -f /etc/gentoo-release ]; then
gentoo_installdeps
elif [ -x /usr/bin/pacman ]; then
archlinux_installdeps
elif [ -f /etc/os-release ]; then
case "$(. /etc/os-release; echo "${ID_LIKE:-$ID}")" in
*suse*)
suse_installdeps
;;
nixos)
nixos_installdeps
;;
alpine)
alpine_installdeps
;;
*)
error "Don't know how to install deps on your version of Linux"
;;
esac
else
error "Don't know how to install deps on your version of Linux"
fi
}
freebsd_installdeps() {
installing
check sudo pkg update
pkgs="llvm-devel cmake ccache nasm ffmpeg gettext-tools gettext pkgconf sdl2 sfml wx31-gtk3 iconv zip ninja"
[ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg"
# currently the wx30 and wx31 packages produce GTK errors on CURRENT (as of 04/2019)
check sudo pkg install -y $pkgs
build_instructions
}
# the -j flag for make parameter, empty if 1
jobs_flag() {
if [ $(num_cpus) -gt 1 ]; then
echo "-j$(num_cpus)"
fi
}
# number of CPUs to use for jobs, 1 less than total to not overload resources
num_cpus() {
if [ -n "$_num_cpus" ]; then
if [ $((_num_cpus - 1)) -lt 1 ]; then
echo 1
else
echo $((_num_cpus - 1))
fi
return 0
fi
# determine number of CPUs and cache it
if command -v nproc >/dev/null; then
_num_cpus=$(nproc)
elif [ $os = linux -o $os = windows ]; then
_num_cpus=$(grep '^processor *:' /proc/cpuinfo | wc -l)
elif [ $os = mac ] || [ $os = freebsd ]; then
_num_cpus=$(sysctl -n hw.ncpu)
fi
[ -z "$_num_cpus" ] && _num_cpus=1
num_cpus
}
check_cross() {
target=$(echo "$target" | tr 'A-Z' 'a-z')
if [ -z "$target" ]; then
if [ -n "$msys2" ]; then
case "$MSYSTEM" in
MINGW32)
target='mingw-w64-i686'
;;
MINGW64)
target='mingw-w64-x86_64'
;;
CLANG32)
target='mingw-w64-clang-i686'
;;
CLANG64)
target='mingw-w64-clang-x86_64'
;;
UCRT64)
target='mingw-w64-ucrt-x86_64'
;;
MSYS)
error 'host builds in MSYS mode are not supported, supply a target or start a MINGW shell'
;;
*)
error 'unknown value for $MSYSTEM: '"$MSYSTEM"' '
;;
esac
else
return
fi
fi
case "$target" in
win32|win64|mingw*)
if [ -z "$arch_linux" -a -z "$msys2" -a -z "$debian" -a -z "$fedora" ]; then
error 'win32 cross compiling targets are only supported on Debian/Ubuntu, Fedora, Arch and MSYS2 at the moment'
fi
case "$target" in
win32)
target='mingw-w64-i686'
;;
win64)
target='mingw-w64-x86_64'
;;
mingw-w64-x86_64|mingw-w64-i686|mingw-w64-clang-x86_64|mingw-w64-ucrt-x86_64|mingw-w64-clang-i686)
;;
*)
error "target must be one of 'm32', 'win32', 'win64', or one of the MinGW/clang/ucrt targets supported by MSYS2: mingw-w64-[clang|ucrt]-(x86_64|i686)."
;;
esac
;;
m32|-m32)
target=m32
if [ -z "$msys2" -a -z "$fedora" -a -z "$arch_linux" -a -z "$solus" -a -z "$suse" ]; then
error '32 bit builds are only supported on Fedora, OpenSUSE, Arch, Solus and MSYS2 at the moment'
fi
if [ -n "$msys2" ]; then
target='mingw-w64-i686'
else
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake"
fi
;;
m64)
if [ -z "$msys2" ]; then
error '64 bit cross target only supported on MSYS2 at the moment'
fi
target='mingw-w64-x86_64'
;;
*)
error "unknown cross target: '$target' "
;;
esac
}
debian_installdeps() {
debian=1
check_cross
installing
if [ -z "$target" ]; then
sudo apt-get -qq -y update
sfml_libs=
for lib in graphics window network; do
sfml_libs="$sfml_libs $(apt-cache search "libsfml-$lib" | sed 's/ - .*//' | sort -r | head -1)"
done
glew_lib=$(apt-cache search libglew | grep '^libglew[0-9]' | sed 's/ - .*//' | sort -r | head -1)
sdl_lib=$(apt-cache search '^libsdl2-2.0' | sed 's/ - .*//' | sort -r | head -1)
# not present in trusty
if [ -n "$ENABLE_FFMPEG" ]; then
libswresample_dev=$(apt-cache search libswresample-dev | awk '{print $1}')
fi
wx_libs=$(apt-cache search 'libwxgtk[0-9]' | sed 's/ - .*//')
# Use -gtk3 variant on older distros.
case "$wx_libs" in
*-gtk3*)
new_wx_libs=
for pkg in $wx_libs; do
case "$pkg" in
*-gtk3*)
new_wx_libs="$new_wx_libs $pkg"
;;
esac
done
wx_libs=$new_wx_libs
;;
esac
pkgs="build-essential g++ nasm cmake ccache gettext zlib1g-dev libgl1-mesa-dev libgettextpo-dev libsdl2-dev $sdl_lib libglu1-mesa-dev libglu1-mesa libgles2-mesa-dev libsfml-dev $sfml_libs $glew_lib $wx_libs libgtk2.0-dev libgtk-3-dev ccache zip ninja-build"
[ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs libopenal-dev"
[ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs libavcodec-dev libavformat-dev libswscale-dev libavutil-dev $libswresample_dev"
check sudo apt-get -qy install $pkgs
else
case "$target" in
mingw-w64-i686)
target='i686-w64-mingw32.static'
CMAKE="/usr/lib/mxe/usr/bin/i686-w64-mingw32.static-cmake"
;;
mingw-w64-x86_64)
target='x86-64-w64-mingw32.static'
CMAKE="/usr/lib/mxe/usr/bin/x86_64-w64-mingw32.static-cmake"
;;
*)
error "unknown cross target (you shouldn't see this)"
;;
esac
pre_build='export PATH="$PATH:/usr/lib/mxe/usr/bin"'
debian_rel=$(lsb_release -a 2>/dev/null | sed -En 's/^Codename:[[:space:]]*//p')
case "$debian_rel" in
bionic|stretch|trusty|xenial)
;;
yakkety|zesty|artful)
debian_rel=xenial
;;
utopic|vivid|wily)
debian_rel=trusty
;;
*)
debian_rel=bionic
;;
esac
mxe_apt_sources=/etc/apt/sources.list.d/mxeapt.list
sudo apt-get -qq -y update
if [ -z "$(apt-cache search '^mxe-source$')" ]; then
if [ ! -f "$mxe_apt_sources" ]; then
echo "deb http://pkg.mxe.cc/repos/apt $debian_rel main" | sudo -- sh -c "cat > $mxe_apt_sources"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C6BF758A33A3A276 || :
else
error "$mxe_apt_sources exists but mxe packages are not found in apt, either delete it or fix it"
fi
fi
deps="gcc zlib ffmpeg gettext sdl2 sfml openal wxwidgets"
[ -n "$ENABLE_OPENAL" ] && deps="$deps openal"
[ -n "$ENABLE_FFMPEG" ] && deps="$deps ffmpeg"
set --
for dep in $deps; do
set -- "$@" "mxe-${target}-$dep"
done
check sudo apt-get --allow-unauthenticated -qq -y update
# Native wx-common needed for wxrc executable.
check sudo apt-get --allow-unauthenticated -qy install build-essential cmake ninja-build ccache wx-common git "$@"
# The ccache symlink is broken in some versions of these mxe packages.
ccache_link=/usr/lib/mxe/.ccache/bin/ccache
if [ ! -e "$ccache_link" ]; then
sudo mkdir -p ${ccache_link%/*}
sudo ln -sf /usr/bin/ccache "$ccache_link"
fi
# get the necessary win32 headers
git submodule update --init --remote --recursive
fi
build_instructions
}
fedora_installdeps() {
fedora=1
ffmpeg=ffmpeg-devel
rpms_installed=
check_cross
installing
warning=
if [ -n "$ENABLE_FFMPEG" ]; then
# using --nogpgcheck with dnf because keys can be a problem on rawhide
fedora_release=$(rpm -E %fedora)
tries=3
curdir=$(pwd)
# make sure rpmfusion is installed for ffmpeg
while [ $tries -gt 0 ]; do
mkdir -p "${tmp}/fusion"
cd "${tmp}/fusion"
if ! curl -fLO https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-${fedora_release}.noarch.rpm; then
fedora_release=$((fedora_release - 1))
tries=$((tries - 1))
continue
fi
if ! curl -fLO https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-${fedora_release}.noarch.rpm; then
tries=0
break
fi
# check if already installed
if rpm -q rpmfusion-free-release-${fedora_release} >/dev/null 2>&1 && rpm -q rpmfusion-nonfree-release-${fedora_release} >/dev/null 2>&1; then
info_msg 'rpmfusion already installed, good'
break
fi
# otherwise try to install
if ! sudo rpm --nodeps -Uvh ./rpmfusion-*.rpm; then
tries=0
break
fi
break
done
cd "$curdir"
if [ $tries -eq 0 ]; then
warning 'installing rpmfusion repos failed, continuing without ffmpeg'
no_ffmpeg=1
fi
fi
# non-multiarch packages first
check sudo dnf -y --nogpgcheck --best --allowerasing install gcc gcc-c++ make cmake ccache git nasm redhat-rpm-config pkgconfig ccache ninja-build
# try to install multiarch libgcc, glibc-devel and pkgconfig if available
if [ -n "$amd64" ]; then
for pkg in pkgconfig libgcc glibc-devel; do
if [ "$target" = m32 ]; then
sudo dnf -y --nogpgcheck --best --allowerasing install "$pkg".i686
else
sudo dnf -y --nogpgcheck --best --allowerasing install "$pkg".x86_64
fi
done
fi
set --
if [ -z "$target" -o "$target" = m32 ]; then
# try to install both 64 bit and 32 bit versions on 64 bit hosts (see below)
if [ -n "$amd64" ]; then
# this is sometimes necessary for rawhide
set -- --exclude='glibc32*'
fi
for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel SDL2-devel SFML-devel openal-soft-devel wxGTK-devel gtk3-devel; do
case $pkg in
*ffmpeg*)
[ -z "$ENABLE_FFMPEG" ] && continue
;;
*openal*)
[ -z "$ENABLE_OPENAL" ] && continue
;;
esac
pkg_arch=
if [ -n "$amd64" ]; then
pkg_arch=.x86_64
if [ "$target" = m32 ]; then
pkg_arch=.i686
fi
fi
# Check which is newer, wxGTK or wxGTK3.
if [ "$pkg" = wxGTK-devel ]; then
pkg=$(dnf -q --releasever=$(rpm -E %fedora) --showduplicates list wxGTK-devel wxGTK3-devel 2>/dev/null | awk '{ print $1 "\t" $2 }' | grep -Ev '^(Installed|Available)' | sort -rVu -k 2,2 | head -1 | awk '{ print $1 }' | sed -E 's/\.[^.]+//')
[ -z "$pkg" ] && pkg=wxGTK3-devel
fi
set -- "$@" "${pkg}${pkg_arch}"
done
# fedora has a bug where all necessary -devel packages are not pulled in for 32 bit direct -devel deps
# this hack adds them to the list
if [ -n "$amd64" -a "$target" = m32 ]; then
info_msg 'Calculating dependencies, this will take a while..'
curdeps=
newdeps=$@
while [ "$curdeps" != "$newdeps" ]; do
curdeps=$newdeps
set -- $(echo "$@" $(sudo dnf -y --nogpgcheck repoquery --deplist "$@" 2>/dev/null | sed -n 's/\.x86_64$/.i686/; s/^ *provider: *\([^ ]*-devel-.*\)$/\1/p' | sort -u) | sed 's/ */\n/g' | sort -u)
newdeps=$@
printf '%s' .
done
echo
info_msg 'Done'
## install the RPMs with rpm --force get around file conflicts
host_rpms=$(echo "$@" | sed 's/\.i686//g')
# first update the host arch versions to reduce chances of conflicts
check sudo dnf -y --nogpgcheck --allowerasing --best install $host_rpms
oldcwd=$PWD
mkdir "$tmp/rpms"
cd "$tmp/rpms"
check sudo dnf -y --nogpgcheck --allowerasing --best download "$@"
# first try installing with dnf to pull in deps
check sudo dnf -y --nogpgcheck --allowerasing --best --skip-broken install *.rpm
# follow up with rpm --force to ignore conflicts
check sudo rpm -Uvh --force *.rpm
rm -f *.rpm
# reinstall the host rpms to make sure any overwritten files are the host version
check sudo dnf -y --nogpgcheck --allowerasing --best download $host_rpms
check sudo dnf -y --nogpgcheck --allowerasing --best --skip-broken install *.rpm
check sudo rpm -Uvh --force *.rpm
cd "$oldcwd"
rm -rf "$tmp/rpms"
ffmpeg=ffmpeg-devel.i686
rpms_installed=1
fi
else # mingw build
set -- "$@" pkgconfig
case "$target" in
mingw-w64-i686)
target=mingw32
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686-static.cmake"
;;
mingw-w64-x86_64)
target=mingw64
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64-static.cmake"
;;
*)
error 'unknown cross target (this should not happen)'
;;
esac
# install static deps
for pkg in zlib gettext SDL2 wxWidgets3; do
set -- "$@" "${target}-${pkg}-static"
done
# install deps that are not available as static
if [ -n "$ENABLE_OPENAL" ]; then
for pkg in openal-soft; do
set -- "$@" "${target}-${pkg}"
done
fi
# get the necessary win32 headers
git submodule update --init --remote --recursive
warning='SFML is required for LINK support, Fedora does not currently have a MinGW SFML package, if you want LINK support you will need to install it manually'
fi
[ -z "$rpms_installed" ] && check sudo dnf -y --nogpgcheck --best --allowerasing install "$@"
if [ -n "$ENABLE_FFMPEG" ] && ! rpm -q $ffmpeg >/dev/null 2>&1; then
warning 'ffmpeg failed to install (probably due to conflicts)'
fi
[ -n "$warning" ] && warning "$warning"
build_instructions
}
rhel_installdeps() {
rhel=1
ffmpeg=ffmpeg-devel
rpms_installed=
check_cross
installing
warning=
rhel_release=$(rpm -E %rhel)
tries=3
curdir=$(pwd)
# this source is necessary for mingw packages on rhel, and may be for other things in the future
check sudo yum -y install epel-release
# make sure rpmfusion is installed for ffmpeg
if [ -n "$ENABLE_FFMPEG" ]; then
while [ $tries -gt 0 ]; do
mkdir -p "${tmp}/fusion"
cd "${tmp}/fusion"
if ! curl -fLO https://download1.rpmfusion.org/free/el/rpmfusion-free-release-${rhel_release}.noarch.rpm; then
rhel_release=$((rhel_release - 1))
tries=$((tries - 1))
continue
fi
if ! curl -fLO https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-${rhel_release}.noarch.rpm; then
tries=0
break
fi
# check if already installed
if rpm -q rpmfusion-free-release-${rhel_release} >/dev/null 2>&1 && rpm -q rpmfusion-nonfree-release-${rhel_release} >/dev/null 2>&1; then
info_msg 'rpmfusion already installed, good'
break
fi
# otherwise try to install
if ! sudo rpm --nodeps -Uvh ./rpmfusion-*.rpm; then
tries=0
break
fi
break
done
cd "$curdir"
if [ $tries -eq 0 ]; then
warning 'installing rpmfusion repos failed, continuing without ffmpeg'
fi
fi
# non-multiarch packages first
CMAKE=cmake3
check sudo yum -y install gcc gcc-c++ make cmake3 ccache git nasm redhat-rpm-config pkgconfig ccache ninja-build
# try to install multiarch libgcc, glibc-devel and pkgconfig if available
if [ -n "$amd64" ]; then
for pkg in pkgconfig libgcc glibc-devel; do
if [ "$target" = m32 ]; then
sudo yum -y install "$pkg".i686
else
sudo yum -y install "$pkg".x86_64
fi
done
fi
set --
if [ -z "$target" -o "$target" = m32 ]; then
# try to install both 64 bit and 32 bit versions on 64 bit hosts (see below)
if [ -n "$amd64" ]; then
# this is sometimes necessary for rawhide
set -- --exclude='glibc32*'
fi
warning='RHEL does not currently have SFML packages, LINK support will be disabled'
for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel SDL2-devel openal-soft-devel wxGTK3-devel gtk3-devel; do
case $pkg in
*ffmpeg*)
[ -z "$ENABLE_FFMPEG" ] && continue
;;
*openal*)
[ -z "$ENABLE_OPENAL" ] && continue
;;
esac
if [ -n "$amd64" ]; then
if [ "$target" = m32 ]; then
set -- "$@" "${pkg}.i686"
else
set -- "$@" "${pkg}.x86_64"
fi
else
set -- "$@" "$pkg"
fi
done
# redhat has a bug where all necessary -devel packages are not pulled in for 32 bit direct -devel deps
# this hack adds them to the list
if [ -n "$amd64" -a "$target" = m32 ]; then
info_msg 'Calculating dependencies, this will take a while..'
curdeps=
newdeps=$@
while [ "$curdeps" != "$newdeps" ]; do
curdeps=$newdeps
set -- $(echo "$@" $(repoquery --deplist "$@" 2>/dev/null | sed -n 's/\.x86_64$/.i686/; s/^ *provider: *\([^ ]*-devel-.*\)$/\1/p' | sort -u) | sed 's/ */\n/g' | sort -u)
newdeps=$@
printf '%s' .
done
echo
info_msg 'Done'
## install the RPMs with rpm --force get around file conflicts
host_rpms=$(echo "$@" | sed 's/\.i686//g')
# first update the host arch versions to reduce chances of conflicts
check sudo yum -y install $host_rpms
oldcwd=$PWD
mkdir "$tmp/rpms"
cd "$tmp/rpms"
check sudo yum -y download "$@"
# first try installing with yum to pull in deps
check sudo yum -y --skip-broken install *.rpm
# follow up with rpm --force to ignore conflicts
check sudo rpm -Uvh --force *.rpm
rm -f *.rpm
# reinstall the host rpms to make sure any overwritten files are the host version
check sudo yum -y download $host_rpms
check sudo yum -y --skip-broken install *.rpm
check sudo rpm -Uvh --force *.rpm
cd "$oldcwd"
rm -rf "$tmp/rpms"
ffmpeg=ffmpeg-devel.i686
rpms_installed=1
fi
else # mingw build
set -- "$@" pkgconfig
case "$target" in
mingw-w64-i686)
target=mingw32
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake"
;;
mingw-w64-x86_64)
target=mingw64
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake"
;;
*)
error 'unknown cross target (this should not happen)'
;;
esac
# install static deps
for pkg in zlib gettext SDL2 wxWidgets; do
set -- "$@" "${target}-${pkg}-static"
done
# install deps that are not available as static
if [ -n "$ENABLE_OPENAL" ]; then
for pkg in openal-soft; do
set -- "$@" "${target}-${pkg}"
done
fi
# get the necessary win32 headers
git submodule update --init --remote --recursive
warning='SFML is required for LINK support, RHEL/EPEL does not currently have a MinGW SFML package, if you want LINK support you will need to install it manually'
fi
[ -z "$rpms_installed" ] && check sudo yum -y install "$@"
if [ -n "$ENABLE_FFMPEG" ] && ! rpm -q $ffmpeg >/dev/null 2>&1; then
warning 'ffmpeg failed to install (probably due to conflicts)'
fi
[ -n "$warning" ] && warning "$warning"
build_instructions
}
suse_installdeps() {
suse=1
check_cross
installing
tools="make cmake ccache nasm gettext-tools pkg-config ccache zip sfml2-devel ninja"
libs="gcc gcc-c++ libSDL2-devel wxWidgets-3_0-devel" # ffmpeg-devel
[ -n "$ENABLE_OPENAL" ] && libs="$libs openal-soft-devel"
# ffmpeg requires packman repos
if [ "$target" = m32 ]; then
libs=$(echo "$libs" | sed -E 's/([^ ]) ([^ ])/\1-32bit \2/g; s/$/-32bit/;')
fi
check sudo zypper in -y $tools $libs
build_instructions
}
nixos_installdeps() {
nixos=1
cat <<EOF
[32mTo build run:[0m
nix-shell --command 'mkdir build; cd build; $CMAKE .. $cmake_flags -G Ninja; ninja'
EOF
}
archlinux_require_yaourt() {
if ! command -v yaourt >/dev/null; then
(
cd "$tmp"
git clone https://aur.archlinux.org/package-query.git
cd package-query
makepkg --noconfirm -si
cd ..
git clone https://aur.archlinux.org/yaourt.git
cd yaourt
makepkg --noconfirm -si
)
[ $? -ne 0 ] && error 'could not install yaourt'
fi
pacman='yaourt --aur --m-arg=--skipinteg'
}
archlinux_installdeps() {
arch_linux=1
pacman='sudo pacman'
command -v pacaur >/dev/null && pacman='pacaur --noedit'
command -v yaourt >/dev/null && pacman='yaourt --aur --m-arg=--skipinteg'
check_cross
installing
# check for gcc-multilib
gcc_pkg=gcc
if $pacman -Q gcc-multilib >/dev/null 2>&1; then
gcc_pkg=gcc-multilib
fi
# update catalogs
check $pacman -Sy
# common needed dev packages
# not using the base-devel group because it can break gcc-multilib
check $pacman --noconfirm --needed -S binutils file grep gawk gzip libtool make patch sed util-linux nasm cmake ccache pkg-config git ccache zip ninja
gtk=gtk3
$pacman -Q gtk3-classic >/dev/null 2>&1 && gtk=gtk3-classic
libs="zlib mesa gettext sdl2 wxgtk3 $gtk sfml"
[ -n "$ENABLE_OPENAL" ] && libs="$libs openal"
[ -n "$ENABLE_FFMPEG" ] && libs="$libs ffmpeg"
if [ -z "$target" -o "$target" = m32 ]; then
if [ -z "$target" -o -z "$amd64" ]; then
# Native build.
#
# On newer versions wxgtk2 may have to be manually removed.
if ! $pacman --noconfirm --needed -S "$gcc_pkg" $libs; then
$pacman --noconfirm -R wxgtk2
fi
$pacman --noconfirm --needed -S "$gcc_pkg" $libs
else
# try to build 32 bit binaries
# lib32-sfml and lib32-ffmpeg are in AUR
archlinux_require_yaourt
# enable multilib repos if not enabled
cp /etc/pacman.conf ${tmp}/pacman.conf
cat <<'EOF' >> ${tmp}/pacman.conf
[multilib-testing]
Include = /etc/pacman.d/mirrorlist
[multilib]
Include = /etc/pacman.d/mirrorlist
EOF
pacman="$pacman --config ${tmp}/pacman.conf"
# pull in multilib repo info
$pacman -Sy
yes | check $pacman --needed -S gcc-multilib
libs32=
for lib in $libs; do
libs32="$libs32 lib32-$lib"
done
check $pacman --noconfirm --needed -S $libs32
fi
else
# windows cross build
case "$target" in
*i686*)
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake"
;;
*x86_64*)
cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake"
;;
*)
# this will never be reached, it's checked in check_cross()
error 'unknown cross target (you should not see this)'
;;
esac
check $pacman --noconfirm --needed -S "$gcc_pkg"
archlinux_require_yaourt
pkg_prefix='mingw-w64-'
# cross toolchain (without headers and crt, we'll use -git versions)
set --
for p in binutils gcc winpthreads; do
set -- "$@" "${pkg_prefix}${p}"
done
check $pacman --noconfirm --needed -S "$@"
# build library deps from AUR
info_msg 'We will now build dependencies from AUR, this will take quite a while and has a high probability of failure. In fact, it is definitely broken at the time of this writing. Press CTRL-C now to abort'
countdown 16
# pass appropriate make -jX flag through makepkg
export MAKEPKG_CONF=${MAKEPKG_CONF:-/etc/makepkg.conf}
grep -Ev '^[ ]*MAKEFLAGS=' "$MAKEPKG_CONF" > "$tmp/makepkg.conf"
export MAKEFLAGS=$(jobs_flag)
echo "MAKEFLAGS=\"$MAKEFLAGS\"" >> "$tmp/makepkg.conf"
export MAKEPKG_CONF="$tmp/makepkg.conf"
# now do the AUR builds
# first we need -headers-git and -crt-git (unless the non-git packages are installed)
for p in "${pkg_prefix}headers" "${pkg_prefix}crt"; do
if ! $pacman -Q "$p" >/dev/null 2>&1; then
check $pacman --noconfirm --needed -S "${p}-git"
else
warning "${pkg_prefix}headers-git and ${pkg_prefix}crt-git are recommended over the regular versions, if you have build failures try to install them"
fi
done
deps="zlib gettext pkg-config sdl2 wxmsw"
[ -n "$ENABLE_OPENAL" ] && deps="$deps openal"
# and the actual deps
for p in $deps; do
pkg="${pkg_prefix}${p}"