Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1136 lines (1075 loc) · 55.3 KB
/
Copy pathMakefile
File metadata and controls
1136 lines (1075 loc) · 55.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
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
# ---- Toolchain ----
# Cross-compile to ARM 32-bit (armv7-a / armhf) with `make ARM=1`. Picks
# the standard Debian/Ubuntu cross-toolchain prefix; override with
# `make ARM=1 CC=...` if your distro uses a different name. The build
# expects libsdl2-dev:armhf installed (or a sysroot containing SDL2),
# discoverable via `arm-linux-gnueabihf-pkg-config`. The Amiga struct
# size_check[] asserts assume 32-bit pointers, which armhf already
# provides — no -m32 needed.
#
# Cross-compile to ARM 64-bit (aarch64) with `make ARM64=1`. Picks
# `aarch64-linux-gnu-gcc`; needs libsdl2-dev:arm64 (Debian/Ubuntu
# foreign-arch) or a sysroot. 64-bit pointers mean the static
# size_check[] asserts that hard-code Amiga (32-bit) struct sizes
# will fail to compile until Phase 5 / 6 of the 64-bit transition.
# Useful right now as a "what still hard-codes 32-bit" checklist.
#
# macOS: auto-detected via `uname -s == Darwin`. Native clang; expects
# SDL2 from Homebrew (`brew install sdl2`). Like ARM64, modern macOS
# is 64-bit, so the same Phase 5 / 6 constraints apply.
ifdef WASM
# WebAssembly via Emscripten (`make WASM=1`). `source <emsdk>/emsdk_env.sh`
# first so emcc is on PATH. SDL2 comes from emcc's bundled port (-sUSE_SDL=2),
# NOT pkg-config. Single-threaded + ASYNCIFY — see docs/WASM.md.
CC := emcc
CXX := em++
PKGCONF := true
# Verify-on reloads the career into live globals on every save (corrupts live
# state) — pointless in the browser; default off (command line still overrides).
SWOS_SAVE_FORMAT_JSON_VERIFY ?= 0
else ifdef ARM64
ARM64_HOST_MACHINE := $(shell uname -m)
ifneq (,$(filter aarch64 arm64,$(ARM64_HOST_MACHINE)))
CC := gcc
PKGCONF := pkg-config
else
CC := aarch64-linux-gnu-gcc
CXX := aarch64-linux-gnu-g++ # (NETPLAY=1: GGPO-X is C++ -- the PortMaster port's online play)
PKGCONF := PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig pkg-config
endif
else ifdef ARM
# Native ARM builds (e.g. on a Raspberry Pi) use the system gcc.
# Cross-builds from x86_64 → armhf use the standard Debian/Ubuntu
# arm-linux-gnueabihf- toolchain. Detect by host architecture; user
# can override with `make ARM=1 CC=...` if the distro's prefix is
# different.
ARM_HOST_MACHINE := $(shell uname -m)
ifneq (,$(filter arm% aarch64,$(ARM_HOST_MACHINE)))
CC := gcc
PKGCONF := pkg-config
else
CC := arm-linux-gnueabihf-gcc
# Ubuntu/Debian don't ship an arm-linux-gnueabihf-pkg-config wrapper —
# use the regular pkg-config but force it to look at the armhf
# pkgconfig directory only (PKG_CONFIG_LIBDIR overrides the default
# /usr/lib/pkgconfig:/usr/share/pkgconfig search path that would
# otherwise return amd64 SDL2 paths). libsdl2-dev:armhf installs its
# .pc into /usr/lib/arm-linux-gnueabihf/pkgconfig.
PKGCONF := PKG_CONFIG_LIBDIR=/usr/lib/arm-linux-gnueabihf/pkgconfig pkg-config
endif
else
# Default: native compiler (gcc on Linux/MinGW/Cygwin, clang on macOS).
ifeq ($(shell uname -s),Darwin)
CC := cc
# SDL2 search order on macOS:
# 1. SDL2.framework in /Library/Frameworks, ~/Library/Frameworks,
# /opt/homebrew/Frameworks, or /usr/local/Frameworks. Preferred
# because the official libsdl.org build ships as a universal
# binary — needed for `make macos-universal`.
# 2. Homebrew's SDL2 via pkg-config (single-arch only).
SDL2_MACOS_FW :=
ifneq (,$(wildcard /Library/Frameworks/SDL2.framework))
SDL2_MACOS_FW := /Library/Frameworks
else ifneq (,$(wildcard $(HOME)/Library/Frameworks/SDL2.framework))
SDL2_MACOS_FW := $(HOME)/Library/Frameworks
else ifneq (,$(wildcard /opt/homebrew/Frameworks/SDL2.framework))
SDL2_MACOS_FW := /opt/homebrew/Frameworks
else ifneq (,$(wildcard /usr/local/Frameworks/SDL2.framework))
SDL2_MACOS_FW := /usr/local/Frameworks
endif
ifndef SDL2_MACOS_FW
# Homebrew SDL2 lives under /opt/homebrew (arm64) or /usr/local (intel).
PKGCONF := PKG_CONFIG_PATH=$(shell brew --prefix sdl2 2>/dev/null)/lib/pkgconfig pkg-config
endif
else
CC := gcc
endif
endif
SHELL := /bin/bash
# ---- Platform ----
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
MACOS_ARCH ?= $(shell uname -m)
# Normalize an arch string for the build/<os>/<arch> object dir so the same
# 64-bit ARM target is "arm64" on every OS (Linux uname says aarch64, macOS/
# Windows say arm64) and 32-bit x86 is "x86": $(call norm_arch,aarch64) -> arm64.
norm_arch = $(patsubst aarch64,arm64,$(patsubst amd64,x86_64,$(patsubst i686,x86,$(patsubst i386,x86,$(1)))))
# ---- Output ----
# Each branch sets TARGET_NAME (the bin/ binary name) AND the BUILD_OS /
# BUILD_ARCH that select the build/<os>/<arch> object dir.
ifdef WASM
# emcc emits SWOS.html + SWOS.js + SWOS.wasm + SWOS.data (the preloaded data
# package). Objects live under build/emscripten/wasm (wasm32 = ILP32).
TARGET_NAME := SWOS.html
BUILD_OS := emscripten
BUILD_ARCH := wasm
# PLAYER=1: the recordings player for the server's /playback/ page -- the same game,
# its own page (wasm/player.html) and objects, and no netplay (docs/PLAYBACK.md).
ifdef PLAYER
BUILD_ARCH := wasm-player
endif
else ifeq ($(OS),Windows_NT)
TARGET_NAME := SWOS.exe
BUILD_OS := windows
BUILD_ARCH := $(call norm_arch,$(UNAME_M))
else ifneq (,$(findstring CYGWIN,$(UNAME_S)))
# uname -s on Cygwin outputs `CYGWIN_NT-10.0-22631` (or similar with
# the Windows build number suffix), not bare `CYGWIN_NT`. Use
# `findstring` so the version suffix doesn't break detection.
TARGET_NAME := SWOS.exe
BUILD_OS := windows
BUILD_ARCH := $(call norm_arch,$(UNAME_M))
else ifneq (,$(findstring MINGW,$(UNAME_S)))
# Same suffix issue for MSYS2 MINGW32_NT-X.Y / MINGW64_NT-X.Y.
TARGET_NAME := SWOS.exe
BUILD_OS := windows
BUILD_ARCH := $(call norm_arch,$(UNAME_M))
else ifdef ARM64
TARGET_NAME := SWOS.aarch64
BUILD_OS := linux
BUILD_ARCH := arm64
else ifdef ARM
# Distinguish the cross-built ARM binary so it doesn't overwrite a
# native x86 bin/SWOS in the same checkout. Native ARM builds (on a
# Pi) also get the .armhf suffix — `file bin/SWOS.armhf` confirms the
# ELF arch either way.
TARGET_NAME := SWOS.armhf
BUILD_OS := linux
BUILD_ARCH := armhf
else ifdef X86_64
# Linux x86_64 explicit build (drops the default -m32 so the binary
# is 64-bit LP64 — matches what the macOS / aarch64 / cygwin64
# targets already produce). The size_check[] asserts are gated on
# UINTPTR_MAX so they pick up the 64-bit struct sizes correctly.
TARGET_NAME := SWOS.x86_64
BUILD_OS := linux
BUILD_ARCH := x86_64
else ifeq ($(UNAME_S),Darwin)
TARGET_NAME := SWOS.macos
BUILD_OS := macos
BUILD_ARCH := $(call norm_arch,$(MACOS_ARCH))
else
# Default native build: 32-bit x86 (-m32).
TARGET_NAME := SWOS
BUILD_OS := linux
BUILD_ARCH := x86
endif
BINDIR := bin
# Where the linked target lands. Everything native goes to bin/ — the shared
# runtime tree the game chdir's into and reads its data from.
#
# WASM is the exception: it is not a binary anyone runs from bin/, it is a web
# DEPLOYMENT of four coupled files (SWOS.html + .js + .wasm + the ~21 MB .data
# preload) that are only useful served together. They belong with the rest of
# the release output, so they go to dist/web — beside the zips, the installer
# and the .nsp. scripts/build_dist.sh has always excluded them from every
# archive for the same reason.
ifdef WASM
ifdef PLAYER
OUTDIR := dist/playback
else
OUTDIR := dist/web
endif
else
OUTDIR := $(BINDIR)
endif
TARGET := $(OUTDIR)/$(TARGET_NAME)
# ---- Object output dir (build/<os>/<arch>) ----
# Objects build under build/<os>/<arch> instead of cluttering src/, split by OS
# AND arch so every target in the same checkout keeps its own .o files:
# build/linux/x86_64, build/windows/x86_64, build/windows/arm64, build/linux/
# arm64, build/macos/arm64, … never collide. (The old flat in-tree layout forced
# a `make clean` whenever you switched target; Windows-on-ARM now slots in too.)
OBJDIR := build/$(BUILD_OS)/$(BUILD_ARCH)
# ---- Sources ----
SRCDIR := src
INCDIR := include
# The build stamp: regenerate include/swos_build.h before anything compiles.
# Parse-time, so it is always current; the script rewrites the header only when
# the commit changes, so this does not force a rebuild (scripts/gen_build_info.sh).
# Invoked through `sh`, not as an executable: core.filemode is false on the
# development mount and every script here is recorded 100644, so a fresh clone
# cannot exec it -- which broke the first clean-export build of this commit.
BUILD_STAMP_UNUSED := $(shell sh scripts/gen_build_info.sh)
SOURCES := $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/generated/*.c)
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
DEPS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.d,$(SOURCES))
# The generated-C rules below define `src/*.c` TARGETS, which would otherwise become the
# Makefile's first (default) goal. Pin the default goal so a bare `make` still builds the
# binary (the `all` target), not competition_data.c.
.DEFAULT_GOAL := all
# ---- Data-driven C (JSON -> C bake) ----
# competition_data.c and menu_data.c are GENERATED from the editable JSON in
# bin/data_json/ by the Python emitters (the Amiga build bakes JSON->C the same way).
# Editing the JSON regenerates the C at build; `make regen-data` forces it. To verify the
# regen is faithful, run the bare emitter (no --out): python3 scripts/emit_competitions.py
COMP_JSON := $(wildcard bin/data_json/competitions/*.json)
MENU_JSON := $(wildcard bin/data_json/menus/*.json)
TACTICS_JSON := $(wildcard bin/data_json/tactics/*.json)
# python3 for the JSON->C regen. If it's not on PATH (e.g. a minimal Cygwin), the committed
# .c is compiled as-is and a JSON edit needs python3 to take effect (the touch suppresses a
# pointless rebuild loop). The committed .c always exists, so the build never hard-fails.
PYTHON := $(shell command -v python3 2>/dev/null || command -v python 2>/dev/null)
$(SRCDIR)/competition_data.c: $(COMP_JSON) scripts/emit_competitions.py scripts/export_competitions.py scripts/swos_team_file.py
ifeq ($(strip $(PYTHON)),)
@echo " WARN python3 not found; compiling the committed $@ (JSON edits won't apply)"; touch $@
else
@echo " REGEN $@"; $(PYTHON) scripts/emit_competitions.py --out $@ >/dev/null
endif
$(SRCDIR)/menu_data.c: $(MENU_JSON) scripts/emit_menus.py scripts/export_menus.py
ifeq ($(strip $(PYTHON)),)
@echo " WARN python3 not found; compiling the committed $@ (JSON edits won't apply)"; touch $@
else
@echo " REGEN $@"; $(PYTHON) scripts/emit_menus.py --out $@ >/dev/null
endif
$(SRCDIR)/tactics_data.c: $(TACTICS_JSON) scripts/emit_tactics.py scripts/export_tactics.py
ifeq ($(strip $(PYTHON)),)
@echo " WARN python3 not found; compiling the committed $@ (JSON edits won't apply)"; touch $@
else
@echo " REGEN $@"; $(PYTHON) scripts/emit_tactics.py --out $@ >/dev/null
endif
.PHONY: regen-data
regen-data:
@test -n "$(strip $(PYTHON))" || { echo "regen-data needs python3 on PATH"; exit 1; }
$(PYTHON) scripts/emit_competitions.py --out $(SRCDIR)/competition_data.c
$(PYTHON) scripts/emit_menus.py --out $(SRCDIR)/menu_data.c
$(PYTHON) scripts/emit_tactics.py --out $(SRCDIR)/tactics_data.c
# ---- Windows resource (icon) ----
# On MinGW and Cygwin we compile SWOS.rc → SWOS.res.o via windres and
# link it in, which gives the .exe the SWOS.ico for both the file icon
# (Explorer) and the SDL window/taskbar icon (SDL2 picks up resource ID
# 1 when no SDL_SetWindowIcon is called).
#
# `gcc -dumpmachine` returns e.g. `x86_64-w64-mingw32` on MinGW and
# `x86_64-pc-cygwin` on Cygwin64 — match either via findstring.
GCC_MACHINE := $(shell $(CC) -dumpmachine 2>/dev/null)
WINDRES ?= windres
ifneq (,$(findstring mingw,$(GCC_MACHINE)))
WIN_RES_OBJ := $(OBJDIR)/SWOS.res.o
OBJECTS += $(WIN_RES_OBJ)
else ifneq (,$(findstring cygwin,$(GCC_MACHINE)))
WIN_RES_OBJ := $(OBJDIR)/SWOS.res.o
OBJECTS += $(WIN_RES_OBJ)
endif
# ---- Helpers ----
PKGCONF ?= pkg-config
ifdef WASM
# Emscripten ships SDL2 as a port — downloaded + cached on first use. Same flag
# for compile and link; no pkg-config.
SDL2_CFLAGS := -sUSE_SDL=2
SDL2_LIBS := -sUSE_SDL=2
else ifdef SDL2_MACOS_FW
# macOS framework: header search via -F + Headers/, link via -framework SDL2.
# The -rpath entries let the binary find SDL2.framework at runtime when
# either bundled inside the .app (Contents/Frameworks/) or installed
# system-wide under /Library/Frameworks/ or ~/Library/Frameworks/.
SDL2_CFLAGS := -F $(SDL2_MACOS_FW) -I $(SDL2_MACOS_FW)/SDL2.framework/Headers
SDL2_LIBS := -F $(SDL2_MACOS_FW) -framework SDL2 \
-Wl,-rpath,@executable_path/../Frameworks \
-Wl,-rpath,/Library/Frameworks \
-Wl,-rpath,$(HOME)/Library/Frameworks
else
SDL2_CFLAGS := $(shell $(PKGCONF) --cflags sdl2 2>/dev/null || sdl2-config --cflags 2>/dev/null)
SDL2_LIBS := $(shell $(PKGCONF) --libs sdl2 2>/dev/null || sdl2-config --libs 2>/dev/null)
endif
# ---- Build flags ----
# -m32 keeps pointers and `long` at 32 bits so the Amiga struct layouts
# (and the static size_check[] asserts) survive on a 64-bit host.
# -include forces swos_platform.h into every TU before any other header.
# -fno-strict-aliasing matches the original Amiga build (heavy type punning).
# Warnings dialed back: the imported Amiga code triggers many style warnings
# that are not bugs on x86/x64 but would otherwise drown the output.
#
# MSYS2/MINGW64 ships 64-bit-only libs and has no multilib, so -m32 fails
# at link time ("skipping incompatible libmingw32.a"). Detect the
# 64-bit-only mingw target via `gcc -dumpmachine` and drop -m32 there.
# Testers wanting an actual 32-bit Windows binary should use MSYS2
# MINGW32 (gcc already 32-bit; -m32 is a no-op) or Cygwin's 32-bit
# toolchain.
ifdef WASM
# wasm32 is ILP32 — no -m flags; emcc targets wasm by default. (Struct
# size_check[] asserts pass on ILP32, same as armhf.)
ARCHFLAGS :=
else ifdef ARM64
# aarch64 is 64-bit (LP64) — no -m32 / -m64 needed. The static
# size_check[] asserts that hard-code Amiga 32-bit struct sizes
# will fail until Phase 5 / 6 lands.
ARCHFLAGS :=
else ifdef ARM
# armhf is already 32-bit (ILP32) — no -m32 needed; passing it would
# fail with "unrecognized command-line option '-m32'" on most ARM gcc
# builds. Force armv7-a to keep things uniform across Pi 2/3/4 etc.
ARCHFLAGS := -march=armv7-a -mfpu=neon -mfloat-abi=hard
else ifeq ($(UNAME_S),Darwin)
# Modern macOS is 64-bit (arm64 or x86_64). No -m32. The static
# size_check[] asserts are gated on UINTPTR_MAX (see game_types.h) and
# already pick the 64-bit struct sizes.
#
# MACOS_ARCH: target architecture. Defaults to the host arch (so a plain
# `make` on an M-series Mac produces arm64, on Intel produces x86_64).
# Set explicitly to build a single non-host slice (used by macos-universal
# below). Accepted values match clang's -arch flag: arm64 or x86_64.
#
# MACOS_MIN: minimum deployment target. 11.0 = Big Sur — the oldest macOS
# that supports Apple Silicon natively and that libsdl.org's prebuilt
# SDL2.framework still loads on. Override with MACOS_MIN=12.0 etc. if
# you only need to target newer systems.
MACOS_ARCH ?= $(shell uname -m)
MACOS_MIN ?= 11.0
ARCHFLAGS := -arch $(MACOS_ARCH) -mmacosx-version-min=$(MACOS_MIN)
else ifeq ($(GCC_MACHINE),x86_64-w64-mingw32)
ARCHFLAGS :=
else ifneq (,$(findstring CYGWIN,$(UNAME_S)))
# Cygwin64's gcc is 64-bit-only; -m32 fails with "unimplemented for
# this target" in <signal.h>. Drop -m32 and let it produce a native
# 64-bit Windows binary (struct sizes go through the Phase 5
# bitness-conditional asserts the same way aarch64 does). Testers
# wanting a 32-bit Windows binary should use MSYS2 MINGW32 instead.
ARCHFLAGS :=
else ifdef X86_64
# Explicit 64-bit Linux x86 build. Drop -m32 and pass -m64 so the
# binary is LP64. Same code path as cygwin64 / aarch64 / macOS for
# the bitness-conditional size_check asserts.
ARCHFLAGS := -m64
else
ARCHFLAGS := -m32
endif
# All Amiga "data module" toggles set to 1 so the C versions of
# the leagues, palettes, sprites, fixtures, etc. are compiled in
# (replacing the SWOS2.s data section). This eliminates a large
# fraction of the zero-filled stubs.
DATA_FLAGS := -DCOMPETITION_DATA_C=1 -DTACTICS_DATA_C=1 -DFIXTURE_DATA_C=1 \
-DSIMULATION_DATA_C=1 -DPLAYER_DATA_C=1 -DRENDER_DATA_C=1 \
-DPALETTE_DATA_C=1 -DSTRINGS_DATA_C=1 -DGENERAL_DATA_C=1
# Diagnostic logging defaults to OFF. The bring-up loggers (autoskip
# menu trace, SFX trigger trace) are still in the source — gated on
# SWOS_DEBUG_AUTOSKIP / SWOS_DEBUG_SFX — so a tester chasing a
# regression can re-enable with `make SWOS_DEBUG=1`.
ifdef SWOS_DEBUG
DEBUG_FLAGS := -DSWOS_DEBUG_AUTOSKIP=1 -DSWOS_DEBUG_SFX=1
endif
# Toggling a -D flag below rebuilds every object that the flag reaches -- see
# BUILD_FLAGS_STAMP further down. It used not to: make compares TIMESTAMPS, so
# `make X86_64=1` after `make X86_64=1 SWOS_TEST_NO_INJURIES_CARDS=1` (as it was) relinked
# the old objects, and a binary could carry the flag in some files and not in
# others -- which desynced a live match (2026-09-19, see there).
#
# The testers' rule -- no cards, no injuries, OFFLINE only -- is a SWOS.ini setting,
# `[testing] no_injuries_cards = true`, off by default (include/test_rules.h). It lets a
# tester hit VIEW RESULT uninterruptedly through a season: no substitution menus, no
# booking prompts. SWOS_TEST_RULES=1 (the default) compiles the setting in;
# `make SWOS_TEST_RULES=0` compiles the rule OUT, for a public release nobody should be
# able to switch it on in (scripts/build_dist.sh --release). It also marks a tester
# build for the defaults that differ (match reports on, the menu navigation log).
#
# Until 2026-10-11 this was SWOS_TEST_NO_INJURIES_CARDS, compile-time: a tester's binary
# was a different game from a release, took the rule into online matches, and a binary
# built partly with it desynced one.
#
# KNOWN DISPLAY SIDE-EFFECTS with the rule ON (do NOT re-investigate as port
# bugs — they vanish with the setting off). IsPlayerInjured() returns 0 for
# everyone, so any player carrying a PRE-EXISTING injury/suspension in a loaded
# save is "healthy" to every gameplay query while the row indicator — which
# reads pf->cardsInjuries directly — still shows the "3":
# * the squad screens' red name needs the honest status; all three call sites
# now use IsPlayerInjuredForDisplay() (edit_tactics.c, play_match_menu.c
# DrawPlayerEntries, menus.c SquadAfterDrawCommon), so this one is handled.
# * the tick/cross marks still read low: UpdatePlayerPositionAndReturnRole
# zeroes an injured player's position value via IsPlayerInjured, so under
# the flag he keeps full value and substituting him off scores as a
# DOWNGRADE (big red cross instead of a green tick). Left as-is — that
# value also feeds the match sim, where the flag's "he can play" is the
# intended behaviour.
# * squad LEGALITY (isPlayerDisabled -> GetNumberOfAvailablePlayers/
# Substitutes) read cardsInjuries directly, so ShowOrHidePlayMatchButton
# still hid the PLAY MATCH / VIEW RESULT button and forced a substitution —
# the exact friction the flag exists to remove. isPlayerDisabled now honours
# the override too, so this one is handled. (Stock builds are unaffected:
# an injured starter still hides the button, per SWOS2.s loc_14872A.)
SWOS_TEST_RULES ?= 1
ifeq ($(SWOS_TEST_RULES),1)
DEBUG_FLAGS += -DSWOS_TEST_RULES=1
endif
# The football worlds beyond 96/97 (World 2026-27 and all it brought: include/swos_types.h,
# docs/WORLD_2026_27.md). `make SWOS_WORLDS=0` compiles them out: 96/97 alone, as before them.
SWOS_WORLDS ?= 1
DEBUG_FLAGS += -DSWOS_WORLDS=$(SWOS_WORLDS)
# The chat's font (include/chat_style.h): unset, the chat font (SDL); `make
# SWOS_CHAT_DYNAMIC_FONT=0` the game's own, as a build without the overlay would have it.
ifdef SWOS_CHAT_DYNAMIC_FONT
DEBUG_FLAGS += -DSWOS_CHAT_DYNAMIC_FONT=$(SWOS_CHAT_DYNAMIC_FONT)
endif
# [tweaks] (include/tweaks.h): built when include/project_identity.h says (PROJECT_TWEAKS);
# `make SWOS_TWEAKS=0|1` overrides it.
ifdef SWOS_TWEAKS
DEBUG_FLAGS += -DSWOS_TWEAKS=$(SWOS_TWEAKS)
endif
# The online client (`make ONLINE_CLIENT=1`, SDL with netplay): the game starts at the
# multiplayer log-in, and leaving it quits -- a build for playing online and nothing else
# (SWOS United's). `--online` starts any build there, leaving it for the main menu.
ONLINE_CLIENT ?= 0
DEBUG_FLAGS += -DSWOS_ONLINE_CLIENT=$(ONLINE_CLIENT)
# Build with the PRISTINE Amiga data for the four formations this port
# deliberately corrected — 4-4-2, 4-3-3, 3-4-3, Sweep (commit 1828528, whose
# tester-supplied fix un-swaps central defenders that crossed sides instead of
# holding station). It is the port's one intentional gameplay-data divergence,
# so anything measuring us against ORIGINAL behaviour — the recorded-game
# replay rig above all (docs/TESTS.md) — needs to be able to turn it off.
# `make clean` first: this changes baked data and make compares timestamps,
# not flags. See the header comment in src/tactics_data.c.
ifdef SWOS_ORIGINAL_TACTICS
DEBUG_FLAGS += -DSWOS_ORIGINAL_TACTICS=1
endif
# The DOS release's formation coverage instead of the Amiga's. Nine of the
# twelve are byte-identical; 4-4-2 (68 bytes), Sweep (64) and 4-3-3 (10) are
# not, and 60/61 of the first two are the two forward slots, rewritten. Since
# GetPlayerPrice walks the tactics table for every player, this changes player
# values and in-game skill nibbles as well as where men stand.
# `make clean` first (same reason as above), and it is mutually exclusive with
# SWOS_ORIGINAL_TACTICS. See src/tactics_data.c and docs/TACTICS_POSITION_VALUE.md
# section 9 — including why the replay corpus disagrees with the forward slots.
ifdef SWOS_DOS_TACTICS
DEBUG_FLAGS += -DSWOS_DOS_TACTICS=1
endif
# Debug: force a World Cup for a national-team career, bypassing the natural
# 4-year competition cycle, so the national-coach WC path can be reproduced on
# demand (e.g. the season-transition 0x8888 backup-clobber in
# _VerifyTeamLoaded). Off by default; enable with `make SWOS_INJECT_WC=1`.
# Only affects national-team career selection (country code 80..85), and is
# compile-time only so production builds never ship with it on. See the inject
# site in src/career_init.c (_InitializeNewSeason).
ifdef SWOS_INJECT_WC
DEBUG_FLAGS += -DSWOS_INJECT_WC=1
endif
# Save-file format toggle. Default ON — new saves are written as JSON
# via mjson (see src/save_format_json.c) and load auto-detects format
# from the file header.
#
# The big overlay-dump saves (.CAR/.SEA/.PRE/.DIY) are now JSON-only on
# BOTH read and write regardless of this flag — their legacy raw-memory-
# dump readers AND writers have been deleted (roadmap step 4 complete).
# The flag now only governs the WRITE format of the small fixed-layout
# records that KEEP binary support (.HIL/.TAC): ON (default) writes them
# JSON-first; =0 writes them in the original binary layout. Their binary
# READ path is compiled either way (load auto-detects), so .HIL/.TAC/.EDT/
# .CFG interop is preserved. See docs/SAVE_DATA.md "Format migration /
# read-support policy".
ifneq ($(SWOS_SAVE_FORMAT_JSON),0)
DEBUG_FLAGS += -DSWOS_SAVE_FORMAT_JSON=1
endif
# Coverage verification for the JSON save format. Default ON during
# bring-up — load-time diff compares the byte image produced by the
# named-blob + semantic field loaders against the bytes from opaque_data.
# A zero-mismatch result means every meaningful byte is covered by typed
# fields/blobs and opaque_data can be removed. Opt out with
# `make SWOS_SAVE_FORMAT_JSON_VERIFY=0` to skip the diff (small load-time
# perf win once we trust the format).
ifneq ($(SWOS_SAVE_FORMAT_JSON_VERIFY),0)
DEBUG_FLAGS += -DSWOS_SAVE_FORMAT_JSON_VERIFY=1
endif
# Profile flag: prints per-phase wall-clock timings (`[json-prof-*]`
# lines) so you can see where load/save time is going. Default OFF —
# profiling is largely done; opt in with `make SWOS_SAVE_FORMAT_JSON_PROFILE=1`
# when investigating save/load perf regressions.
ifdef SWOS_SAVE_FORMAT_JSON_PROFILE
DEBUG_FLAGS += -DSWOS_SAVE_FORMAT_JSON_PROFILE=1
endif
# Legacy-dispatch toggle: build with `make SWOS_SAVE_LEGACY_DISPATCH=1` to
# select the per-field path-lookup loop (slow but the established
# baseline). Default OFF — the new walk-once dispatch is faster.
# Keep around for comparison testing when investigating verify deltas.
ifdef SWOS_SAVE_LEGACY_DISPATCH
DEBUG_FLAGS += -DSWOS_SAVE_LEGACY_DISPATCH=1
endif
CFLAGS := $(ARCHFLAGS) -O2 -g -std=gnu11 -fno-strict-aliasing -fno-builtin \
-MMD -MP \
-D_FILE_OFFSET_BITS=64 $(DEBUG_FLAGS) \
-Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable \
-Wno-attributes -Wno-multichar -Wno-builtin-declaration-mismatch \
-Wno-pointer-sign -Wno-int-conversion -Wno-incompatible-pointer-types \
-Wno-braces -Wno-address-of-packed-member \
-Wno-strict-aliasing -Wno-array-bounds -Wno-stringop-overflow \
$(DATA_FLAGS) \
-include $(INCDIR)/swos_platform.h \
-I$(SRCDIR) -I$(INCDIR) $(SDL2_CFLAGS)
# -Wno-braces: tactics_data.c auto-extractor wraps scalar
# initialisers in `{ }`; intentional, ~4200 hits.
# -Wno-address-of-packed-member: packed structs mirror Amiga byte layout
# everywhere; we take &field deliberately.
# -Wno-strict-aliasing: we already pass -fno-strict-aliasing for the
# same reason; this just silences the diag.
# -Wno-array-bounds: Amiga BSS adjacency reads (e.g. extern
# uint8_t selTeamsPtr; then read [4]) intentionally
# walk past the declared end of 1-byte stubs.
# Real adjacency bugs surface as runtime panics —
# this warning is too noisy to be useful.
# -Wno-stringop-overflow: same root cause as -Wno-array-bounds but for
# the WRITE side (`((uint8_t *)&selTeamsPtr)[4] = x`).
# The compiler sees a 1-byte stub and flags any
# wider write; we know the real backing is much
# larger.
LDFLAGS := $(ARCHFLAGS)
# Linux: look for a bundled SDL beside the binary before falling back to the
# system one. SWOS-portable.zip ships lib/<arch>/libSDL2-2.0.so.0 (see
# LINUX_SDL_LIBS in scripts/build_dist.sh) so a tester who has never installed
# libsdl2 can still run it; a dev tree has no lib/ dir, so the loader falls
# straight through to the system copy and nothing changes here.
#
# --disable-new-dtags emits DT_RPATH, NOT the more modern DT_RUNPATH, and that
# is deliberate. DT_RUNPATH applies only to the executable's DIRECT
# dependencies; DT_RPATH is inherited down the whole chain. We need the
# inherited kind, because the distro libSDL2 links its backends rather than
# dlopening them -- with RUNPATH the bundled libSDL2 loads but its own
# dependency on libdecor-0.so.0 is resolved from ld.so.cache only, so on a
# machine without libdecor the bundle fails anyway and shipping it was pointless.
# Measured, not assumed: under RUNPATH ldd showed libSDL2 coming from the bundle
# and libdecor from /lib/x86_64-linux-gnu.
#
# The cost is that DT_RPATH is searched BEFORE LD_LIBRARY_PATH, so that is no
# longer an override. To use a system SDL2 instead, delete the lib/ directory --
# the loader then falls straight through to ld.so.cache. (patchelf on the
# bundled .so would let us keep RUNPATH semantics, but it is not installed here
# and a build machine without it would silently produce a broken drop.)
#
# $$ORIGIN survives make -> shell -> linker as a literal $ORIGIN, resolved by
# the loader at run time. Do not "fix" it to an absolute path.
ifeq ($(BUILD_OS),linux)
LDFLAGS += -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN/lib/$(BUILD_ARCH)'
endif
# macOS: switch to Apple's classic linker (-ld_classic). Modern ld64
# (Xcode 15+) is strict about pointer-relocation alignment and rejects
# packed-struct atoms whose internal pointer fields aren't 8-byte
# aligned — emits errors like "pointer not aligned in _euroCup+0x2E".
# The classic linker behaves like every other linker and accepts the
# misaligned relocations, which is fine at runtime: ARM64 (and x86_64)
# scalar loads cope with misaligned pointers correctly. This keeps the
# struct layout identical across all 64-bit targets (Linux aarch64
# already builds + runs with the same packed structs).
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -Wl,-ld_classic
endif
# The original game's data is not in this repo: the data setup (tools/swosdata)
# builds it from the player's own copy into the assets folder, the same folder
# the game reads at run time (swos_assets_dir() in src/swos_io.c). The web build
# bakes both into SWOS.data: the project's own files from bin/, the game's from
# here. Override with SWOS_ASSETS=/path (also what the game reads).
ifeq ($(origin SWOS_ASSETS),undefined)
SWOS_ASSETS := $(HOME)/.swos/assets
endif
# (grafs_dos: the PC game's graphics -- the menus' PC shading (dosmenus, on by default) and the
# DOS graphics; 1.4 MB. Not sound_dos (15 MB) nor grafs_2020 (not ours to hand out).)
WASM_DATA_DIRS := data grafs grafs_aga grafs_dos grafs_jag sound data_json mods
# Emscripten link flags. ASYNCIFY lets the blocking game loop yield to the
# browser at the one Platform_VBlank choke-point (emscripten_sleep — docs/WASM.md
# §0/§2a). Growable heap; preload the read-only game data into MEMFS; IDBFS for
# persistent saves at /save (mounted in wasm/pre.js). Single-threaded — the
# 20 ms SDL timer + 5 ms audio-pump thread are compiled out (#ifdef SWOS_WASM_BUILD).
#
# BOTH graphics tiers are preloaded: resload.c resolves a grafs load as
# grafs_aga/ first then grafs/ (display.h defines AGA on this build too), so
# without grafs_aga in MEMFS the browser silently ran the 4bpp OCS set while
# native ran 8bpp. grafs_aga is currently a complete superset, so grafs/ is only
# the safety net — droppable later if the ~268K matters for download size.
ifdef WASM
ifdef PLAYER
WASM_SHELL := wasm/player.html
else
WASM_SHELL := wasm/shell.html
endif
# EMULATE_FUNCTION_POINTER_CASTS: SWOS's menu system stores void(void) callbacks
# (e.g. FriendlyMenu) in void(MenuEntry*) fields and invokes them through void*
# casts — fine on every native ABI, but wasm hard-traps an indirect call whose
# table signature differs ("indirect call signature mismatch"). This generates
# adapter thunks so the mismatched calls work, like native. wasm-only flag.
LDFLAGS += -sASYNCIFY -sASYNCIFY_STACK_SIZE=65536 \
-sEMULATE_FUNCTION_POINTER_CASTS=1 \
-sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=134217728 \
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap,FS -lidbfs.js \
--pre-js wasm/pre.js --shell-file $(WASM_SHELL) \
$(foreach d,$(WASM_DATA_DIRS),$(foreach r,bin $(SWOS_ASSETS),\
$(if $(wildcard $(r)/$(d)),--preload-file $(r)/$(d)@/$(d)))) \
--exclude-file '*data_json/worlds*'
# (Never a world's data: World 2026-27's is its authors' and never goes out with OpenSWOS --
# a player installs its package with OpenSWOS Setup. A developer's bin/ has it, gitignored, and
# until 2026-11-01 this took its teams and competitions into SWOS.data: caught before a deploy.)
# Re-link when the pre-js or shell HTML changes (both embedded at link time).
WASM_LINK_DEPS := wasm/pre.js $(WASM_SHELL)
# The --preload-file dirs are baked into SWOS.data AT LINK TIME, but nothing above
# makes them a prerequisite — so editing/adding a data file and re-running
# `make WASM=1` relinked nothing and silently shipped the OLD SWOS.data. (Hit for
# real when bin/data_json/teams landed: SWOS.data stayed 2.8MB until the target was
# deleted by hand, then jumped to 21MB.) List the preloaded files so a data change
# forces the relink.
WASM_PRELOAD_FILES := $(wildcard $(foreach r,bin $(SWOS_ASSETS),\
$(r)/data/* $(r)/grafs/* $(r)/grafs_aga/* $(r)/grafs_jag/* $(r)/sound/* \
$(r)/data_json/*.json $(r)/data_json/*/*.json \
$(r)/data_json/*/*/*.json))
WASM_LINK_DEPS += $(WASM_PRELOAD_FILES)
endif
LDLIBS := $(SDL2_LIBS) -lm
# timeBeginPeriod (src/platform_timer.c). winmm.dll is part of Windows, so the
# shipped DLL list does not change.
ifeq ($(BUILD_OS),windows)
LDLIBS += -lwinmm
endif
# Windows draws with Direct3D 11 (src/sokol_impl_d3d11.c) unless WIN_GL=1 keeps OpenGL. The DLLs it
# loads (d3d11, dxgi, d3dcompiler_47) are Windows 10's own: the shipped DLL list does not change.
ifeq ($(BUILD_OS),windows)
ifeq ($(WIN_GL),1)
CFLAGS += -DSWOS_WIN_GL=1
else
LDLIBS += -ld3d11 -ldxgi -ldxguid
endif
endif
# Linux: the presenter's GL is OpenGL ES 3.0 on ARM, OpenGL 4.1 core elsewhere (src/sokol_config.h);
# GPU_GLES=1 / 0 picks one for any Linux build (a test of the handhelds' path on a desktop).
ifneq ($(GPU_GLES),)
CFLAGS += -DSWOS_GPU_GLES=$(GPU_GLES)
endif
# The GPU presenter (src/gpu_present.c, sokol_gfx; docs/RENDERING.md). Desktop Linux and Windows
# load OpenGL through SDL (src/sokol_gl_loader.h), so link nothing; macOS links its OpenGL
# framework, the web asks for WebGL 2 (GLES 3).
# macOS draws with Metal (src/sokol_impl_metal.m, Objective-C) unless MACOS_GL=1 keeps OpenGL.
ifndef WASM
ifeq ($(UNAME_S),Darwin)
ifeq ($(MACOS_GL),1)
CFLAGS += -DSWOS_MACOS_GL=1
LDLIBS += -framework OpenGL
else
OBJECTS += $(OBJDIR)/sokol_impl_metal.o
DEPS += $(OBJDIR)/sokol_impl_metal.d
LDLIBS += -framework Metal -framework QuartzCore -framework Foundation
endif
endif
else
LDLIBS += -sMAX_WEBGL_VERSION=2
endif
# ---- Netplay: GGPO-X rollback networking (docs/NETPLAY.md) ----
# third_party/ggpo-x is C++; src/netplay.c reaches it through ggponet.h's C API.
# Default ON where it is built and tested: 64-bit Linux (X86_64=1), macOS (both
# slices) and Cygwin64. Anywhere else opt in with NETPLAY=1 -- it needs a C++
# compiler for the target, and the default -m32 Linux build also needs
# g++-multilib. Without it src/netplay.c compiles to stubs.
#
# WASM: a browser has no UDP sockets, so Emscripten's socket layer carries each
# datagram as one WebSocket message to ws://host:port -- wss:// from an https page --
# the matchmaker's WebSocket gate (--websocket, docs/NETPLAY.md §8), which hands it
# to the server's UDP port as if it came from an ordinary client. A browser can
# only ever talk to that server, so it always plays through the relay. Default ON
# since 2026-09-24, when the public server (us.swos.eu) got its certificate: the
# public page is https, and until the gate spoke wss:// its MULTIPLAYER button
# would have led nowhere. `make WASM=1 NETPLAY=0` builds one without.
#
# macOS was off until 2026-09-17 for no reason but never having been tried: the
# arch flags were already threaded through the C++ and ENET rules ($(ARCHFLAGS)),
# and the link already skips -static-libstdc++ on Darwin (clang ships libc++).
# A Mac player could not see the MULTIPLAYER button at all, since the main menu
# hides it without SWOS_NETPLAY.
#
# The C++ runtime is linked STATICALLY, so the binary gains no DLL/.so: the
# Windows drop's exact four-DLL list (CLAUDE.md) and the Linux lib/<arch> bundle
# stay as they are. Check with `cygcheck bin/SWOS.exe` / `ldd bin/SWOS.x86_64`.
#
# Toggling NETPLAY rebuilds every object by itself: the flags stamp (CLAUDE.md).
GGPO_DIR := third_party/ggpo-x/src
ENET_DIR := third_party/enet
ifndef NETPLAY
ifdef PLAYER
NETPLAY := 0
else ifdef WASM
NETPLAY := 1
else ifeq ($(BUILD_OS)/$(BUILD_ARCH),linux/x86_64)
NETPLAY := 1
else ifeq ($(BUILD_OS),macos)
NETPLAY := 1
else ifneq (,$(findstring cygwin,$(GCC_MACHINE)))
NETPLAY := 1
else
NETPLAY := 0
endif
endif
LINK := $(CC)
ifeq ($(NETPLAY),1)
GGPO_SRCS := $(filter-out %/platform_windows.cpp, \
$(wildcard $(GGPO_DIR)/lib/ggpo/*.cpp \
$(GGPO_DIR)/lib/ggpo/network/*.cpp \
$(GGPO_DIR)/lib/ggpo/backends/*.cpp))
GGPO_OBJS := $(patsubst $(GGPO_DIR)/lib/ggpo/%.cpp,$(OBJDIR)/ggpo/%.o,$(GGPO_SRCS))
OBJECTS += $(GGPO_OBJS)
# The one C++ file of ours: it bridges the C emulator to GGPO's C++ hook.
OBJECTS += $(OBJDIR)/netplay_netem_install.o
DEPS += $(OBJDIR)/netplay_netem_install.d
DEPS += $(GGPO_OBJS:.o=.d)
CFLAGS += -DSWOS_NETPLAY=1 -I$(GGPO_DIR)/include
# -w: third-party code, compiled as upstream ships it (plus OPENSWOS.md's patches).
# GGPO_SEND_FRAME_ADVANTAGE=0: the time sync works from each peer's own estimate alone.
# That is how every build before 2026-10-06 ran without meaning to -- the fork's min()
# returned a dangling reference, so the advantage a peer sent was noise, nearly always
# 0 -- and it is what the pacing in src/netplay_match.c was tuned against: with the real
# figure the same pacing over-corrects and the two peers swing five frames apart
# (docs/NETPLAY_BALANCE.md). Sending a plain 0 keeps that behaviour without the noise.
GGPO_CXXFLAGS := $(ARCHFLAGS) -O2 -g -std=gnu++17 -MMD -MP -w \
-DGGPO_SEND_FRAME_ADVANTAGE=0 \
-I$(GGPO_DIR)/include -I$(GGPO_DIR)/lib/ggpo \
-I$(GGPO_DIR)/lib/ggpo/network -I$(GGPO_DIR)/lib/ggpo/backends \
-Iinclude
# ENET: the transport for matchmaking (src/mm_client.c) and the same library the
# vendored server is built from -- one copy, see third_party/enet/OPENSWOS.md.
#
# win32.c ONLY for a real Win32 target. Cygwin sets BUILD_OS=windows but is a
# POSIX host and does NOT define _WIN32, and enet.h picks its platform header on
# exactly that (`#if defined(_WIN32)` -> enet/win32.h, else enet/unix.h). Keying
# this off BUILD_OS would hand Cygwin win32.c against unix.h and fail to build.
# So it keys off mingw, the same way the rest of the file distinguishes them.
ENET_SRCS := $(ENET_DIR)/callbacks.c $(ENET_DIR)/compress.c $(ENET_DIR)/host.c \
$(ENET_DIR)/list.c $(ENET_DIR)/packet.c $(ENET_DIR)/peer.c \
$(ENET_DIR)/protocol.c
ifneq (,$(findstring mingw,$(GCC_MACHINE)))
ENET_SRCS += $(ENET_DIR)/win32.c
ENET_PLATFORM_DEFS :=
else
ENET_SRCS += $(ENET_DIR)/unix.c
# Normally probed by enet's own autotools/CMake. Getting one wrong does not fail
# the build, it silently changes socket behaviour -- so they are written out.
ENET_PLATFORM_DEFS := -DHAS_SOCKLEN_T=1 -DHAS_POLL=1 -DHAS_FCNTL=1 \
-DHAS_INET_PTON=1 -DHAS_INET_NTOP=1 -DHAS_MSGHDR_FLAGS=1
endif
ENET_OBJS := $(patsubst $(ENET_DIR)/%.c,$(OBJDIR)/enet/%.o,$(ENET_SRCS))
OBJECTS += $(ENET_OBJS)
DEPS += $(ENET_OBJS:.o=.d)
CFLAGS += -I$(ENET_DIR)/include
# -w: third-party code, compiled as upstream ships it.
ENET_CFLAGS := $(ARCHFLAGS) -O2 -g -MMD -MP -w -I$(ENET_DIR)/include $(ENET_PLATFORM_DEFS)
ifneq (,$(findstring mingw,$(GCC_MACHINE)))
LDLIBS += -lws2_32 -lwinmm
endif
LINK := $(CXX)
# Not Darwin (clang ships libc++) and not WASM (em++ links its own runtime).
ifneq ($(UNAME_S),Darwin)
ifndef WASM
LDFLAGS += -static-libstdc++ -static-libgcc
endif
endif
endif
# ---- The shader compiler: glslang + SPIRV-Cross (docs/RENDERING.md, "Shaders from files") ----
# RetroArch's way: a .slang shader (Vulkan GLSL) is compiled on the player's machine by glslang
# to SPIR-V, and SPIRV-Cross turns that into the running backend's language (GLSL, GLSL ES,
# Metal, HLSL) -- one file for every backend. Both are submodules pinned to one Vulkan SDK
# release (third_party/glslang, third_party/SPIRV-Cross), compiled here from their sources as
# GGPO-X is, so every target -- the cross-compilers and the web build too -- builds them the
# same way, with no CMake step. glslang's generated build_info.h is src/shadercc's copy.
# Default ON where a C++ compiler for the target is known to work (as NETPLAY); without it the
# game's own shaders work as before and shader files are not offered. Linked statically.
SHADERCC_GLSLANG := third_party/glslang
SHADERCC_SPVC := third_party/SPIRV-Cross
ifndef SHADERCC
ifdef PLAYER
SHADERCC := 0
else ifdef WASM
SHADERCC := 1
else ifeq ($(BUILD_OS)/$(BUILD_ARCH),linux/x86_64)
SHADERCC := 1
else ifeq ($(BUILD_OS),macos)
SHADERCC := 1
else ifneq (,$(findstring cygwin,$(GCC_MACHINE)))
SHADERCC := 1
else
SHADERCC := 0
endif
endif
ifeq ($(SHADERCC),1)
SHADERCC_SRCS := $(SHADERCC_GLSLANG)/SPIRV/CInterface/spirv_c_interface.cpp \
$(SHADERCC_GLSLANG)/SPIRV/GlslangToSpv.cpp \
$(SHADERCC_GLSLANG)/SPIRV/InReadableOrder.cpp \
$(SHADERCC_GLSLANG)/SPIRV/Logger.cpp \
$(SHADERCC_GLSLANG)/SPIRV/SpvBuilder.cpp \
$(SHADERCC_GLSLANG)/SPIRV/SpvPostProcess.cpp \
$(SHADERCC_GLSLANG)/SPIRV/SpvTools.cpp \
$(SHADERCC_GLSLANG)/SPIRV/disassemble.cpp \
$(SHADERCC_GLSLANG)/SPIRV/doc.cpp \
$(SHADERCC_GLSLANG)/glslang/CInterface/glslang_c_interface.cpp \
$(SHADERCC_GLSLANG)/glslang/GenericCodeGen/CodeGen.cpp \
$(SHADERCC_GLSLANG)/glslang/GenericCodeGen/Link.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/Constant.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/InfoSink.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/Initialize.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/IntermTraverse.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/Intermediate.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/ParseContextBase.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/ParseHelper.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/PoolAlloc.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/RemoveTree.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/Scan.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/ShaderLang.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/SpirvIntrinsics.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/SymbolTable.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/Versions.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/attribute.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/glslang_tab.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/intermOut.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/iomapper.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/limits.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/linkValidate.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/parseConst.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/preprocessor/Pp.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/preprocessor/PpAtom.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/preprocessor/PpContext.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/preprocessor/PpScanner.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/preprocessor/PpTokens.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/propagateNoContraction.cpp \
$(SHADERCC_GLSLANG)/glslang/MachineIndependent/reflection.cpp \
$(SHADERCC_GLSLANG)/glslang/OSDependent/Unix/ossource.cpp \
$(SHADERCC_GLSLANG)/glslang/ResourceLimits/ResourceLimits.cpp \
$(SHADERCC_GLSLANG)/glslang/ResourceLimits/resource_limits_c.cpp \
$(SHADERCC_SPVC)/spirv_cfg.cpp \
$(SHADERCC_SPVC)/spirv_cross.cpp \
$(SHADERCC_SPVC)/spirv_cross_c.cpp \
$(SHADERCC_SPVC)/spirv_cross_parsed_ir.cpp \
$(SHADERCC_SPVC)/spirv_glsl.cpp \
$(SHADERCC_SPVC)/spirv_hlsl.cpp \
$(SHADERCC_SPVC)/spirv_msl.cpp \
$(SHADERCC_SPVC)/spirv_parser.cpp \
$(SHADERCC_SPVC)/spirv_reflect.cpp
SHADERCC_OBJS := $(patsubst third_party/%.cpp,$(OBJDIR)/shadercc/%.o,$(SHADERCC_SRCS))
OBJECTS += $(SHADERCC_OBJS)
DEPS += $(SHADERCC_OBJS:.o=.d)
CFLAGS += -DSWOS_SHADERCC=1 -I$(SHADERCC_GLSLANG) -I$(SHADERCC_SPVC)
# The web, two traps the Retro TV preset fell into (2026-11-08):
# - glslang's parser needs far more stack than Emscripten's 64 KB (native threads have 8 MB);
# - Asyncify instrumented the compiler too -- the game's sleeps are reachable through indirect
# calls, so it cannot prove the compiler never sleeps -- and the instrumented SPIRV-Cross took
# the browser's page process down mid-compile (a crash, no message; fine in Node, and fine
# without the game). The compiler never sleeps: left out, the wasm is 24 MB -> 15 MB.
ifdef WASM
LDFLAGS += -sSTACK_SIZE=4194304 \
'-sASYNCIFY_REMOVE=["spirv_cross::*","glslang::*","spv::*","spvc_*","glslang_*","Slang_*"]'
endif
# -w: third-party code, compiled as upstream ships it; the defines are its CMake build's.
SHADERCC_CXXFLAGS := $(ARCHFLAGS) -O2 -std=gnu++17 -MMD -MP -w -DNDEBUG \
-DENABLE_OPT=0 -DENABLE_SPIRV -DGLSLANG_OSINCLUDE_UNIX \
-DSPIRV_CROSS_C_API_GLSL=1 -DSPIRV_CROSS_C_API_HLSL=1 \
-DSPIRV_CROSS_C_API_MSL=1 -DSPIRV_CROSS_C_API_REFLECT=1 \
-Isrc/shadercc -I$(SHADERCC_GLSLANG) -I$(SHADERCC_SPVC)
LINK := $(CXX)
ifneq ($(UNAME_S),Darwin)
ifndef WASM
LDFLAGS += -static-libstdc++ -static-libgcc
endif
endif
endif
# ---- A fork's own build additions ----
# A fork of OpenSWOS (docs/FORKING.md) puts what only it builds in fork.mk beside this file --
# a library of its own (OBJECTS += its objects, with their rules), flags, libraries to link
# (FORK_CFLAGS counts in the build-flags stamp below) -- so it never edits this Makefile, and
# merging OpenSWOS's never conflicts here. OpenSWOS has none.
-include fork.mk
# ---- A changed flag rebuilds everything ----
# make compares TIMESTAMPS, not flags. Toggling a -D (SWOS_TEST_NO_INJURIES_CARDS,
# say) used to relink the old objects, and hand back a binary with the old flag in
# every file that had not changed since and the new one in the rest. That is how a
# Windows build that books players (a stale tackle_foul.o, compiled without the flag)
# met a clean Mac build that cannot: a live match desynced at the first booking
# (2026-09-19), with both build stamps reading the same commit.
#
# So the compile flags are written to one file per object tree, rewritten only when
# they change, and every object depends on it. $(shell), not $(file): macOS still
# ships GNU make 3.81.
BUILD_FLAGS_STAMP := $(OBJDIR)/.build-flags
BUILD_FLAGS_NOW := $(strip $(CC) $(CFLAGS) :: $(CXX) $(GGPO_CXXFLAGS) :: $(ENET_CFLAGS) :: $(FORK_CFLAGS))
ifneq ($(BUILD_FLAGS_NOW),$(strip $(shell cat $(BUILD_FLAGS_STAMP) 2>/dev/null)))
$(shell mkdir -p $(OBJDIR) && printf '%s\n' '$(BUILD_FLAGS_NOW)' > $(BUILD_FLAGS_STAMP))
endif
# Gone after a `clean` in the same run: write it again rather than stop.
$(BUILD_FLAGS_STAMP):
@mkdir -p $(dir $@)
@printf '%s\n' '$(BUILD_FLAGS_NOW)' > $@
# ---- Targets ----
.PHONY: all clean distclean debug macos-universal macos-app
all: $(TARGET)
ifdef PLAYER
# The recordings list beside the player (docs/PLAYBACK.md).
all: $(OUTDIR)/index.html
$(OUTDIR)/index.html: wasm/playback-index.html
@mkdir -p $(OUTDIR)
cp $< $@
endif
debug:
$(MAKE) DEBUG=1 all
# Ensure the output dir exists, then link. $(WASM_LINK_DEPS) re-links on a
# pre-js change (empty for non-WASM targets). emcc drops SWOS.js/.wasm/.data
# beside the -o target, so pointing TARGET at dist/web moves all four.
$(TARGET): $(OBJECTS) $(WASM_LINK_DEPS) | $(OUTDIR)
$(LINK) $(OBJECTS) -o $@ $(LDFLAGS) $(LDLIBS)
# Create output directory if needed ($(OUTDIR) is bin/ for every native target)
$(OUTDIR):
mkdir -p $(OUTDIR)
# Compile each src/*.c into build/<os>/<arch>/*.o (mirrors src/ subdirs, e.g.
# src/generated/x.c -> $(OBJDIR)/generated/x.o). The mkdir creates the
# per-target object tree on first build.
# A fork's mods (src/fork_mods.inc, include/mod_api.h): __has_include finds it, but make would not
# rebuild mods_builtin.o the first time it appears -- the fork's mods silently missing.
$(OBJDIR)/mods_builtin.o: $(wildcard $(SRCDIR)/fork_mods.inc)
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.m $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CC) -x objective-c -fobjc-arc $(CFLAGS) -c $< -o $@
ifeq ($(SHADERCC),1)
$(OBJDIR)/shadercc/%.o: third_party/%.cpp $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CXX) $(SHADERCC_CXXFLAGS) -c $< -o $@
endif
ifeq ($(NETPLAY),1)
$(OBJDIR)/ggpo/%.o: $(GGPO_DIR)/lib/ggpo/%.cpp $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CXX) $(GGPO_CXXFLAGS) -c $< -o $@
# Our C++ shim needs GGPO's include path AND our own build defines: compiled
# with GGPO_CXXFLAGS alone, SWOS_SDL_BUILD/SWOS_NETPLAY are undefined and the
# whole file preprocesses away to an empty object that links without error and
# resolves nothing.
$(OBJDIR)/netplay_netem_install.o: $(SRCDIR)/netplay_netem_install.cpp $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CXX) $(GGPO_CXXFLAGS) -DSWOS_SDL_BUILD=1 -DSWOS_NETPLAY=1 -Iinclude -c $< -o $@
$(OBJDIR)/enet/%.o: $(ENET_DIR)/%.c $(BUILD_FLAGS_STAMP)
@mkdir -p $(dir $@)
$(CC) $(ENET_CFLAGS) -c $< -o $@
endif
# Compile the Windows resource file (icon) on MinGW/Cygwin builds. The output
# is COFF-format and gets linked into the final exe.
$(OBJDIR)/SWOS.res.o: SWOS.rc SWOS.ico
@mkdir -p $(dir $@)
$(WINDRES) -O coff $< $@
# Pull in the auto-generated header dependencies (-MMD) so editing a header
# rebuilds just the affected objects — no more blanket `make clean`.
-include $(DEPS)