Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Makefile.in - github.com/ValveSoftware/Proton.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b0b98cfd410dfc2e23ad42c9fbb0e841b893ebb (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
# Enable secondary expansions, needed for font compilation rules
.SECONDEXPANSION:

SRC := $(abspath $(SRCDIR))
OBJ := $(abspath $(CURDIR))

ifeq ($(filter s,$(MAKEFLAGS)),s)
MAKEFLAGS += --quiet --no-print-directory
--quiet? := --quiet
else
MFLAGS += V=1 VERBOSE=1
-v? := -v
--verbose? := --verbose
endif

##
## Nested make
##

SHELL := /bin/bash

ifneq ($(NO_NESTED_MAKE),1)
# Pass all variables/goals to ourselves as a sub-make such that we will get a trailing error message upon failure.  (We
# invoke a lot of long-running build-steps, and make fails to re-print errors when they happened ten thousand lines
# ago.)
export
.DEFAULT_GOAL := default
.PHONY: $(MAKECMDGOALS) default nested_make
default $(MAKECMDGOALS): nested_make

nested_make:
	+$(MAKE) $(MAKECMDGOALS) -f $(firstword $(MAKEFILE_LIST)) NO_NESTED_MAKE=1

else # (Rest of the file is the else)

##
## General/global config
##

# We expect the configure script to conditionally set the following:
#   SRCDIR          - Path to source
#   BUILD_NAME      - Name of the build for manifests etc.
#   STEAMRT_IMAGE   - Name of the docker image to use for building
#   STEAMRT_NAME    - Name of the steam runtime to build against (scout / soldier)

ifeq ($(SRCDIR),)
	foo := $(error SRCDIR not set, do not include Makefile.in directly, run ./configure.sh to generate Makefile)
endif

include $(SRC)/make/utility.mk
include $(SRC)/make/rules-source.mk
include $(SRC)/make/rules-common.mk
include $(SRC)/make/rules-meson.mk
include $(SRC)/make/rules-cmake.mk
include $(SRC)/make/rules-autoconf.mk
include $(SRC)/make/rules-configure.mk
include $(SRC)/make/rules-winemaker.mk
include $(SRC)/make/rules-cargo.mk

# If CC is coming from make's defaults or nowhere, use our own default.  Otherwise respect environment.
CCACHE_ENV := $(patsubst %,-e %,$(shell env|cut -d= -f1|grep '^CCACHE_'))
ifeq ($(ENABLE_CCACHE),1)
	export CCACHE_DIR := $(if $(CCACHE_DIR),$(CCACHE_DIR),$(HOME)/.ccache)
	override DOCKER_OPTS := -v $(CCACHE_DIR):$(CCACHE_DIR)$(CONTAINER_MOUNT_OPTS) $(CCACHE_ENV) -e CCACHE_DIR=$(CCACHE_DIR) $(DOCKER_OPTS)
else
	export CCACHE_DISABLE := 1
	override DOCKER_OPTS := $(CCACHE_ENV) -e CCACHE_DISABLE=1 $(DOCKER_OPTS)
endif

export CARGO_HOME := $(if $(CARGO_HOME),$(CARGO_HOME),$(HOME)/.cargo)
override DOCKER_OPTS := -v $(CARGO_HOME):$(CARGO_HOME)$(CONTAINER_MOUNT_OPTS) -e CARGO_HOME=$(CARGO_HOME) $(DOCKER_OPTS)

ifneq ($(ROOTLESS_CONTAINER),1)
	override DOCKER_OPTS := -e HOME -e USER -e USERID=$(shell id -u) -u $(shell id -u):$(shell id -g) $(DOCKER_OPTS)
endif

ifeq ($(CONTAINER_ENGINE),)
	CONTAINER_ENGINE := docker
endif

DOCKER_BASE = $(CONTAINER_ENGINE) run --rm -v $(SRC):$(SRC)$(CONTAINER_MOUNT_OPTS) -v $(OBJ):$(OBJ)$(CONTAINER_MOUNT_OPTS) \
                -w $(OBJ) -e MAKEFLAGS \
                $(DOCKER_OPTS) $(STEAMRT_IMAGE)

STEAMRT_NAME ?= soldier
ifeq ($(STEAMRT_NAME),soldier)
TOOLMANIFEST_VDF_SRC := toolmanifest_runtime.vdf
else
TOOLMANIFEST_VDF_SRC := toolmanifest_noruntime.vdf
endif

ifneq ($(STEAMRT_IMAGE),)
CONTAINER_SHELL := $(DOCKER_BASE) /bin/bash
STEAM_RUNTIME_RUNSH := $(DOCKER_BASE)
else
CONTAINER_SHELL := $(SHELL)
STEAM_RUNTIME_RUNSH :=
endif


MAKECMDGOALS32 := $(filter-out all32,$(filter %32,$(MAKECMDGOALS)))
MAKECMDGOALS64 := $(filter-out all64,$(filter %64,$(MAKECMDGOALS)))
CONTAINERGOALS := $(MAKECMDGOALS32) $(MAKECMDGOALS64) $(filter fonts,$(MAKECMDGOALS))

all: all32 all64 fonts
.PHONY: all

all32 $(MAKECMDGOALS32):
.PHONY: all32 $(MAKECMDGOALS32)

all32 $(MAKECMDGOALS64):
.PHONY: all64 $(MAKECMDGOALS64)

ifeq ($(CONTAINER),)
J := $(shell nproc)
ifeq ($(ENABLE_CCACHE),1)
container-build: $(shell mkdir -p $(CCACHE_DIR))
endif
container-build: $(shell mkdir -p $(CARGO_HOME))
container-build: private SHELL := $(CONTAINER_SHELL)
container-build:
	+$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) -f $(firstword $(MAKEFILE_LIST)) $(MFLAGS) $(MAKEOVERRIDES) CONTAINER=1 $(CONTAINERGOALS)
.PHONY: container-build

all32 $(MAKECMDGOALS32): container-build
all64 $(MAKECMDGOALS64): container-build
else
J = $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS)))
endif


.PHONY: test-container
test-container:
	@echo >&2 ":: Testing container"
	$(CONTAINER_SHELL) -c "echo Hello World!"

# Many of the configure steps below depend on the makefile itself, such that they are dirtied by changing the recipes
# that create them.  This can be annoying when working on the makefile, building with NO_MAKEFILE_DEPENDENCY=1 disables
# this.
MAKEFILE_DEP := $(MAKEFILE_LIST)
ifeq ($(NO_MAKEFILE_DEPENDENCY),1)
MAKEFILE_DEP :=
endif

##
## Global config
##

DST_BASE := $(OBJ)/dist
DST_DIR := $(DST_BASE)/dist
DST_LIBDIR32 := $(DST_DIR)/lib
DST_LIBDIR64 := $(DST_DIR)/lib64
DEPLOY_DIR := ./deploy
REDIST_DIR := ./redist

# All top level goals.  Lazy evaluated so they can be added below.
GOAL_TARGETS = $(GOAL_TARGETS_LIBS)
# Excluding goals like wine and dist that are either long running or slow per invocation
GOAL_TARGETS_LIBS =
# Any explicit thing, superset
ALL_TARGETS =

##
## Platform-specific variables
##

ifneq ($(UNSTRIPPED_BUILD),)
    STRIP :=
    INSTALL_PROGRAM_FLAGS :=
    MESON_STRIP_ARG :=
else
    STRIP := strip
    INSTALL_PROGRAM_FLAGS := -s
    MESON_STRIP_ARG := --strip
endif

CROSSLDFLAGS   += -Wl,--file-alignment,4096
OPTIMIZE_FLAGS := -O2 -march=nocona -mtune=core-avx2 -mfpmath=sse
SANITY_FLAGS   := -fwrapv -fno-strict-aliasing
DEBUG_FLAGS    := -gdwarf-2 -gstrict-dwarf
COMMON_FLAGS    = $(DEBUG_FLAGS) $(OPTIMIZE_FLAGS) $(SANITY_FLAGS) -ffile-prefix-map=$(CCACHE_BASEDIR)=.
COMMON_FLAGS32 := -mstackrealign
CARGO_BUILD_ARG := --release

##
## Target configs
##

COMPAT_MANIFEST_TEMPLATE := $(SRCDIR)/compatibilitytool.vdf.template
LICENSE := $(SRCDIR)/dist.LICENSE
OFL_LICENSE := $(SRCDIR)/fonts/liberation-fonts/LICENSE
AV1_PATENTS := $(SRCDIR)/dav1d/doc/PATENTS

GECKO_VER := 2.47.3
GECKO32_TARBALL := wine-gecko-$(GECKO_VER)-x86.tar.xz
GECKO64_TARBALL := wine-gecko-$(GECKO_VER)-x86_64.tar.xz

WINEMONO_VER := 7.3.0
WINEMONO_TARBALL := wine-mono-$(WINEMONO_VER)-x86.tar.xz

FONTS := $(SRCDIR)/fonts
FONTS_OBJ := ./obj-fonts

ifeq ($(CONTAINER),)

## downloads -- Convenience target to download packages used during the build
## process. Places them in subdirs one up from the Proton source dir, so
## they won't be wiped during git-clean, vagrant rsync, etc.

.PHONY: downloads

GECKO64_TARBALL_URL := https://dl.winehq.org/wine/wine-gecko/$(GECKO_VER)/$(GECKO64_TARBALL)
GECKO32_TARBALL_URL := https://dl.winehq.org/wine/wine-gecko/$(GECKO_VER)/$(GECKO32_TARBALL)
MONO_TARBALL_URL := https://github.com/madewokherd/wine-mono/releases/download/wine-mono-$(WINEMONO_VER)/$(WINEMONO_TARBALL)

SHARED_GECKO64_TARBALL := $(SRCDIR)/../gecko/$(GECKO64_TARBALL)
SHARED_GECKO32_TARBALL := $(SRCDIR)/../gecko/$(GECKO32_TARBALL)
SHARED_MONO_TARBALL := $(SRCDIR)/../mono/$(WINEMONO_TARBALL)

$(SHARED_GECKO64_TARBALL):
	mkdir -p $(dir $@)
	wget -O "$@" "$(GECKO64_TARBALL_URL)"

$(SHARED_GECKO32_TARBALL):
	mkdir -p $(dir $@)
	wget -O "$@" "$(GECKO32_TARBALL_URL)"

$(SHARED_MONO_TARBALL):
	mkdir -p $(dir $@)
	wget -O "$@" "$(MONO_TARBALL_URL)"

downloads: $(SHARED_GECKO64_TARBALL) $(SHARED_GECKO32_TARBALL) $(SHARED_MONO_TARBALL)

##
## dist/install -- steps to finalize the install
##

$(DST_DIR):
	mkdir -p $@

STEAM_DIR := $(HOME)/.steam/root

FILELOCK_TARGET := $(addprefix $(DST_BASE)/,filelock.py)
$(FILELOCK_TARGET): $(addprefix $(SRCDIR)/,filelock.py)

PROTON_PY_TARGET := $(addprefix $(DST_BASE)/,proton)
$(PROTON_PY_TARGET): $(addprefix $(SRCDIR)/,proton)

PROTON37_TRACKED_FILES_TARGET := $(addprefix $(DST_BASE)/,proton_3.7_tracked_files)
$(PROTON37_TRACKED_FILES_TARGET): $(addprefix $(SRCDIR)/,proton_3.7_tracked_files)

USER_SETTINGS_PY_TARGET := $(addprefix $(DST_BASE)/,user_settings.sample.py)
$(USER_SETTINGS_PY_TARGET): $(addprefix $(SRCDIR)/,user_settings.sample.py)

DIST_COPY_TARGETS := $(FILELOCK_TARGET) $(PROTON_PY_TARGET) \
                     $(PROTON37_TRACKED_FILES_TARGET) $(USER_SETTINGS_PY_TARGET)

DIST_VERSION := $(DST_BASE)/version
DIST_OVR32 := $(DST_LIBDIR32)/wine/dxvk/openvr_api_dxvk.dll
DIST_OVR64 := $(DST_LIBDIR64)/wine/dxvk/openvr_api_dxvk.dll
DIST_PREFIX := $(DST_DIR)/share/default_pfx/
DIST_COMPAT_MANIFEST := $(DST_BASE)/compatibilitytool.vdf
DIST_LICENSE := $(DST_BASE)/LICENSE
DIST_TOOLMANIFEST := $(addprefix $(DST_BASE)/,toolmanifest.vdf)
DIST_OFL_LICENSE := $(DST_BASE)/LICENSE.OFL
DIST_AV1_PATENTS := $(DST_BASE)/PATENTS.AV1
DIST_GECKO_DIR := $(DST_DIR)/share/wine/gecko
DIST_GECKO32 := $(DIST_GECKO_DIR)/wine-gecko-$(GECKO_VER)-x86
DIST_GECKO64 := $(DIST_GECKO_DIR)/wine-gecko-$(GECKO_VER)-x86_64
DIST_WINEMONO_DIR := $(DST_DIR)/share/wine/mono
DIST_WINEMONO := $(DIST_WINEMONO_DIR)/wine-mono-$(WINEMONO_VER)
DIST_FONTS := $(DST_DIR)/share/fonts
DIST_WINEOPENXR_JSON64 := $(DIST_PREFIX)/drive_c/openxr/wineopenxr64.json
DIST_WINEOPENXR64 := $(DIST_PREFIX)/drive_c/windows/system32/wineopenxr.dll

DIST_TARGETS := $(DIST_COPY_TARGETS) $(DIST_OVR32) $(DIST_OVR64) \
                $(DIST_GECKO32) $(DIST_GECKO64) $(DIST_WINEMONO) \
                $(DIST_COMPAT_MANIFEST) $(DIST_LICENSE) $(DIST_TOOLMANIFEST) \
                $(DIST_OFL_LICENSE) $(DIST_AV1_PATENTS) $(DIST_FONTS)

DEPLOY_COPY_TARGETS := $(DIST_COPY_TARGETS) $(DIST_VERSION) $(DIST_LICENSE) \
                       $(DIST_TOOLMANIFEST) $(DIST_OFL_LICENSE) $(DIST_AV1_PATENTS)
REDIST_COPY_TARGETS := $(DEPLOY_COPY_TARGETS) $(DIST_COMPAT_MANIFEST)

$(DIST_LICENSE): $(LICENSE)
	cp -a $< $@

$(DIST_TOOLMANIFEST): $(addprefix $(SRCDIR)/,$(TOOLMANIFEST_VDF_SRC))
	cp -a $< $@

$(DIST_OFL_LICENSE): $(OFL_LICENSE)
	cp -a $< $@

$(DIST_AV1_PATENTS): $(AV1_PATENTS)
	cp -a $< $@

$(DIST_OVR32): $(SRCDIR)/openvr/bin/win32/openvr_api.dll | $(DST_DIR)
	mkdir -p $(DST_LIBDIR32)/wine/dxvk
	cp -a $< $@

$(DIST_OVR64): $(SRCDIR)/openvr/bin/win64/openvr_api.dll | $(DST_DIR)
	mkdir -p $(DST_LIBDIR64)/wine/dxvk
	cp -a $< $@

$(DIST_COPY_TARGETS): | $(DST_DIR)
	cp -a $(SRCDIR)/$(notdir $@) $@

$(DIST_COMPAT_MANIFEST): $(COMPAT_MANIFEST_TEMPLATE) $(MAKEFILE_DEP) | $(DST_DIR)
	sed -r 's|##BUILD_NAME##|$(BUILD_NAME)|' $< > $@

$(DIST_GECKO_DIR):
	mkdir -p $@

$(DIST_GECKO64): | $(DIST_GECKO_DIR)
	if [ -e "$(SHARED_GECKO64_TARBALL)" ]; then \
		tar -xf "$(SHARED_GECKO64_TARBALL)" -C "$(dir $@)"; \
	else \
		mkdir -p $(SRCDIR)/contrib/; \
		if [ ! -e "$(SRCDIR)/contrib/$(GECKO64_TARBALL)" ]; then \
			echo ">>>> Downloading wine-gecko. To avoid this in future, put it here: $(SRCDIR)/../gecko/$(GECKO64_TARBALL)"; \
			wget -O "$(SRCDIR)/contrib/$(GECKO64_TARBALL)" "$(GECKO64_TARBALL_URL)"; \
		fi; \
		tar -xf "$(SRCDIR)/contrib/$(GECKO64_TARBALL)" -C "$(dir $@)"; \
	fi

$(DIST_GECKO32): | $(DIST_GECKO_DIR)
	if [ -e "$(SHARED_GECKO32_TARBALL)" ]; then \
		tar -xf "$(SHARED_GECKO32_TARBALL)" -C "$(dir $@)"; \
	else \
		mkdir -p $(SRCDIR)/contrib/; \
		if [ ! -e "$(SRCDIR)/contrib/$(GECKO32_TARBALL)" ]; then \
			echo ">>>> Downloading wine-gecko. To avoid this in future, put it here: $(SRCDIR)/../gecko/$(GECKO32_TARBALL)"; \
			wget -O "$(SRCDIR)/contrib/$(GECKO32_TARBALL)" "$(GECKO32_TARBALL_URL)"; \
		fi; \
		tar -xf "$(SRCDIR)/contrib/$(GECKO32_TARBALL)" -C "$(dir $@)"; \
	fi

$(DIST_WINEMONO_DIR):
	mkdir -p $@

$(DIST_WINEMONO): | $(DIST_WINEMONO_DIR)
	if [ -e "$(SHARED_MONO_TARBALL)" ]; then \
		tar -xf "$(SHARED_MONO_TARBALL)" -C "$(dir $@)"; \
	else \
		mkdir -p $(SRCDIR)/contrib/; \
		if [ ! -e "$(SRCDIR)/contrib/$(WINEMONO_TARBALL)" ]; then \
			echo ">>>> Downloading wine-mono. To avoid this in future, put it here: $(SRCDIR)/../mono/$(WINEMONO_TARBALL)"; \
			wget -O "$(SRCDIR)/contrib/$(WINEMONO_TARBALL)" "$(MONO_TARBALL_URL)"; \
		fi; \
		tar -xf "$(SRCDIR)/contrib/$(WINEMONO_TARBALL)" -C "$(dir $@)"; \
	fi

$(DIST_FONTS): fonts
	mkdir -p $@
	cp $(FONTS_OBJ)/*.ttf "$@"
	cp $(FONTS_OBJ)/source-han/msyh.ttf "$@"
	cp $(FONTS_OBJ)/source-han/simsun.ttc "$@"
	cp $(FONTS_OBJ)/ume-gothic/msgothic.ttc "$@"
	cp $(FONTS_OBJ)/source-han/malgun.ttf "$@"

.PHONY: dist

ALL_TARGETS += dist
GOAL_TARGETS += dist

dist_prefix: wine gst_good gst_libav gst_plugins_rs
	find $(DST_LIBDIR32)/wine -type f -execdir chmod a-w '{}' '+'
	find $(DST_LIBDIR64)/wine -type f -execdir chmod a-w '{}' '+'
	rm -rf $(abspath $(DIST_PREFIX))
	python3 $(SRCDIR)/default_pfx.py $(abspath $(DIST_PREFIX)) $(abspath $(DST_DIR)) $(STEAM_RUNTIME_RUNSH)

dist_wineopenxr: dist_prefix $(DIST_WINEOPENXR_JSON64)

dist: $(DIST_TARGETS) all-dist dist_wineopenxr | $(DST_DIR)
	echo `date '+%s'` `GIT_DIR=$(abspath $(SRCDIR)/.git) git describe --tags` > $(DIST_VERSION)

deploy: dist | $(filter-out dist deploy install redist,$(MAKECMDGOALS))
	mkdir -p $(DEPLOY_DIR) && \
	cp -a $(DEPLOY_COPY_TARGETS) $(DEPLOY_DIR) && \
	tar -C $(DST_DIR) -c . > $(DEPLOY_DIR)/proton_dist.tar
	@echo "Created deployment archive at "$(DEPLOY_DIR)"/proton_dist.tar"

install: dist | $(filter-out dist deploy install redist,$(MAKECMDGOALS))
	if [ ! -d $(STEAM_DIR) ]; then echo >&2 "!! "$(STEAM_DIR)" does not exist, cannot install"; return 1; fi
	mkdir -p $(STEAM_DIR)/compatibilitytools.d/$(BUILD_NAME)
	cp -rf --no-dereference --preserve=mode,links $(DST_BASE)/* $(STEAM_DIR)/compatibilitytools.d/$(BUILD_NAME)
	cp -f $(DIST_VERSION) $(STEAM_DIR)/compatibilitytools.d/$(BUILD_NAME)/dist/
	@echo "Installed Proton to "$(STEAM_DIR)/compatibilitytools.d/$(BUILD_NAME)
	@echo "You may need to restart Steam to select this tool"

redist: dist | $(filter-out dist deploy install redist,$(MAKECMDGOALS))
	mkdir -p $(REDIST_DIR)
	cp -a $(REDIST_COPY_TARGETS) $(REDIST_DIR)
	tar -C $(DST_DIR) -c . | gzip -c -1 > $(REDIST_DIR)/proton_dist.tar.gz
	@echo "Created redistribution tarball at "$(REDIST_DIR)"/proton_dist.tar.gz"

.PHONY: module32 module64 module

module32: private SHELL := $(CONTAINER_SHELL)
module32: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure32
module32: | all-source wine-configure32
	+$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ32)/dlls/$(module)

module64: private SHELL := $(CONTAINER_SHELL)
module64: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure64
module64: | all-source wine-configure64
	+$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ64)/dlls/$(module)

module: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure
module: | all-source wine-configure
module: module32 module64

endif # ifeq ($(CONTAINER),)


##
## dav1d
##

DAV1D_MESON_ARGS = \
	-Denable_tools=false \
	-Denable_tests=false

$(eval $(call rules-source,dav1d,$(SRCDIR)/dav1d))
$(eval $(call rules-meson,dav1d,32))
$(eval $(call rules-meson,dav1d,64))


##
## gst-orc
##

GST_ORC_MESON_ARGS := \
	-Dorc-test=disabled

$(eval $(call rules-source,gst_orc,$(SRCDIR)/gst-orc))
$(eval $(call rules-meson,gst_orc,32))
$(eval $(call rules-meson,gst_orc,64))


##
## gstreamer
##

GSTREAMER_MESON_ARGS := \
	-Dgst_parse=false \
	-Dbenchmarks=disabled \
	-Dtools=disabled \
	-Dbash-completion=disabled

GSTREAMER_DEPENDS = gst_orc

$(eval $(call rules-source,gstreamer,$(SRCDIR)/gstreamer))
$(eval $(call rules-meson,gstreamer,32))
$(eval $(call rules-meson,gstreamer,64))


##
## gst-plugins-base
##

GST_BASE_MESON_ARGS := \
	-Dauto_features=disabled \
	-Dadder=enabled \
	-Dapp=enabled \
	-Daudioconvert=enabled \
	-Daudioresample=enabled \
	-Dogg=enabled \
	-Dopus=enabled \
	-Dpbtypes=enabled \
	-Dplayback=enabled \
	-Dtheora=enabled \
	-Dtypefind=enabled \
	-Dvideoconvert=enabled \
	-Dvideoscale=enabled \
	-Dvorbis=enabled \
	-Dorc=enabled

GST_BASE_DEPENDS = gst_orc gstreamer

$(eval $(call rules-source,gst_base,$(SRCDIR)/gst-plugins-base))
$(eval $(call rules-meson,gst_base,32))
$(eval $(call rules-meson,gst_base,64))


##
## gst-plugins-good
##

GST_GOOD_MESON_ARGS := \
	-Dauto_features=disabled \
	-Daudioparsers=enabled \
	-Dautodetect=enabled \
	-Davi=enabled \
	-Ddebugutils=enabled \
	-Ddeinterlace=enabled \
	-Disomp4=enabled \
	-Dmatroska=enabled \
	-Dmpg123=enabled \
	-Dvideobox=enabled \
	-Dvideofilter=enabled \
	-Dvpx=enabled \
	-Dwavparse=enabled \
	-Did3demux=enabled \
	-Dmpg123=enabled \
	-Dorc=enabled

GST_GOOD_DEPENDS = gst_orc gstreamer gst_base

$(eval $(call rules-source,gst_good,$(SRCDIR)/gst-plugins-good))
$(eval $(call rules-meson,gst_good,32))
$(eval $(call rules-meson,gst_good,64))

##
## FFmpeg
##

FFMPEG_CONFIGURE_ARGS := \
	--enable-shared \
	--disable-static \
	--disable-everything \
	--disable-programs \
	--disable-doc \

$(eval $(call rules-source,ffmpeg,$(SRCDIR)/ffmpeg))
$(eval $(call rules-configure,ffmpeg,32))
$(eval $(call rules-configure,ffmpeg,64))

## Only use ffmpeg to build gst-libav; we don't ship it.
$(OBJ)/.ffmpeg-dist32:
	touch $@
$(OBJ)/.ffmpeg-dist64:
	touch $@

##
## gst-libav
##

GST_LIBAV_DEPENDS = gst_orc gstreamer gst_base ffmpeg

$(eval $(call rules-source,gst_libav,$(SRCDIR)/gst-libav))
$(eval $(call rules-meson,gst_libav,32))
$(eval $(call rules-meson,gst_libav,64))


##
## gst-plugins-rs
##

GST_PLUGINS_RS_CARGO_ARGS = \
	-p gst-plugin-dav1d

GST_PLUGINS_RS_DEPENDS = gst_orc gstreamer gst_base dav1d

$(eval $(call rules-source,gst_plugins_rs,$(SRCDIR)/gst-plugins-rs))
$(eval $(call rules-cargo,gst_plugins_rs,32))
$(eval $(call rules-cargo,gst_plugins_rs,64))

$(OBJ)/.gst_plugins_rs-post-build64:
	mkdir -p $(GST_PLUGINS_RS_DST64)/lib64/gstreamer-1.0/
	cp -a $(GST_PLUGINS_RS_OBJ64)/x86_64-unknown-linux-gnu/release/libgstrsdav1d.so $(GST_PLUGINS_RS_DST64)/lib64/gstreamer-1.0/
	touch $@

$(OBJ)/.gst_plugins_rs-post-build32:
	mkdir -p $(GST_PLUGINS_RS_DST32)/lib/gstreamer-1.0/
	cp -a $(GST_PLUGINS_RS_OBJ32)/i686-unknown-linux-gnu/release/libgstrsdav1d.so $(GST_PLUGINS_RS_DST32)/lib/gstreamer-1.0/
	touch $@


##
## Vulkan-Headers
##

$(eval $(call rules-source,vulkan-headers,$(SRCDIR)/Vulkan-Headers))
$(eval $(call rules-cmake,vulkan-headers,32,CROSS))
$(eval $(call rules-cmake,vulkan-headers,64,CROSS))


##
## SPIRV-Headers
##

$(eval $(call rules-source,spirv-headers,$(SRCDIR)/SPIRV-Headers))
$(eval $(call rules-cmake,spirv-headers,32,CROSS))
$(eval $(call rules-cmake,spirv-headers,64,CROSS))


##
## Vulkan-Loader
##

VULKAN_LOADER_CMAKE_ARGS = -DUSE_MASM=OFF
VULKAN_LOADER_CMAKE_ARGS64 = -DVULKAN_HEADERS_INSTALL_DIR=$(VULKAN_HEADERS_DST64)
VULKAN_LOADER_CMAKE_ARGS32 = -DVULKAN_HEADERS_INSTALL_DIR=$(VULKAN_HEADERS_DST32)
VULKAN_LOADER_CFLAGS = -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00 # 0x0A00 is _WIN32_WINNT_WIN10
VULKAN_LOADER_DEPENDS = vulkan-headers spirv-headers

$(eval $(call rules-source,vulkan-loader,$(SRCDIR)/Vulkan-Loader))
$(eval $(call rules-cmake,vulkan-loader,32,CROSS))
$(eval $(call rules-cmake,vulkan-loader,64,CROSS))


##
## lsteamclient
##

LSTEAMCLIENT_CFLAGS = -Wno-attributes
LSTEAMCLIENT_CXXFLAGS = -Wno-attributes
LSTEAMCLIENT_LDFLAGS = -static-libgcc -static-libstdc++ -ldl

LSTEAMCLIENT_WINEMAKER_ARGS = \
	-DSTEAM_API_EXPORTS \
	-Dprivate=public \
	-Dprotected=public

LSTEAMCLIENT_DEPENDS = wine

$(eval $(call rules-source,lsteamclient,$(SRCDIR)/lsteamclient))
$(eval $(call rules-winemaker,lsteamclient,32,lsteamclient.dll))
$(eval $(call rules-winemaker,lsteamclient,64,lsteamclient.dll))


##

##
## openxr
## Note 32-bit is not supported by SteamVR, so we don't build it.
##

OPENXR_CMAKE_ARGS = -DHAVE_FILESYSTEM_WITHOUT_LIB=0

$(eval $(call rules-source,openxr,$(SRCDIR)/OpenXR-SDK))
# $(eval $(call rules-cmake,openxr,32))
$(eval $(call rules-cmake,openxr,64))


##
## wineopenxr
## Note 32-bit is not supported by SteamVR, so we don't build it.
##

WINEOPENXR_LDFLAGS = -lopenxr_loader -ldxgi -lvulkan

WINEOPENXR_DEPENDS = wine openxr

$(eval $(call rules-source,wineopenxr,$(SRCDIR)/wineopenxr))
# $(eval $(call rules-winemaker,wineopenxr,32,wineopenxr.dll))
$(eval $(call rules-winemaker,wineopenxr,64,wineopenxr.dll))

$(DIST_WINEOPENXR_JSON64): $(WINEOPENXR_SRC)/wineopenxr64.json dist_prefix
	mkdir -p $(dir $@)
	cp -a $< $@


##
## steam.exe
##

STEAMEXE_CFLAGS = -Wno-attributes
STEAMEXE_CXXFLAGS = -Wno-attributes
STEAMEXE_LDFLAGS = -L$(STEAMEXE_SRC)/32/ -L$(STEAMEXE_SRC)/64/ -lsteam_api -lole32 -ldl -static-libgcc -static-libstdc++

STEAMEXE_WINEMAKER_ARGS = \
	"-I$(SRC)/lsteamclient/steamworks_sdk_142/" \
	"-I$(SRC)/openvr/headers/" \
	"-L$(SRC)/steam_helper/"

STEAMEXE_DEPENDS = wine

$(eval $(call rules-source,steamexe,$(SRCDIR)/steam_helper))
$(eval $(call rules-winemaker,steamexe,64,steam.exe))
$(eval $(call rules-winemaker,steamexe,32,steam.exe))

$(OBJ)/.steamexe-post-build32:
	cp $(STEAMEXE_SRC)/32/libsteam_api.so $(DST_LIBDIR32)/
	touch $@

$(OBJ)/.steamexe-post-build64:
	cp $(STEAMEXE_SRC)/64/libsteam_api.so $(DST_LIBDIR64)/
	touch $@


##
## wine
##

WINE_SOURCE_ARGS = \
  --exclude configure \
  --exclude autom4te.cache \
  --exclude include/config.h.in \

WINE_CONFIGURE_ARGS = \
  --with-mingw \
  --disable-tests

WINE_CONFIGURE_ARGS64 = --enable-win64

WINE_DEPENDS = gst_orc gstreamer gst_base

$(eval $(call rules-source,wine,$(SRCDIR)/wine))
$(eval $(call rules-autoconf,wine,32))
$(eval $(call rules-autoconf,wine,64))

$(OBJ)/.wine-post-source:
	cd $(WINE_SRC) && tools/make_requests
	cd $(WINE_SRC) && dlls/winevulkan/make_vulkan -x vk.xml
	touch $@

$(OBJ)/.wine-post-build64:
	mkdir -p $(DST_DIR)/{bin,share}
	$(call install-strip,$(WINE_DST64)/bin/wine64,$(DST_DIR)/bin)
	$(call install-strip,$(WINE_DST64)/bin/wine64-preloader,$(DST_DIR)/bin)
	$(call install-strip,$(WINE_DST64)/bin/wineserver,$(DST_DIR)/bin)
	cp -a $(WINE_DST64)/share/wine $(DST_DIR)/share
	cp -a $(WINE_DST64)/bin/msidb $(DST_DIR)/bin
	touch $@

$(OBJ)/.wine-post-build32:
	mkdir -p $(DST_DIR)/bin
	$(call install-strip,$(WINE_DST32)/bin/wine,$(DST_DIR)/bin)
	$(call install-strip,$(WINE_DST32)/bin/wine-preloader,$(DST_DIR)/bin)
	touch $@


##
## vrclient
##

VRCLIENT_CFLAGS = -Wno-attributes
VRCLIENT_CXXFLAGS = -Wno-attributes
VRCLIENT_LDFLAGS = -static-libgcc -static-libstdc++ -ldl

VRCLIENT_WINEMAKER_ARGS = \
	"-I$(VRCLIENT_SRC)/" \
	"-I$(VRCLIENT_SRC)/vrclient_x64/"

VRCLIENT_DEPENDS = wine

$(eval $(call rules-source,vrclient,$(SRCDIR)/vrclient_x64))
$(eval $(call rules-winemaker,vrclient,32,vrclient.dll))
$(eval $(call rules-winemaker,vrclient,64,vrclient_x64.dll))

$(OBJ)/.vrclient-post-source:
	mkdir -p $(VRCLIENT_OBJ32) && cp -a $(VRCLIENT_SRC)/vrclient_x64/vrclient_x64.spec $(VRCLIENT_OBJ32)/vrclient.spec
	mkdir -p $(VRCLIENT_OBJ64) && cp -a $(VRCLIENT_SRC)/vrclient_x64/vrclient_x64.spec $(VRCLIENT_OBJ64)/vrclient_x64.spec
	touch $@


##
## dxvk
##

DXVK_MESON_ARGS32 = --bindir=$(DXVK_DST32)/lib/wine/dxvk
DXVK_MESON_ARGS64 = --bindir=$(DXVK_DST64)/lib64/wine/dxvk

$(eval $(call rules-source,dxvk,$(SRCDIR)/dxvk))
$(eval $(call rules-meson,dxvk,32,CROSS))
$(eval $(call rules-meson,dxvk,64,CROSS))

$(OBJ)/.dxvk-post-build64:
	mkdir -p "$(DST_DIR)"/lib64/wine/dxvk
	rm -f "$(DST_DIR)"/lib64/wine/dxvk/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- dxvk ) > "$(DST_DIR)"/lib64/wine/dxvk/version; fi
	touch $@

$(OBJ)/.dxvk-post-build32:
	mkdir -p "$(DST_DIR)"/lib/wine/dxvk
	rm -f "$(DST_DIR)"/lib/wine/dxvk/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- dxvk ) > "$(DST_DIR)"/lib/wine/dxvk/version; fi
	touch $@


##
## dxvk-nvapi
##

DXVK_NVAPI_MESON_ARGS32 = --bindir=$(DXVK_NVAPI_DST32)/lib/wine/nvapi
DXVK_NVAPI_MESON_ARGS64 = --bindir=$(DXVK_NVAPI_DST64)/lib64/wine/nvapi

$(eval $(call rules-source,dxvk-nvapi,$(SRCDIR)/dxvk-nvapi))
$(eval $(call rules-meson,dxvk-nvapi,32,CROSS))
$(eval $(call rules-meson,dxvk-nvapi,64,CROSS))

$(OBJ)/.dxvk-nvapi-post-build64:
	mkdir -p "$(DST_DIR)"/lib64/wine/nvapi
	rm -f "$(DST_DIR)"/lib64/wine/nvapi/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- dxvk-nvapi ) > "$(DST_DIR)"/lib64/wine/nvapi/version; fi
	touch $@

$(OBJ)/.dxvk-nvapi-post-build32:
	mkdir -p "$(DST_DIR)"/lib/wine/nvapi
	rm -f "$(DST_DIR)"/lib/wine/nvapi/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- dxvk-nvapi ) > "$(DST_DIR)"/lib/wine/nvapi/version; fi
	touch $@


##
## vkd3d
##

VKD3D_SOURCE_ARGS = \
  --exclude aclocal.m4 \
  --exclude autom4te.cache \
  --exclude bin/ \
  --exclude configure \
  --exclude include/config.h.in \
  --exclude Makefile.in \
  --exclude m4/libtool.m4 \
  --exclude m4/ltoptions.m4 \
  --exclude m4/ltsugar.m4 \
  --exclude m4/ltversion.m4 \
  --exclude m4/lt~obsolete.m4 \

VKD3D_CONFIGURE_ARGS = \
  --disable-doxygen-doc \
  --disable-tests \
  --disable-demos \
  --without-ncurses \

VKD3D_LDFLAGS = -static-libgcc $(CROSSLDFLAGS)
VKD3D_DEPENDS = vulkan-loader vulkan-headers spirv-headers

$(eval $(call rules-source,vkd3d,$(SRCDIR)/vkd3d))
$(eval $(call rules-autoconf,vkd3d,32,CROSS))
$(eval $(call rules-autoconf,vkd3d,64,CROSS))

$(OBJ)/.vkd3d-post-build64:
	mkdir -p $(DST_DIR)/lib64/vkd3d/
	$(call install-strip,$(VKD3D_DST64)/bin/libvkd3d-shader-1.dll,$(DST_LIBDIR64)/vkd3d)
	touch $@

$(OBJ)/.vkd3d-post-build32:
	mkdir -p $(DST_DIR)/lib/vkd3d/
	$(call install-strip,$(VKD3D_DST32)/bin/libvkd3d-shader-1.dll,$(DST_LIBDIR32)/vkd3d)
	touch $@

##
## vkd3d-proton
##

VKD3D_PROTON_SOURCE_ARGS = \
  --exclude vkd3d_build.h.in \
  --exclude vkd3d_version.h.in \

VKD3D_PROTON_MESON_ARGS32 = --bindir=$(VKD3D_PROTON_DST32)/lib/wine/vkd3d-proton
VKD3D_PROTON_MESON_ARGS64 = --bindir=$(VKD3D_PROTON_DST64)/lib64/wine/vkd3d-proton

$(eval $(call rules-source,vkd3d-proton,$(SRCDIR)/vkd3d-proton))
$(eval $(call rules-meson,vkd3d-proton,32,CROSS))
$(eval $(call rules-meson,vkd3d-proton,64,CROSS))

$(OBJ)/.vkd3d-proton-post-source:
	sed -re 's#@VCS_TAG@#$(shell git -C $(SRCDIR)/vkd3d-proton describe --always --exclude=* --abbrev=15 --dirty=0)#' \
	    $(SRCDIR)/vkd3d-proton/vkd3d_build.h.in > $(VKD3D_PROTON_SRC)/vkd3d_build.h.in
	sed -re 's#@VCS_TAG@#$(shell git -C $(SRCDIR)/vkd3d-proton describe --always --tags --dirty=+)#' \
	    $(SRCDIR)/vkd3d-proton/vkd3d_version.h.in > $(VKD3D_PROTON_SRC)/vkd3d_version.h.in
	touch $@

$(OBJ)/.vkd3d-proton-post-build32:
	mkdir -p "$(DST_DIR)"/lib/wine/vkd3d-proton
	rm -f "$(DST_DIR)"/lib/wine/vkd3d-proton/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- vkd3d-proton ) > "$(DST_DIR)"/lib/wine/vkd3d-proton/version; fi
	touch $@

$(OBJ)/.vkd3d-proton-post-build64:
	mkdir -p "$(DST_DIR)"/lib64/wine/vkd3d-proton
	rm -f "$(DST_DIR)"/lib64/wine/vkd3d-proton/version && if test -e $(SRCDIR)/.git; then ( cd $(SRCDIR) && git submodule status -- vkd3d-proton ) > "$(DST_DIR)"/lib64/wine/vkd3d-proton/version; fi
	touch $@



##
## mediaconv
##

MEDIACONV_DEPENDS = gst_orc gstreamer gst_base

$(eval $(call rules-source,mediaconv,$(SRCDIR)/media-converter))
$(eval $(call rules-cargo,mediaconv,32))
$(eval $(call rules-cargo,mediaconv,64))

$(OBJ)/.mediaconv-post-build64:
	mkdir -p $(MEDIACONV_DST64)/lib64/gstreamer-1.0/
	cp -a $(MEDIACONV_OBJ64)/x86_64-unknown-linux-gnu/release/libprotonmediaconverter.so $(MEDIACONV_DST64)/lib64/gstreamer-1.0/
	touch $@

$(OBJ)/.mediaconv-post-build32:
	mkdir -p $(MEDIACONV_DST32)/lib/gstreamer-1.0/
	cp -a $(MEDIACONV_OBJ32)/i686-unknown-linux-gnu/release/libprotonmediaconverter.so $(MEDIACONV_DST32)/lib/gstreamer-1.0/
	touch $@


##
## BattlEye Bridge
##

ifneq ($(wildcard $(SRCDIR)/battleye-bridge/.*),)

BATTLEYE_LDFLAGS = -static-libgcc -static-libstdc++ -ldl

BATTLEYE_DEPENDS = wine

$(eval $(call rules-source,battleye,$(SRCDIR)/battleye-bridge))
$(eval $(call rules-winemaker,battleye,32,beclient.dll))
$(eval $(call rules-winemaker,battleye,64,beclient_x64.dll))

$(OBJ)/.battleye-post-source:
	mkdir -p $(BATTLEYE_OBJ32) && cp -a $(BATTLEYE_SRC)/beclient.spec $(BATTLEYE_OBJ32)/beclient.spec
	mkdir -p $(BATTLEYE_OBJ64) && cp -a $(BATTLEYE_SRC)/beclient.spec $(BATTLEYE_OBJ64)/beclient_x64.spec
	touch $@

$(OBJ)/.battleye-post-build64:
	mkdir -p $(OBJ)/dist-battleye/v1
	cp -r $(BATTLEYE_DST64)/* $(OBJ)/dist-battleye/v1/
	rm -rf $(BATTLEYE_DST64)/*
	touch $@

$(OBJ)/.battleye-post-build32:
	mkdir -p $(OBJ)/dist-battleye/v1
	cp -r $(BATTLEYE_DST32)/* $(OBJ)/dist-battleye/v1/
	rm -rf $(BATTLEYE_DST32)/*
	touch $@

endif

##
## EasyAntiCheat Bridge
##

ifneq ($(wildcard $(SRCDIR)/eac-bridge/.*),)

EAC_DEPENDS = wine

$(eval $(call rules-source,eac,$(SRCDIR)/eac-bridge))
$(eval $(call create-rules-common,eac,EAC,64))
$(eval $(call create-rules-common,eac,EAC,32))


$(OBJ)/.eac-build64:
	@echo ":: building 64bit eac..." >&2
	rsync -arx "$(EAC_SRC)/" "$(EAC_OBJ64)/"
	env $(EAC_ENV64) \
	$(MAKE) -C "$(EAC_OBJ64)" WINE_OBJ="$(WINE_OBJ64)" HOST="x86_64-w64-mingw32" CROSSCXX="x86_64-w64-mingw32-g++" BIT="64"
	mkdir -p $(OBJ)/dist-eac/v2/lib64
	$(call install-strip,$(EAC_OBJ64)/easyanticheat.so,$(OBJ)/dist-eac/v2/lib64)
	$(call install-strip,$(EAC_OBJ64)/easyanticheat.dll,$(OBJ)/dist-eac/v2/lib64)
	cp $(OBJ)/dist-eac/v2/lib64/easyanticheat.so $(OBJ)/dist-eac/v2/lib64/easyanticheat_x64.so
	cp $(OBJ)/dist-eac/v2/lib64/easyanticheat.dll $(OBJ)/dist-eac/v2/lib64/easyanticheat_x64.dll
	touch $@

$(OBJ)/.eac-build32:
	@echo ":: building 32bit eac..." >&2
	rsync -arx "$(EAC_SRC)/" "$(EAC_OBJ32)/"
	env $(EAC_ENV32) \
	$(MAKE) -C "$(EAC_OBJ32)" WINE_OBJ="$(WINE_OBJ32)" HOST="i686-w64-mingw32" CROSSCXX="i686-w64-mingw32-g++" BIT="32"
	mkdir -p $(OBJ)/dist-eac/v2/lib32
	$(call install-strip,$(EAC_OBJ32)/easyanticheat.so,$(OBJ)/dist-eac/v2/lib32)
	$(call install-strip,$(EAC_OBJ32)/easyanticheat.dll,$(OBJ)/dist-eac/v2/lib32)
	mv $(OBJ)/dist-eac/v2/lib32/easyanticheat.so $(OBJ)/dist-eac/v2/lib32/easyanticheat_x86.so
	mv $(OBJ)/dist-eac/v2/lib32/easyanticheat.dll $(OBJ)/dist-eac/v2/lib32/easyanticheat_x86.dll
	touch $@

endif

ALL_TARGETS += fonts
GOAL_TARGETS += fonts

.PHONY: fonts

FONTFORGE = fontforge -quiet
FONTSCRIPT = $(FONTS)/scripts/generatefont.pe
MERGEFONTSSCRIPT = $(FONTS)/scripts/mergefonts.pe

LIBERATION_SRCDIR = $(FONTS)/liberation-fonts/src
SOURCE_HAN_SANS_SRCDIR = $(FONTS)/source-han-sans
UME_DIR = $(FONTS)/ume

msyh.ttf_CIDFONT = $(SOURCE_HAN_SANS_SRCDIR)/cidfont.ps.OTC.SC
msyh.ttf_FEATURES = $(SOURCE_HAN_SANS_SRCDIR)/features.OTC.SC
msyh.ttf_SEQUENCES = $(SOURCE_HAN_SANS_SRCDIR)/SourceHanSans_CN_sequences.txt
msyh.ttf_UNISOURCE = $(SOURCE_HAN_SANS_SRCDIR)/UniSourceHanSansCN-UTF32-H
msyh.ttf_MENUNAMEDB = $(FONTS)/patches/YaHei-FontMenuNameDB
msyh.ttf = $(FONTS_OBJ)/source-han/msyh.ttf

simsun.ttf_CIDFONT = $(SOURCE_HAN_SANS_SRCDIR)/cidfont.ps.OTC.SC
simsun.ttf_FEATURES = $(SOURCE_HAN_SANS_SRCDIR)/features.OTC.SC
simsun.ttf_SEQUENCES = $(SOURCE_HAN_SANS_SRCDIR)/SourceHanSans_CN_sequences.txt
simsun.ttf_UNISOURCE = $(SOURCE_HAN_SANS_SRCDIR)/UniSourceHanSansCN-UTF32-H
simsun.ttf_MENUNAMEDB = $(FONTS)/patches/SimSun-FontMenuNameDB
simsun.ttf = $(FONTS_OBJ)/source-han/simsun.ttf

nsimsun.ttf_CIDFONT = $(SOURCE_HAN_SANS_SRCDIR)/cidfont.ps.OTC.SC
nsimsun.ttf_FEATURES = $(SOURCE_HAN_SANS_SRCDIR)/features.OTC.SC
nsimsun.ttf_SEQUENCES = $(SOURCE_HAN_SANS_SRCDIR)/SourceHanSans_CN_sequences.txt
nsimsun.ttf_UNISOURCE = $(SOURCE_HAN_SANS_SRCDIR)/UniSourceHanSansCN-UTF32-H
nsimsun.ttf_MENUNAMEDB = $(FONTS)/patches/NSimSun-FontMenuNameDB
nsimsun.ttf = $(FONTS_OBJ)/source-han/nsimsun.ttf

msgothic.ttf_FONT = $(UME_DIR)/ume-tgo4.ttf
msgothic.ttf_NAMETABLE_PATCH = $(FONTS)/patches/UmeGothic-nametable.patch
msgothic.ttf = $(FONTS_OBJ)/ume-gothic/msgothic.ttf

mspgothic.ttf_FONT = $(UME_DIR)/ume-pgo4.ttf
mspgothic.ttf_NAMETABLE_PATCH = $(FONTS)/patches/UmePGothic-nametable.patch
mspgothic.ttf = $(FONTS_OBJ)/ume-gothic/mspgothic.ttf

msuigothic.ttf_FONT = $(UME_DIR)/ume-ugo4.ttf
msuigothic.ttf_NAMETABLE_PATCH = $(FONTS)/patches/UmeUIGothic-nametable.patch
msuigothic.ttf = $(FONTS_OBJ)/ume-gothic/msuigothic.ttf

malgun.ttf_CIDFONT = $(SOURCE_HAN_SANS_SRCDIR)/cidfont.ps.OTC.K
malgun.ttf_FEATURES = $(SOURCE_HAN_SANS_SRCDIR)/features.OTC.K
malgun.ttf_SEQUENCES = $(SOURCE_HAN_SANS_SRCDIR)/SourceHanSans_KR_sequences.txt
malgun.ttf_UNISOURCE = $(SOURCE_HAN_SANS_SRCDIR)/UniSourceHanSansKR-UTF32-H
malgun.ttf_MENUNAMEDB = $(FONTS)/patches/Malgun-FontMenuNameDB
malgun.ttf = $(FONTS_OBJ)/source-han/malgun.ttf

simsun.ttc = $(FONTS_OBJ)/source-han/simsun.ttc
msgothic.ttc = $(FONTS_OBJ)/ume-gothic/msgothic.ttc

noto_sans.ttf = $(FONTS)/noto/NotoSans-Regular.ttf
noto_sans_arabic.ttf = $(FONTS)/noto/NotoSansArabic-Regular.ttf
noto_sans_armenian.tff = $(FONTS)/noto/NotoSansArmenian-Regular.ttf
noto_sans_bengali.ttf = $(FONTS)/noto/NotoSansBengali-Regular.ttf
noto_sans_coptic.ttf = $(FONTS)/noto/NotoSansCoptic-Regular.ttf
noto_sans_georgian.ttf = $(FONTS)/noto/NotoSansGeorgian-Regular.ttf
noto_sans_gujarati.ttf = $(FONTS)/noto/NotoSansGujarati-Regular.ttf
noto_sans_hebrew.ttf = $(FONTS)/noto/NotoSansHebrew-Regular.ttf
noto_sans_khmer.ttf = $(FONTS)/noto/NotoSansKhmer-Regular.ttf
noto_sans_tamil.ttf = $(FONTS)/noto/NotoSansTamil-Regular.ttf
noto_sans_thaana.ttf = $(FONTS)/noto/NotoSansThaana-Regular.ttf
noto_sans_thai.ttf = $(FONTS)/noto/NotoSansThai-Regular.ttf
micross.ttf = $(FONTS_OBJ)/micross.ttf

noto_sans_bengaliui.ttf = $(FONTS)/noto/NotoSansBengaliUI-Regular.ttf
noto_sans_devanagariui.ttf = $(FONTS)/noto/NotoSansDevanagariUI-Regular.ttf
noto_sans_gujaratiui.ttf = $(FONTS)/noto/NotoSansGujaratiUI-Regular.ttf
noto_sans_gurmukhiui.ttf = $(FONTS)/noto/NotoSansGurmukhiUI-Regular.ttf
noto_sans_kannadaui.ttf = $(FONTS)/noto/NotoSansKannadaUI-Regular.ttf
noto_sans_malayalamui.ttf = $(FONTS)/noto/NotoSansMalayalamUI-Regular.ttf
noto_sans_meeteimayek.ttf = $(FONTS)/noto/NotoSansMeeteiMayek-Regular.ttf
noto_sans_olchiki.ttf = $(FONTS)/noto/NotoSansOlChiki-Regular.ttf
noto_sans_oriyaui.ttf = $(FONTS)/noto/NotoSansOriyaUI-Regular.ttf
noto_sans_sinhalaui.ttf = $(FONTS)/noto/NotoSansSinhalaUI-Regular.ttf
noto_sans_sorasompeng.ttf = $(FONTS)/noto/NotoSansSoraSompeng-Regular.ttf
noto_sans_tamilui.ttf = $(FONTS)/noto/NotoSansTamilUI-Regular.ttf
noto_sans_teluguui.ttf = $(FONTS)/noto/NotoSansTeluguUI-Regular.ttf
nirmala.ttf = $(FONTS_OBJ)/nirmala.ttf

#The use of "Arial" here is for compatibility with programs that require that exact string. This font is not Arial.
LiberationSans-Regular_NAMES := "Arial" "Arial" "Arial"
#The use of "Arial" here is for compatibility with programs that require that exact string. This font is not Arial.
LiberationSans-Bold_NAMES := "Arial-Bold" "Arial" "Arial Bold"
#The use of "Times New Roman" here is for compatibility with programs that require that exact string. This font is not Times New Roman.
LiberationSerif-Regular_NAMES := "TimesNewRoman" "Times New Roman" "Times New Roman"
#The use of "Courier New" here is for compatibility with programs that require that exact string. This font is not Courier New.
LiberationMono-Regular_NAMES := "CourierNew" "Courier New" "Courier New"
LiberationMono-Regular_PATCH := $(FONTS)/patches/LiberationMono-Regular.patch
#The use of "Courier New" here is for compatibility with programs that require that exact string. This font is not Courier New.
LiberationMono-Bold_NAMES := "CourierNewPS-BoldMT" "Courier New" "Courier New Bold"

$(FONTS_OBJ):
	mkdir -p $@

ifeq ($(CONTAINER),)
fonts: container-build # trigger container build

$(FONTS_OBJ)/%.ttf: $(FONTS_OBJ)/%.sfd $(FONTSCRIPT) | $(FONTS_OBJ)
	$(FONTFORGE) -script $(FONTSCRIPT) $< $($(*)_NAMES)

$(FONTS_OBJ)/%.sfd: $(LIBERATION_SRCDIR)/%.sfd | $(FONTS_OBJ)
	patch $< -o $@ $(firstword $($(*)_PATCH) /dev/null)

# fonts below need a newer fontforge version then the one in the container
fonts: $(FONTS_OBJ)/LiberationSans-Regular.ttf
fonts: $(FONTS_OBJ)/LiberationSans-Bold.ttf
fonts: $(FONTS_OBJ)/LiberationSerif-Regular.ttf
fonts: $(FONTS_OBJ)/LiberationMono-Regular.ttf
fonts: $(FONTS_OBJ)/LiberationMono-Bold.ttf
else # ifeq ($(CONTAINER),)
#The use of "YaHei" for compatibility with programs that require that exact string. This font is not Microsoft YaHei.
$(FONTS_OBJ)/source-han/%.ttf: $$(%.ttf_CIDFONT) $$(%.ttf_FEATURES) $$(%.ttf_SEQUENCES) $$(%.ttf_UNISOURCE) $$(%.ttf_MENUNAMEDB)
	mkdir -p $(FONTS_OBJ)/source-han
	# Do not immediately create the target file, so that make is interrupted
	# it will restart again
	afdko makeotfexe -f $($(notdir $@)_CIDFONT) -omitMacNames -ff $($(notdir $@)_FEATURES) \
		-lic ADOBE -mf $($(notdir $@)_MENUNAMEDB) -r -nS -cs 25 -ch $($(notdir $@)_UNISOURCE) \
		-ci $($(notdir $@)_SEQUENCES) -o $@.tmp
	afdko tx -cff +S -no_futile $($(notdir $@)_CIDFONT) $@.cff
	# sftnedit uses a hardcoded temporary file in the local directory, so we have
	# to run it in a dedicated temporary directory to prevent concurrent instances
	# to step onto each other's feet
	(TEMP_DIR=`mktemp -d` && cd $$TEMP_DIR && afdko sfntedit -a CFF=$(abspath $($(notdir $@)).cff) $(abspath $@.tmp) && rm -fr $$TEMP_DIR)
	mv $@.tmp $@

$(FONTS_OBJ)/ume-gothic/%.ttf: $$(%.ttf_FONT) $$(%.ttf_NAMETABLE_PATCH)
	mkdir -p $(FONTS_OBJ)/ume-gothic
	ttx -o $(FONTS_OBJ)/ume-gothic/$(notdir $(basename $($(notdir $@)_NAMETABLE_PATCH))).ttx -t name $($(notdir $@)_FONT)
	patch $(FONTS_OBJ)/ume-gothic/$(notdir $(basename $($(notdir $@)_NAMETABLE_PATCH))).ttx $($(notdir $@)_NAMETABLE_PATCH)
	ttx -o $@ -m $($(notdir $@)_FONT) $(FONTS_OBJ)/ume-gothic/$(notdir $(basename $($(notdir $@)_NAMETABLE_PATCH))).ttx

$(simsun.ttc): $(simsun.ttf) $(nsimsun.ttf)
	afdko otf2otc -o $@ $^

$(msgothic.ttc): $(msgothic.ttf) $(mspgothic.ttf) $(msuigothic.ttf)
	afdko otf2otc -o $@ $^

$(micross.ttf): $(noto_sans.ttf) $(noto_sans_arabic.ttf) $(noto_sans_armenian.ttf) $(noto_sans_bengali.ttf) $(noto_sans_coptic.ttf) \
		$(noto_sans_georgian.ttf) $(noto_sans_gujarati.ttf) $(noto_sans_hebrew.ttf) $(noto_sans_khmer.ttf) $(noto_sans_tamil.ttf) \
		$(noto_sans_thaana.ttf) $(noto_sans_thai.ttf)
	$(FONTFORGE) -script $(MERGEFONTSSCRIPT) $(noto_sans.ttf) $(noto_sans_arabic.ttf) $(noto_sans_armenian.ttf) $(noto_sans_bengali.ttf) \
		$(noto_sans_coptic.ttf) $(noto_sans_georgian.ttf) $(noto_sans_gujarati.ttf) $(noto_sans_hebrew.ttf) $(noto_sans_khmer.ttf) \
		$(noto_sans_tamil.ttf) $(noto_sans_thaana.ttf) $(noto_sans_thai.ttf) "MicrosoftSansSerif" "Microsoft Sans Serif" "Regular" $(micross.ttf)

$(nirmala.ttf): $(noto_sans.ttf) $(noto_sans_bengaliui.ttf) $(noto_sans_devanagariui.ttf) $(noto_sans_gujaratiui.ttf) $(noto_sans_gurmukhiui.ttf) \
		$(noto_sans_kannadaui.ttf) $(noto_sans_malayalamui.ttf) $(noto_sans_meeteimayek.ttf) $(noto_sans_olchiki.ttf) $(noto_sans_oriyaui.ttf) \
		$(noto_sans_sinhalaui.ttf) $(noto_sans_sorasompeng.ttf) $(noto_sans_tamilui.ttf) $(noto_sans_teluguui.ttf)
	$(FONTFORGE) -script $(MERGEFONTSSCRIPT) $(noto_sans.ttf) $(noto_sans_bengaliui.ttf) $(noto_sans_devanagariui.ttf) $(noto_sans_gujaratiui.ttf) \
		$(noto_sans_gurmukhiui.ttf) $(noto_sans_kannadaui.ttf) $(noto_sans_malayalamui.ttf) $(noto_sans_meeteimayek.ttf) $(noto_sans_olchiki.ttf) \
		$(noto_sans_oriyaui.ttf) $(noto_sans_sinhalaui.ttf) $(noto_sans_sorasompeng.ttf) $(noto_sans_tamilui.ttf) $(noto_sans_teluguui.ttf) \
		"NirmalaUI" "Nirmala UI" "Regular" $(nirmala.ttf)

fonts: $(msyh.ttf)
fonts: $(simsun.ttc)
fonts: $(msgothic.ttc)
fonts: $(malgun.ttf)
fonts: $(micross.ttf)
fonts: $(nirmala.ttf)
endif # ifeq ($(CONTAINER),)

##
## Targets
##

ifeq ($(CONTAINER),)
.PHONY: all all64 all32 default help targets

# Produce a working dist directory by default
default: all dist
.DEFAULT_GOAL := default

# For suffixes 64/32/_configure64/_configure32 automatically check if they exist compared to ALL_TARGETS and make
# all_configure32/etc aliases
GOAL_TARGETS64           := $(filter $(addsuffix 64,$(GOAL_TARGETS)),$(ALL_TARGETS))
GOAL_TARGETS32           := $(filter $(addsuffix 32,$(GOAL_TARGETS)),$(ALL_TARGETS))
GOAL_TARGETS_LIBS64      := $(filter $(addsuffix 64,$(GOAL_TARGETS_LIBS)),$(ALL_TARGETS))
GOAL_TARGETS_LIBS32      := $(filter $(addsuffix 32,$(GOAL_TARGETS_LIBS)),$(ALL_TARGETS))
GOAL_TARGETS_CONFIGURE   := $(filter $(addsuffix _configure,$(GOAL_TARGETS)),$(ALL_TARGETS))
GOAL_TARGETS_CONFIGURE64 := $(filter $(addsuffix _configure64,$(GOAL_TARGETS)),$(ALL_TARGETS))
GOAL_TARGETS_CONFIGURE32 := $(filter $(addsuffix _configure32,$(GOAL_TARGETS)),$(ALL_TARGETS))

# Anything in all-targets that didn't end up in here
OTHER_TARGETS := $(filter-out $(ALL_TARGETS),$(GOAL_TARGETS) $(GOAL_TARGETS64) $(GOAL_TARGETS32) \
                                             $(GOAL_TARGETS_LIBS64) $(GOAL_TARGETS_LIBS32) $(GOAL_TARGETS_CONFIGURE) \
                                             $(GOAL_TARGETS_CONFIGURE64) $(GOAL_TARGETS_CONFIGURE32))

help: targets
targets:
	$(info Default targets      (make all):              $(strip $(GOAL_TARGETS)))
	$(info Default targets      (make all_lib):          $(strip $(GOAL_TARGETS_LIBS)))
	$(info Default targets      (make all_configure):    $(strip $(GOAL_TARGETS_CONFIGURE)))
	$(info Default targets      (make all64):            $(strip $(GOAL_TARGETS64)))
	$(info Default targets      (make all32):            $(strip $(GOAL_TARGETS32)))
	$(info Default targets      (make all64_lib):        $(strip $(GOAL_TARGETS_LIBS64)))
	$(info Default targets      (make all32_lib):        $(strip $(GOAL_TARGETS_LIBS32)))
	$(info Reconfigure targets  (make all64_configure):  $(strip $(GOAL_TARGETS_CONFIGURE64)))
	$(info Reconfigure targets  (make all32_configure):  $(strip $(GOAL_TARGETS_CONFIGURE32)))
	$(info Other targets:    $(OTHER_TARGETS))

# All target
all: $(GOAL_TARGETS)
	@echo ":: make $@ succeeded"

all32: $(GOAL_TARGETS32)
	@echo ":: make $@ succeeded"

all64: $(GOAL_TARGETS64)
	@echo ":: make $@ succeeded"

# Libraries (not wine) only -- wine has a length install step that runs unconditionally, so this is useful for updating
# incremental builds when not iterating on wine itself.
all_lib: $(GOAL_TARGETS_LIBS)
	@echo ":: make $@ succeeded"

all32_lib: $(GOAL_TARGETS_LIBS32)
	@echo ":: make $@ succeeded"

all64_lib: $(GOAL_TARGETS_LIBS64)
	@echo ":: make $@ succeeded"

# Explicit reconfigure all targets
all_configure: $(GOAL_TARGETS_CONFIGURE)
	@echo ":: make $@ succeeded"

all32_configure: $(GOAL_TARGETS_CONFIGURE32)
	@echo ":: make $@ succeeded"

all64_configure: $(GOAL_TARGETS_CONFIGURE64)
	@echo ":: make $@ succeeded"

endif # ifeq ($(CONTAINER),)
endif # End of NESTED_MAKE from beginning