-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-release
executable file
·923 lines (759 loc) · 22.7 KB
/
build-release
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
#! /usr/bin/env bash
# ===========================================================================
#
# Copyright (c) 2017-2022 Unvanquished Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===========================================================================
# exit in case of failure
set -e
# error on undefined variable
set -u
throwError () {
local error_keyword="${1}"
local error_message="${2}"
local error_code
case "${error_keyword}" in
'BADREQUEST')
error_code=2
;;
'INTERNAL')
error_code=3
;;
'NOTIMPLEMENTED')
error_code=4
;;
esac
printf 'ERROR %s: %s\n' "${error_keyword}" "${error_message}" >&2
exit "${error_code}"
}
printHelp () {
local prog_name="$(basename "${0}")"
local tab="$(printf '\t')"
cat <<-EOF
${prog_name}: a tool to build game for release purpose.
Usage:
${tab}${prog_name} [option] <target>
The script must be called within game source directory,
but can be called from anywhere in source directory.
Option can be:
${tab}-j<NUMBER>
${tab}${tab}with NUMBER the number of parallel compilation jobs
${tab}-p
${tab}${tab}build multiple targets at once in parallel
${tab}${tab}beware: return code will be inaccurate
${tab}-u
${tab}${tab}write username in version string (requires -v)
${tab}-v
${tab}${tab}write package version strings
${tab}--vm-name <STRING>
${tab}${tab}use STRING as custom vm package basename
${tab}--vm-deps <STRING>
${tab}${tab}adds a DEPS file to the vm package using STRING as content
${tab}--build-dir <DIRECTORY>
${tab}${tab}write built files in DIRECTORY
Target can be:
${tab}vm
${tab}${tab}build virtual machine
${tab}linux-amd64
${tab}${tab}build linux amd64 engine
${tab}linux-armhf
${tab}${tab}build linux armhf engine
${tab}linux-arm64
${tab}${tab}build linux arm64 engine
${tab}macos-amd64
${tab}${tab}build mac amd64 engine
${tab}windows-amd64
${tab}${tab}build windows amd64 engine
${tab}windows-i686
${tab}${tab}build windows i686 engine
Example:
${tab}${prog_name} vm linux-amd64
EOF
exit
}
getUserName () {
whoami \
| tr '[:upper:]' '[:lower:]' \
| tr -d '[:blank:]' \
| tr -d '[:punct:]' \
| cut -c'1-10'
}
getBinPath () {
local system_windows="${1}"
local bin_name="${2}"
if "${system_windows}"
then
echo "${bin_name}.exe"
else
echo "${bin_name}"
fi
}
dumpSymbols () {
local dumpsyms_bin="${1}"
local symbol_dir="${2}"
local exec_file="${3}"
local temp_file="$(mktemp)"
"${dumpsyms_bin}" "${exec_file}" > "${temp_file}"
local symbol_basename="$(head -n'1' "${temp_file}" | cut -f'5' -d' ')"
local build_id="$(head -n'1' "${temp_file}" | cut -f'4' -d' ')"
local exec_symbol_dir="${symbol_dir}/${symbol_basename}/${build_id}"
mkdir -pv "${exec_symbol_dir}"
mv "${temp_file}" "${exec_symbol_dir}/${symbol_basename}.sym"
}
findDll () {
local mingw_arch="${1}"
local dll_name="${2}"
if [ -z "${mingw_arch}" ]
then
find "${MINGW_PREFIX}/bin/${dll_name}"
return
fi
# HACK: sort to get posix flavor of libstdc++ before win32 flavor
find '/usr' -name "${dll_name}" -type f | sort | grep --max-count=1 "${mingw_arch}" \
|| throwError INTERNAL "couldn't find DLL ${dll_name}"
}
cleanSymbols () {
local symbol_dir="${1}"
local symbol_archive_filename="${2}"
if [ -e "${symbol_dir}" ]
then
find "${symbol_dir}" -type f -name '*.sym' -exec rm -v {} \;
find "${symbol_dir}" -depth -type d -exec rmdir {} \;
fi
if [ -f "${symbol_archive_filename}" ]
then
rm "${symbol_archive_filename}"
fi
}
cleanBinaries () {
local system_windows="${1}"
local target_build_dir="${2}"
local content_dir="${3}"
local bin_list="${4}"
for bin_filename in ${bin_list}
do
bin_path="$(getBinPath "${system_windows}" "${target_build_dir}/${bin_filename}")"
engine_bin_path="$(getBinPath "${system_windows}" "${content_dir}/${bin_filename}")"
if [ -f "${bin_path}" ]
then
rm "${bin_path}"
fi
if [ -f "${engine_bin_path}" ]
then
rm "${engine_bin_path}"
fi
done
if [ -d "${content_dir}" ]
then
rmdir "${content_dir}"
fi
}
cleanEngineBuildDir () {
local content_dir="${1}"
if [ -e "${content_dir}" ]
then
find "${content_dir}" -type l -exec rm -v {} \;
find "${content_dir}" -type f -exec rm -v {} \;
find "${content_dir}" -depth -type d -exec rmdir {} \;
fi
}
cleanVmBuildDir () {
local content_dir="${1}"
local symbol_archive_basename="${2}"
if [ -e "${content_dir}" ]
then
find "${content_dir}" -type f -name '?game-*.nexe' -exec rm -v {} \;
find "${content_dir}" -type f -name "${symbol_archive_basename}.*" -exec rm -v {} \;
find "${content_dir}" -depth -type d -exec rmdir {} \;
fi
}
packageDir () {
local append='false'
if [ "${1}" = '--append' ]
then
append='true'
shift
fi
local archive_format="${1}"
local archive_filename="${2}"
local content_dir="${3}"
(
cd "${content_dir}"
if [ -f "${archive_filename}" ]
then
if ! "${append}"
then
rm -v "${archive_filename}"
fi
fi
7z -mx='9' -t"${archive_format}" a "${archive_filename}" .
)
}
printVersion () {
local tag_string='0'
local date_string=''
local ref_string=''
local dirt_string=''
local git_last_commit_short="$(git rev-parse --short HEAD)"
if [ -n "${git_last_commit_short}" ]
then
local git_describe_string="$(git describe --tags --match 'v[0-9].*' 2>/dev/null | cut -c2-)"
local git_closest_tag="$(git describe --tags --abbrev=0 --match 'v[0-9].*' 2>/dev/null | cut -c2-)"
local git_last_commit_date="$(date --date="@$(git log -1 '--pretty=format:%ct')" --utc '+%Y%m%d-%H%M%S')"
if [ -n "${git_closest_tag}" ]
then
tag_string="${git_closest_tag}"
if [ "${git_closest_tag}" != "${git_describe_string}" ]
then
date_string="-${git_last_commit_date}"
ref_string="-${git_last_commit_short}"
fi
else
date_string="-${git_last_commit_date}"
ref_string="-${git_last_commit_short}"
fi
else
date_string="-$(date --utc '+%Y%m%d-%H%M%S')"
ref_string='-0'
fi
if ! git diff --quiet 2>/dev/null
then
dirt_string='+dirty'
fi
echo "${tag_string}${date_string}${ref_string}${dirt_string}"
}
build () {
local job_count="${1}"
local write_version_string="${2}"
local write_username_string="${3}"
local root_dir="${4}"
local target="${5}"
local symbol_archive_basename='symbols'
local vmpak_archive_basename=''
local engine_archive_basename=''
local engine_archive_format='zip'
local symbol_archive_format='7z'
local vmpak_archive_format='zip'
local vmpak_archive_extension='dpk'
local build_dir="${build_dir:-${root_dir}/build}"
local release_dir="${build_dir}/release"
local vm_kind_list='cgame sgame'
local vm_arch_list='i686 amd64 armhf'
local main_nexe='main.nexe'
local engine_file_list=''
local engine_strip_list=''
local engine_symbolize_list=''
local build_vm='false'
local build_engine='false'
local system_linux='false'
local system_macos='false'
local system_windows='false'
local dumpsyms_relpath=''
local arch_amd64='false'
local arch_i686='false'
local arch_arm64='false'
local arch_armhf='false'
local host_linux='false'
local host_mac='false'
local host_windows='false'
local mingw_arch_prefix=''
case "${target}" in
'vm')
build_vm='true'
dumpsyms_relpath=linux/dump_syms/dump_syms
;;
'linux-'*)
build_engine='true'
system_linux='true'
dumpsyms_relpath=linux/dump_syms/dump_syms
;;
'macos-'*)
build_engine='true'
system_macos='true'
dumpsyms_relpath=mac/dump_syms/dump_syms_mac
;;
'windows-'*)
build_engine='true'
system_windows='true'
dumpsyms_relpath=windows/dump_syms_dwarf/dump_syms
;;
esac
case "${target}" in
*'-amd64')
arch_amd64='true'
engine_file_list="${engine_file_list} irt_core-amd64.nexe"
;;
*'-i686')
arch_i686='true'
engine_file_list="${engine_file_list} irt_core-i686.nexe"
;;
*'-arm64')
arch_arm64='true'
engine_file_list="${engine_file_list} irt_core-armhf.nexe"
;;
*'-armhf')
arch_armhf='true'
engine_file_list="${engine_file_list} irt_core-armhf.nexe"
;;
esac
local target_root_dir="${build_dir}/target"
local target_build_dir="${target_root_dir}/${target}"
local content_dir="${target_build_dir}/content"
local symbol_dir="${target_build_dir}/${symbol_archive_basename}"
local symbol_archive_filename="${target_build_dir}/${symbol_archive_basename}.${symbol_archive_format}"
local uname_system="$(uname -s)"
case "${uname_system}" in
'Linux'*)
host_linux='true'
;;
'Darwin'*)
host_mac='true'
;;
'CYGWIN'*|'MINGW'*)
host_windows='true'
;;
*)
throwError NOTIMPLEMENTED "unknown system: ${uname_system}"
;;
esac
if "${write_version_string}"
then
build_version="$(printVersion)"
if "${write_username_string}"
then
build_version+="-$(whoami | tr '[:upper:]' '[:lower:]')"
fi
vmpak_version_string="_${build_version}"
engine_version_string="_${build_version}"
else
vmpak_version_string='_0'
engine_version_string=''
fi
if [ -z "${job_count}" ]
then
if command -v 'nproc' >/dev/null
then
job_count="$(nproc)"
elif command -v 'sysctl' >/dev/null
then
job_count="$(sysctl -n 'hw.ncpu')"
else
job_count='4'
fi
fi
if [ -d "${target_build_dir}" ]
then
echo "Removing '${target_build_dir}' and contents"
# Safe w.r.t. symlinks, as long as you don't put a trailing slash:
# https://superuser.com/questions/382314/does-rm-rf-follow-symbolic-links
rm -r "${target_build_dir}"
fi
mkdir -pv "${target_build_dir}"
mkdir -pv "${release_dir}"
local cmake_opts='-DBUILD_GAME_NATIVE_DLL=OFF -DBUILD_GAME_NATIVE_EXE=OFF'
local cmake_cflags=''
if "${system_macos}"
then
PATH="${PATH}:/Applications/CMake.app/Contents/bin"
cmake_opts="${cmake_opts} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DCMAKE_BUILD_TYPE=Release -DUSE_BREAKPAD=OFF"
produce_symbols=false
else
cmake_opts="${cmake_opts} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_BREAKPAD=ON"
produce_symbols=true
fi
if "${system_macos}" && "${arch_amd64}"
then
cmake_opts="${cmake_opts} -DCMAKE_OSX_ARCHITECTURES=x86_64"
fi
if "${build_vm}"
then
vmpak_archive_basename="${vmpak_basename}"
cmake_opts="${cmake_opts} -DBUILD_GAME_NACL=ON -DBUILD_GAME_NACL_NEXE=ON -DBUILD_CGAME=ON -DBUILD_SGAME=ON -DBUILD_CLIENT=OFF -DBUILD_TTY_CLIENT=OFF -DBUILD_SERVER=OFF"
fi
if "${build_engine}"
then
engine_archive_basename="${target}"
cmake_opts="${cmake_opts} -DUSE_LTO=ON -DBUILD_CLIENT=ON -DBUILD_SERVER=ON -DBUILD_TTY_CLIENT=ON -DBUILD_GAME_NACL=OFF -DBUILD_GAME_NACL_NEXE=OFF -DBUILD_CGAME=OFF -DBUILD_SGAME=OFF -DUSE_HARDENING=1"
local strip='strip'
if "${system_windows}" && ! "${host_windows}"
then
if "${arch_i686}"
then
bitness='32'
mingw_arch_prefix='i686'
else
bitness='64'
mingw_arch_prefix='x86_64'
fi
strip="${mingw_arch_prefix}-w64-mingw32-strip"
cmake_opts="${cmake_opts} -DCMAKE_TOOLCHAIN_FILE=${root_dir}/daemon/cmake/cross-toolchain-mingw${bitness}.cmake"
# unused
# cmake_opts="${cmake_opts} -DPKG_CONFIG_EXECUTABLE=${mingw_arch_prefix}-w64-mingw32-pkg-config"
fi
if ${system_linux}
then
cmake_opts="${cmake_opts} -DUSE_STATIC_LIBS=1 -DOpenGL_GL_PREFERENCE=LEGACY"
engine_file_list="${engine_file_list} daemon daemonded daemon-tty crash_server nacl_helper_bootstrap nacl_loader"
engine_symbolize_list='daemon daemonded daemon-tty'
engine_strip_list='daemon daemonded daemon-tty crash_server'
if "${arch_i686}"
then
cmake_opts+=' -DCMAKE_C_COMPILER=i686-linux-gnu-gcc'
cmake_opts+=' -DCMAKE_CXX_COMPILER=i686-linux-gnu-g++'
elif "${arch_arm64}"
then
engine_file_list+=" nacl_helper_bootstrap-armhf lib-armhf/ld-linux-armhf lib-armhf/libc.so.6 lib-armhf/libgcc_s.so.1 lib-armhf/libm.so.6 lib-armhf/libpthread.so.0 lib-armhf/librt.so.1 lib-armhf/libstdc++.so.6"
cmake_opts+=' -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc'
cmake_opts+=' -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++'
elif "${arch_armhf}"
then
cmake_opts+=' -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc'
cmake_opts+=' -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++'
fi
fi
if "${system_macos}"
then
engine_file_list="${engine_file_list} daemon daemonded daemon-tty nacl_loader"
# No Breakpad, hence no symbolize and strip steps
fi
if "${system_windows}"
then
if "${arch_i686}"
then
engine_file_list="${engine_file_list} nacl_loader-amd64.exe irt_core-amd64.nexe" # WOW64 support
if "${host_windows}"
then
# MSYS2 uses the DWARF exception flavor
special_dll='libgcc_s_dw2-1.dll'
else
special_dll='libgcc_s_sjlj-1.dll'
fi
else
special_dll='libgcc_s_seh-1.dll'
fi
extra_dll_list="${special_dll} libstdc++-6.dll libwinpthread-1.dll libssp-0.dll"
# DLLs are added to engine_file_list after building
engine_file_list="${engine_file_list} daemon.exe daemonded.exe daemon-tty.exe crash_server.exe nacl_loader.exe"
engine_symbolize_list='daemon.exe daemonded.exe daemon-tty.exe'
engine_strip_list='daemon.exe daemonded.exe daemon-tty.exe crash_server.exe'
# those paths are distro-centric
# cp -av "/usr/${mingw_arch_prefix}-w64-mingw32/lib/libwinpthread-1.dll" "${target_build_dir}/"
# cp -av "/usr/lib/gcc/${mingw_arch_prefix}-w64-mingw32/7.3-posix/libstdc++-6.dll" "${target_build_dir}/"
# cp -av "/usr/lib/gcc/${mingw_arch_prefix}-w64-mingw32/7.3-posix/${special_dll}" "${target_build_dir}/"
for dll_name in ${extra_dll_list}
do
dll_location="$(findDll "${mingw_arch_prefix}" "${dll_name}")"
cp -av "${dll_location}" "${target_build_dir}/"
done
fi
local strip='strip'
if "${system_windows}" && ! "${host_windows}"
then
if "${arch_i686}"
then
bitness='32'
mingw_arch_prefix='i686'
else
bitness='64'
mingw_arch_prefix='x86_64'
fi
strip="${mingw_arch_prefix}-w64-mingw32-strip"
cmake_opts="${cmake_opts} -DCMAKE_TOOLCHAIN_FILE=${root_dir}/daemon/cmake/cross-toolchain-mingw${bitness}.cmake"
# unused
# cmake_opts="${cmake_opts} -DPKG_CONFIG_EXECUTABLE=${mingw_arch_prefix}-w64-mingw32-pkg-config"
fi
fi
if "${build_vm}"
then
# configuration
cmake -H"${root_dir}" \
-B"${target_build_dir}" \
-G"Unix Makefiles" \
${cmake_opts} \
|| throwError INTERNAL "${target} cmake failed"
fi
if "${build_engine}"
then
# configuration
cmake -H"${root_dir}" \
-B"${target_build_dir}" \
-G"Unix Makefiles" \
-D"CMAKE_C_FLAGS=${cmake_cflags}" \
-D"CMAKE_CXX_FLAGS=${cmake_cflags}" \
-D"CMAKE_EXE_LINKER_FLAGS=${cmake_cflags}" \
${cmake_opts} \
|| throwError INTERNAL "${target} cmake failed"
fi
if "${build_vm}" || "${build_engine}"
then
daemon_dir="$(cmake -H"${root_dir}" -B"${target_build_dir}" -LH | grep '^DAEMON_DIR:' | sed -e 's/[^=]*=//')"
fi
if "${build_vm}"
then
# build vm
cmake --build "${target_build_dir}" -- -j"${job_count}" nacl-vms \
|| throwError INTERNAL "${target} build failed"
fi
if "${build_engine}"
then
# build engine
cmake --build "${target_build_dir}" -- -j"${job_count}" \
|| throwError INTERNAL "${target} build failed"
if "${system_windows}"
then
engine_file_list="${engine_file_list} $(cd "${target_build_dir}" && ls *.dll)"
elif "${system_macos}"
then
# On Mac there are multiple copies of each dylib; get the ones with 3 version numbers
# stat -f%N just echos back the filenames while erroring if one doesn't exist
engine_file_list="${engine_file_list} $(cd "${target_build_dir}" && stat -f%N libGLEW.*.*.*.dylib libopenal.*.*.*.dylib)"
fi
fi
if "${produce_symbols}"
then
# build breakpad
local breakpad_dir="${daemon_dir}/libs/breakpad"
local dumpsyms_bin="$(getBinPath ${host_windows} ${breakpad_dir}/src/tools/${dumpsyms_relpath})"
if ! [ -d "${breakpad_dir}" ]
then
throwError INTERNAL "breakpad dir missing: ${breakpad_dir}"
fi
# Check for working dump_syms. In MSYS2 it doesn't run from an opposite-bitness shell.
set +e
"${dumpsyms_bin}" --help 2>/dev/null
local exitcode=$?
set -e
if [ "${exitcode}" -gt 1 ]
then
(
cd "${breakpad_dir}"
autoreconf -fvi && ./configure \
|| throwError INTERNAL 'breakpad configure failed'
)
make -C"${breakpad_dir}" clean \
|| true
local make_targets=''
if "${host_windows}"
then
make_targets='src/tools/windows/dump_syms_dwarf/dump_syms.exe'
fi
make -j"${job_count}" -C"${breakpad_dir}" $make_targets \
|| throwError INTERNAL 'breakpad build failed'
fi
fi
if "${build_vm}"
then
cleanSymbols "${symbol_dir}" "${symbol_archive_filename}"
# extract vm symbols
for vm in ${vm_kind_list}
do
for arch in ${vm_arch_list}
do
(
cd "${target_build_dir}"
local vm_file="${vm}-${arch}.nexe"
local stripped_vm_file="${vm}-${arch}-stripped.nexe"
printf 'extracting symbols from %s\n' "${vm_file}"
if ! [ -f "${vm_file}" ]
then
throwError INTERNAL "missing: ${vm_file}"
fi
if [ -f "${main_nexe}" ]
then
rm "${main_nexe}"
fi
ln -s "${vm_file}" 'main.nexe'
dumpSymbols "${dumpsyms_bin}" "${symbol_dir}" "${main_nexe}"
mkdir -pv "${content_dir}"
cp -v "${stripped_vm_file}" "${content_dir}/${vm_file}"
)
done
done
# compress vm symbols
packageDir "${symbol_archive_format}" "${symbol_archive_filename}" "${symbol_dir}"
cp -v "${symbol_archive_filename}" "${content_dir}/${symbol_archive_basename}.${symbol_archive_format}"
# make vm package
vmpak_archive_filename="${release_dir}/${vmpak_archive_basename}${vmpak_version_string}.${vmpak_archive_extension}"
if [ -f "${vmpak_archive_filename}" ]
then
rm -v "${vmpak_archive_filename}"
fi
packageDir "${vmpak_archive_format}" "${vmpak_archive_filename}" "${content_dir}"
if [ -n "${vmpak_deps_content}" ]
then
local temp_deps_dir="$(mktemp -d)"
printf "${vmpak_deps_content}" > "${temp_deps_dir}/DEPS"
packageDir --append "${vmpak_archive_format}" "${vmpak_archive_filename}" "${temp_deps_dir}"
rm "${temp_deps_dir}/DEPS"
rmdir "${temp_deps_dir}"
fi
cleanSymbols "${symbol_dir}" "${symbol_archive_filename}"
cleanVmBuildDir "${content_dir}" "${symbol_archive_basename}"
fi
if "${build_engine}"
then
local bin_path
local engine_bin_path
cleanSymbols "${symbol_dir}" "${symbol_archive_filename}"
mkdir -pv "${content_dir}"
if "${produce_symbols}"
then
# extract engine symbols
for bin in ${engine_symbolize_list}
do
bin_path="${target_build_dir}/${bin}"
printf 'extracting symbols from %s\n' "${bin_path}"
dumpSymbols "${dumpsyms_bin}" "${symbol_dir}" "${bin_path}"
done
fi
local engine_file_dest="${content_dir}"
if "${system_macos}"
then
engine_file_dest="${content_dir}/Unvanquished.app/Contents/MacOS"
mkdir -pv "${engine_file_dest}"
cp -v "${root_dir}/macosx/unvanquished.sh" "${engine_file_dest}"
cp -av "${target_build_dir}/SDL2.framework" "${engine_file_dest}"
rm -rv "${engine_file_dest}/SDL2.framework/Headers"
rm -rv "${engine_file_dest}/SDL2.framework/Versions/A/Headers"
rm -rv "${engine_file_dest}/SDL2.framework/Versions/Current/Headers"
cp -v "${root_dir}/macosx/Info.plist" "${content_dir}/Unvanquished.app/Contents"
mkdir -v "${content_dir}/Unvanquished.app/Contents/Resources"
cp -v "${root_dir}/macosx/Unvanquished.icns" "${content_dir}/Unvanquished.app/Contents/Resources"
fi
for file in ${engine_file_list}
do
file_dir="$(dirname "${file}")"
if [ "${file_dir}" != '.' ]
then
mkdir -pv "${engine_file_dest}/${file_dir}"
fi
cp -v "${target_build_dir}/${file}" "${engine_file_dest}/${file}"
done
for file in ${engine_strip_list}
do
echo "Stripping ${file}"
"${strip}" "${engine_file_dest}/${file}"
done
if "${produce_symbols}"
then
# compress engine symbols
packageDir "${symbol_archive_format}" "${symbol_archive_filename}" "${symbol_dir}"
cp -v "${symbol_archive_filename}" "${content_dir}/${symbol_archive_basename}-${target}.${symbol_archive_format}"
fi
# make engine archive
engine_archive_filename="${release_dir}/${engine_archive_basename}${engine_version_string}.${engine_archive_format}"
packageDir "${engine_archive_format}" "${engine_archive_filename}" "${content_dir}"
cleanSymbols "${symbol_dir}" "${symbol_archive_filename}"
cleanEngineBuildDir "${content_dir}"
fi
}
root_dir="$(git rev-parse --show-toplevel)"
[ -f "${root_dir}/src/cgame/cg_main.cpp" ] || throwError INTERNAL "must be called from game source tree"
[ -z "${1:-}" ] && throwError BADREQUEST 'missing target'
job_count=''
parallel_target='false'
write_version_string='false'
write_username_string='false'
target_list=''
vmpak_basename='vm'
vmpak_deps_content=''
while [ -n "${1:-}" ]
do
case "${1}" in
'vm'|'linux-amd64'|'linux-i686'|'linux-arm64'|'linux-armhf'|'macos-amd64'|'windows-amd64'|'windows-i686')
target_list="${target_list} ${1}"
shift
;;
'macos-i686')
throwError NOTIMPLEMENTED "unsupported target: ${1}"
;;
'-d')
set -x
shift
;;
'-j'*)
job_count="${1:2}"
shift
;;
'-p')
parallel_target='true'
shift
;;
'-u')
write_username_string='true'
shift
;;
'-v')
write_version_string='true'
shift
;;
'--vm-name')
shift
case "${1:-}" in
''|'-'*)
throwError BADREQUEST "missing vm name"
;;
esac
vmpak_basename="${1}"
shift
;;
'--vm-deps')
shift
case "${1:-}" in
''|'-'*)
throwError BADREQUEST "missing DEPS content string"
;;
esac
vmpak_deps_content="${1}"
shift
;;
'--build-dir')
shift
case "${1:-}" in
''|'-'*)
throwError BADREQUEST "missing build dir"
;;
esac
build_dir="$(realpath "${1}")"
shift
;;
'-h'|'--help')
printHelp
;;
'-'*)
throwError BADREQUEST "unknown option: ${1}"
;;
*)
throwError BADREQUEST "unknown target: ${1}"
;;
esac
done
for target in ${target_list}
do
if "${parallel_target}"
then
build "${job_count}" "${write_version_string}" "${write_username_string}" "${root_dir}" "${target}" &
else
build "${job_count}" "${write_version_string}" "${write_username_string}" "${root_dir}" "${target}"
fi
done
wait
#EOF