-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
788 lines (704 loc) · 36.9 KB
/
Copy pathMakefile
File metadata and controls
788 lines (704 loc) · 36.9 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
# Requires GNU make. On BSD: pkg_add gmake (or pkg install gmake), then run gmake.
APP_NAME="\"Pakka\""
MAJOR=1
MINOR=9
PATCH=0
BUILD_DATE="\"$(shell date +'%b %d, %Y')\""
VERSION="\"$(MAJOR).$(MINOR).$(PATCH)\""
TARGET=pakka
# _XOPEN_SOURCE=700 (POSIX.1-2008 + XSI) — needed for realpath():
# glibc gates it on __USE_XOPEN_EXTENDED, musl on _XOPEN_SOURCE, neither
# on _POSIX_C_SOURCE.
# _FILE_OFFSET_BITS=64 — widens off_t / fseeko / ftello on 32-bit glibc
# so pakka_platform_fseek/ftell can address the [2 GiB, 4 GiB) range.
CPPFLAGS = -Iinclude -Isrc -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64 -D_DEBUG=1 -DAPP_NAME=$(APP_NAME) -DVERSION=$(VERSION) -DBUILD_DATE=$(BUILD_DATE)
# Opt-in fault-injection hook (PAKKA_INJECT_FAULT_AT="op:N" env var,
# read by pakka_test_should_fault in src/platform.c). Compiled into
# binaries only when the user invokes a test target, so a plain
# `make` produces a release-style build without the hook. `make test`
# (and any realpak target) sets PAKKA_TEST_BUILD across libpakka +
# the C test binaries so the hook is reachable from the in-process
# fault-injection cases in test/pk3_test.c. CMake / Windows release
# builds never define PAKKA_TEST_BUILD.
ifneq ($(filter test test-fault realpak-test realpak-test-q3 realpak-test-goldsrc, $(MAKECMDGOALS)),)
CPPFLAGS += -DPAKKA_TEST_BUILD
PAKKA_BUILD_MODE := test
else
PAKKA_BUILD_MODE := prod
endif
CC=cc $(CPPFLAGS)
CFLAGS=-g -Wall --std=c99 --pedantic
AR ?= ar
SRC_DIR=src
INCLUDE_DIR=include
BUILD_DIR=build
# Per-build-mode object + library directories. `make` and `make test`
# compile with different CPPFLAGS (the latter adds -DPAKKA_TEST_BUILD),
# so sharing OBJ/LIB lets the wrong-flavor .o or .a be reused after a
# mode switch — especially painful at second-resolution mtime
# comparisons where back-to-back builds collide. Splitting per mode
# keeps each cache warm and avoids the ambiguity. The C test binaries
# under build/test/ link directly against the per-mode libpakka.a via
# the $(LIBPAKKA) Makefile variable, so the right archive is always
# selected.
OBJ_DIR=$(BUILD_DIR)/obj-$(PAKKA_BUILD_MODE)
LIB_DIR=$(BUILD_DIR)/lib-$(PAKKA_BUILD_MODE)
TEST_DIR=$(BUILD_DIR)/test
SOURCES=$(wildcard $(SRC_DIR)/*.c)
# DEFLATE backend selection. Default: bundled sdefl + sinfl single-
# header codecs (no external dependency). Opt-in: PAKKA_DEFLATE_BACKEND=zlib
# routes through the host's libz instead, useful for integrators (game
# engines) that already link zlib and don't want to carry the ~1400
# LOC of bundled codec code in their binary. Only one backend is
# compiled per build — the deflate impl files live under src/deflate/
# which the top-level wildcard above doesn't reach, so the conditional
# below is the only way they enter the source list.
PAKKA_DEFLATE_BACKEND ?= vendored
# Two-level if/else rather than `else ifeq` — GNU make 3.79.1 (the
# legacy floor; default on Red Hat 9 / Sarge) errors out on the
# combined form. The nested shape works on every supported make
# version from 3.79.1 forward.
ifeq ($(PAKKA_DEFLATE_BACKEND),zlib)
DEFLATE_SOURCES=$(SRC_DIR)/deflate/deflate_zlib.c
LDLIBS += -lz
else
ifeq ($(PAKKA_DEFLATE_BACKEND),vendored)
DEFLATE_SOURCES=$(SRC_DIR)/deflate/deflate_vendored.c
else
$(error PAKKA_DEFLATE_BACKEND must be 'vendored' or 'zlib', got '$(PAKKA_DEFLATE_BACKEND)')
endif
endif
# Vendored sources live under src/vendor/. Kept out of $(SOURCES) so
# the lint target (clang-tidy WarningsAsErrors:'*') skips them — patches
# against upstream are out of scope. The objects still land in
# libpakka.a via LIB_OBJECTS. The glob stays narrow on purpose: a
# broader src/vendor/*/*.c pattern would unconditionally pull in
# src/vendor/wingetopt/getopt.c + src/vendor/dirent/*.c, which are
# Windows-only shims gated under WIN32 in CMakeLists.txt and not
# linkable on Unix.
ifeq ($(PAKKA_DEFLATE_BACKEND),vendored)
VENDOR_SOURCES=$(wildcard $(SRC_DIR)/vendor/sdefl/*.c) \
$(wildcard $(SRC_DIR)/vendor/sinfl/*.c)
else
VENDOR_SOURCES=
endif
OBJECTS=$(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) \
$(DEFLATE_SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# Library is every src/*.c except cli.c (CLI-only) plus the selected
# deflate backend impl plus the vendored objects. `symbol-audit` below
# enforces only pakka_*-prefixed names leave the archive — both sdefl
# and sinfl were renamed `sdefl_`/`sinfl_` -> `pakka_sdefl_`/`pakka_sinfl_`
# at vendor time so they pass the same gate. The zlib backend links
# against host libz at executable-link time; libz's own symbols appear
# only as undefined references (U flag) in libpakka.a and don't
# violate the pakka_*-prefix rule.
LIB_SOURCES=$(filter-out $(SRC_DIR)/cli.c,$(SOURCES)) $(DEFLATE_SOURCES)
LIB_OBJECTS=$(LIB_SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) \
$(VENDOR_SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
CLI_OBJECTS=$(OBJ_DIR)/cli.o
LIBPAKKA=$(LIB_DIR)/libpakka.a
# Fixture URLs + SHA-256 pins live in dev/fixtures.mk so the CI cache
# key can hash just that file and stay warm across unrelated Makefile
# edits. dev/win/fixtures.ps1 parses the same file on Windows — single
# source of truth for both build systems.
include dev/fixtures.mk
QUAKE_TARBALL=$(TEST_DIR)/quakesw.tar.gz
PAK0=$(TEST_DIR)/pak0.pak
# Q3 demo wrapper from archive.org (redistribution of id's freely
# distributable demo). Used by the optional `realpak-test-q3` target
# only — not pulled by default `make test`. archive.org's CDN is
# occasionally 503; if the fetch fails, realpak-test-q3 fails but
# normal CI is unaffected.
Q3DEMO_ZIP=$(TEST_DIR)/q3demo.zip
Q3DEMO_PAK0_PK3=$(TEST_DIR)/q3demo/pak0.pk3
# GoldSrc PAK fixtures — two real Valve-built PACK archives from the
# Half-Life 1 lineage. GoldSrc PAK is bit-identical to Quake/Q2 PAK
# (same 12-byte header, 56-byte names, 64-byte entries), so these are
# parity-confirmation fixtures against real Valve writer output, not a
# separate code path. Driven by `realpak-test-goldsrc` (separate from
# the Q3 demo's `realpak-test-q3`); default `make test` leaves them
# untouched.
#
# Both wrappers are plain ZIPs from archive.org; we unzip then copy
# the inner pak0 out to a canonical path under build/test/. unzip is
# in every base Linux/BSD/macOS install — no extra dependency vs. the
# 7z/unrar paths the upstream archive uploaders could have chosen.
#
# Fixture A: Half-Life Uplink (1999 free standalone demo Valve made
# public for the launch promotion; the executable was distributed
# free of charge). 48 MiB zip from the half-life-day-one archive.org
# item (a community upload — pakka does not assert authorship; the
# SHA pin and the runtime-only fetch keep us out of bundling them).
# Inner path Half-LifeUplink/valve/pak0.PAK (uppercase extension, as
# the original shipped).
# Fixture B: Half-Life: Day One (1998 OEM video-card-bundled demo
# that came with retail Voodoo cards of the period). 90 MiB zip from
# the same archive.org item. Inner path Half-Life Day One/valve/pak0.pak.
# Both fixtures are fetched at test time only; the SHA pin ensures
# we run against the exact bytes we tested against. Neither file is
# committed to this repository.
GOLDSRC_UPLINK_WRAPPER=$(TEST_DIR)/hl-uplink.zip
GOLDSRC_UPLINK_PAK0=$(TEST_DIR)/hl-uplink/valve/pak0.pak
GOLDSRC_DAYONE_WRAPPER=$(TEST_DIR)/hl-dayone.zip
GOLDSRC_DAYONE_PAK0=$(TEST_DIR)/hl-dayone/valve/pak0.pak
CLANG_TIDY ?= clang-tidy
NM ?= nm
# Install paths. PREFIX defaults to /usr/local to match the autoconf
# convention; on most systems that requires root to write to, so plain
# `make install` will fail with permission denied unless run with sudo.
# Override PREFIX (and/or DESTDIR for packager staging) per invocation:
# sudo make install # system-wide /usr/local
# make install PREFIX=$$HOME/.local # user-only, no root
# make install DESTDIR=/tmp/stage # packager staging
# `make uninstall` reverses any of these — use the same overrides.
# install -d (create parents) + install -m work on both BSD install
# (macOS / *BSD) and GNU install (Linux); we avoid GNU-only -D.
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
MANDIR ?= $(PREFIX)/share/man
DOCDIR ?= $(PREFIX)/share/doc/pakka
INSTALL ?= install
# Source-distribution tarball name (no `v` prefix, matches the GitHub
# release artifact CPack writes on the Windows side). `make dist`
# produces $(DIST_NAME).tar.gz plus a SHA-256 sidecar via `git archive
# HEAD` — release.yml guarantees HEAD == tagged version when this runs
# in CI.
DIST_NAME = pakka-$(MAJOR).$(MINOR).$(PATCH)
# Public header. Linted explicitly via lint-header so transitive-include
# regressions in include/pakka.h surface even when every internal TU
# happens to pull in the missing dependency for unrelated reasons.
PUBLIC_HEADERS = $(INCLUDE_DIR)/pakka.h
.PHONY: all clean test test-clean distclean install uninstall dist lint lint-header lint-advisory lint-win32 coverage fuzz fuzz-open fuzz-dk fuzz-roundtrip symbol-audit c_api_test dk_codec_test verify-tarball verify-q3demo verify-goldsrc-uplink verify-goldsrc-dayone fixture realpak-test realpak-test-q3 realpak-test-goldsrc
# Force serial execution. force-relink (below) deletes $(TARGET) and
# $(LIBPAKKA) as a sibling prereq of `all` / `test`; under `make -j`
# that races with the link rules and the c_api_test / dk_codec_test
# recipes that read $(LIBPAKKA). pakka is small enough that serial
# build is under a few seconds — the parallel-make speedup wouldn't
# be worth the race fragility.
.NOTPARALLEL:
all: force-relink $(TARGET)
# Always rebuild the top-level binary and per-mode libpakka.a. GNU
# Make 3.81 (Apple's default) compares mtimes at second resolution,
# so back-to-back `make` ↔ `make test` invocations can land in the
# same second and leave the wrong-flavor binary in place. The
# per-mode .o cache still survives (build/obj-prod/ vs obj-test/), so
# this only adds a relink — a fraction of a second.
.PHONY: force-relink
force-relink:
@rm -f $(TARGET) $(LIBPAKKA)
clean:
rm -rf $(BUILD_DIR)/obj-* $(BUILD_DIR)/lib-* $(BUILD_DIR)/fuzz $(BUILD_DIR)/coverage $(TARGET)
test-clean:
rm -rf $(TEST_DIR)/extracted $(TEST_DIR)/re_extracted $(TEST_DIR)/rebuilt.pak $(TEST_DIR)/crud $(TEST_DIR)/id1
distclean:
rm -rf $(BUILD_DIR) $(TARGET)
rm -f pakka-*.tar.gz pakka-*.tar.gz.sha256
# Install layout mirrors the autoconf / GNU install conventions:
# $(PREFIX)/bin/pakka — CLI binary
# $(PREFIX)/lib/libpakka.a — static library
# $(PREFIX)/include/pakka.h — public C99 header
# $(PREFIX)/share/man/man1/pakka.1 — CLI manpage
# $(PREFIX)/share/man/man3/pakka.3 — libpakka manpage
# $(PREFIX)/share/doc/pakka/{README.md,LICENSE} — docs
# DESTDIR is honored for staged installs (packagers).
#
# force-relink is a prereq so a prior `make test` (which compiles in the
# PAKKA_TEST_BUILD fault-injection hooks) can never leave a stale test-
# flavored ./pakka in place that the next `make install` would copy to
# $(BINDIR). Same guard `all` and `test` already use — install honors it
# for the prod side.
install: force-relink $(TARGET) $(LIBPAKKA)
$(INSTALL) -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) \
$(DESTDIR)$(INCLUDEDIR) \
$(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(MANDIR)/man3 \
$(DESTDIR)$(DOCDIR)
$(INSTALL) -m 0755 $(TARGET) $(DESTDIR)$(BINDIR)/pakka
$(INSTALL) -m 0644 $(LIBPAKKA) $(DESTDIR)$(LIBDIR)/libpakka.a
$(INSTALL) -m 0644 $(INCLUDE_DIR)/pakka.h $(DESTDIR)$(INCLUDEDIR)/pakka.h
$(INSTALL) -m 0644 man/pakka.1 $(DESTDIR)$(MANDIR)/man1/pakka.1
$(INSTALL) -m 0644 man/pakka.3 $(DESTDIR)$(MANDIR)/man3/pakka.3
$(INSTALL) -m 0644 README.md LICENSE $(DESTDIR)$(DOCDIR)/
uninstall:
rm -f $(DESTDIR)$(BINDIR)/pakka
rm -f $(DESTDIR)$(LIBDIR)/libpakka.a
rm -f $(DESTDIR)$(INCLUDEDIR)/pakka.h
rm -f $(DESTDIR)$(MANDIR)/man1/pakka.1
rm -f $(DESTDIR)$(MANDIR)/man3/pakka.3
rm -rf $(DESTDIR)$(DOCDIR)
# Source tarball for distribution. `git archive HEAD` snapshots the
# committed tree (so uncommitted edits never leak into a release), and
# the --prefix= shape gives extractors a versioned top-level directory.
# The SHA-256 sidecar uses the same `openssl dgst -sha256` form the
# fixture-verify targets already rely on (portable across macOS,
# Linux, OpenBSD, FreeBSD).
dist:
git archive --format=tar.gz --prefix=$(DIST_NAME)/ \
-o $(DIST_NAME).tar.gz HEAD
@actual=`openssl dgst -sha256 $(DIST_NAME).tar.gz | awk '{print $$NF}'`; \
echo "$$actual $(DIST_NAME).tar.gz" > $(DIST_NAME).tar.gz.sha256
@echo "==> $(DIST_NAME).tar.gz"
@echo "==> $(DIST_NAME).tar.gz.sha256"
# Verify the public header parses as standalone C with the same warning
# flags the rest of the codebase uses. Catches regressions where the
# header silently relies on transitive includes from an internal TU.
lint-header:
$(CC) $(CFLAGS) -fsyntax-only -x c $(PUBLIC_HEADERS)
lint: lint-header lint-advisory
$(CLANG_TIDY) --quiet $(SOURCES) $(PUBLIC_HEADERS) -- $(CPPFLAGS) --std=c99
# Cross-arm lint: run clang-tidy against the _WIN32 branch of every
# Win32-aware source. Linux's mingw-w64 headers stand in for the
# MSVC SDK so we can syntax-check the Windows arm without an MSVC
# toolchain. Catches regressions where someone touches src/platform.{h,c},
# src/cli.c's CLI path, or src/pakfile.c's PAKKA_ERR_DOMAIN_WIN32
# rebuild branches and ships a subtle break that only the
# windows-msvc job would catch. Targets src/cli.c + src/platform.c +
# src/pakfile.c — the three files with non-trivial _WIN32 code.
#
# Skips cleanly when the cross-headers are absent (e.g. on macOS
# without `brew install mingw-w64` — note Homebrew places them
# under $(brew --prefix mingw-w64), not /usr; override via
# `make WIN32_HEADERS=... lint-win32`). On Ubuntu the apt package
# `mingw-w64` drops them at the default path.
#
# CI sets REQUIRE_WIN32_HEADERS=1 to fail rather than skip when
# the headers are missing — installations there are deterministic
# and a missing-package case is a CI bug, not user laxness.
.PHONY: lint-win32
WIN32_HEADERS ?= /usr/x86_64-w64-mingw32/include
lint-win32:
@if [ ! -d "$(WIN32_HEADERS)" ]; then \
if [ "$(REQUIRE_WIN32_HEADERS)" = "1" ]; then \
echo "lint-win32: Mingw cross-headers required but not found at $(WIN32_HEADERS)" >&2; \
exit 1; \
fi; \
echo "lint-win32: Mingw cross-headers not found at $(WIN32_HEADERS)"; \
echo "lint-win32: install via apt-get install mingw-w64 on Linux"; \
echo "lint-win32: or brew install mingw-w64 on macOS"; \
echo "lint-win32: (override path with WIN32_HEADERS=... if installed elsewhere); skipping"; \
exit 0; \
fi; \
$(CLANG_TIDY) --quiet \
--header-filter='(common|platform|filesystem|pakka)\.h$$' \
src/cli.c src/platform.c src/pakfile.c $(PUBLIC_HEADERS) -- \
$(CPPFLAGS) \
--target=x86_64-w64-mingw32 \
-isystem $(WIN32_HEADERS) \
-Isrc -Isrc/vendor/wingetopt -Isrc/vendor/dirent \
--std=c99 \
-Wno-pragma-pack -Wno-pragma-system-header-outside-header
# Advisory lints — print warnings but don't fail the build. Today this
# is the add-path symmetry check (catches re-divergence of the H1
# hardening). Set STRICT=1 to make it fail on findings. Kept out of
# clang-tidy because the rule isn't easily expressed as a tidy check
# and we want it as a tripwire, not a gate.
.PHONY: lint-advisory
lint-advisory:
@dev/lint/add-path-symmetry.sh $(CURDIR)
# Coverage report. Builds with -fprofile-arcs -ftest-coverage, runs
# the full C test suite, and renders an HTML lcov tree under
# build/coverage/. Needs lcov + genhtml; on macOS install via
# `brew install lcov`. Not wired into `make test` because the
# instrumented build adds ~30% runtime to the test pass and the
# report is only useful as a periodic artifact, not on every iteration.
# libFuzzer harnesses. Need clang with -fsanitize=fuzzer (Ubuntu's
# clang ships this by default; macOS needs `brew install llvm` +
# `CC=$(brew --prefix llvm)/bin/clang`). Built into build/fuzz/ with
# ASan as the bug oracle and the seed corpora living in dev/fuzz/.
# `make fuzz` builds all three; the per-target rules (fuzz-open,
# fuzz-dk, fuzz-roundtrip) build one harness each. CI runs each for
# 60s on push to master.
FUZZ_CC ?= clang
FUZZ_DIR := $(BUILD_DIR)/fuzz
FUZZ_CFLAGS := -g -O1 -Wall --std=c99 \
-fsanitize=fuzzer,address,undefined \
-fno-sanitize-recover=undefined \
-fno-omit-frame-pointer
.PHONY: fuzz fuzz-open fuzz-dk fuzz-roundtrip
fuzz: fuzz-open fuzz-dk fuzz-roundtrip
# Each fuzzer compiles ALL library sources from scratch with the fuzz
# CFLAGS — libpakka-prod / libpakka-test were built without
# -fsanitize=fuzzer so we can't reuse them. The footprint is small
# (one .o file per source per harness) and the alternative is a
# third per-mode library that few people use.
# Compile flags shared by every fuzz harness. Mirrors the standard
# CPPFLAGS minus -DPAKKA_TEST_BUILD (no fault hooks needed) and minus
# -D_DEBUG so libFuzzer's stdout doesn't compete with library debug
# prints.
FUZZ_CPPFLAGS := -Iinclude -Isrc -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64 \
-DAPP_NAME=$(APP_NAME) -DVERSION=$(VERSION) \
-DBUILD_DATE=$(BUILD_DATE)
$(FUZZ_DIR)/pakka_fuzz_open: dev/fuzz/pakka_fuzz_open.c $(LIB_SOURCES) $(VENDOR_SOURCES)
@mkdir -p $(FUZZ_DIR)
$(FUZZ_CC) $(FUZZ_CFLAGS) $(FUZZ_CPPFLAGS) -o $@ $^
$(FUZZ_DIR)/pakka_fuzz_dk_inflate: dev/fuzz/pakka_fuzz_dk_inflate.c $(LIB_SOURCES) $(VENDOR_SOURCES)
@mkdir -p $(FUZZ_DIR)
$(FUZZ_CC) $(FUZZ_CFLAGS) $(FUZZ_CPPFLAGS) -o $@ $^
$(FUZZ_DIR)/pakka_fuzz_roundtrip: dev/fuzz/pakka_fuzz_roundtrip.c $(LIB_SOURCES) $(VENDOR_SOURCES)
@mkdir -p $(FUZZ_DIR)
$(FUZZ_CC) $(FUZZ_CFLAGS) $(FUZZ_CPPFLAGS) -o $@ $^
fuzz-open: $(FUZZ_DIR)/pakka_fuzz_open
fuzz-dk: $(FUZZ_DIR)/pakka_fuzz_dk_inflate
fuzz-roundtrip: $(FUZZ_DIR)/pakka_fuzz_roundtrip
# Local benchmark harness. Times the CLI against a fixed workload table
# via hyperfine, with optional cross-ref comparison driven by a side
# git worktree. Not wired into CI — shared runners are too noisy for
# perf numbers; the bench is a developer tool. See dev/bench/README.md.
#
# NOTE: bench targets are deliberately NOT in the MAKECMDGOALS filter at
# the top of this file that enables -DPAKKA_TEST_BUILD. The synth tool
# and the pakka binary the bench measures must be the release-style
# build so timings reflect what library consumers actually run.
BENCH_DIR := $(BUILD_DIR)/bench
BENCH_SYNTH := $(BENCH_DIR)/synth_tool
.PHONY: bench bench-compare bench-clean
$(BENCH_SYNTH): dev/bench/synth.c $(LIBPAKKA)
@mkdir -p $(BENCH_DIR)
$(CC) $(CFLAGS) -o $@ dev/bench/synth.c $(LIBPAKKA) $(LDLIBS)
bench: $(TARGET) $(BENCH_SYNTH)
@dev/bench/run.sh ./$(TARGET) $(BENCH_SYNTH)
# Usage: make bench-compare REF=v1.5.0
bench-compare: $(TARGET) $(BENCH_SYNTH)
@if [ -z "$(REF)" ]; then \
echo "Usage: make bench-compare REF=<git-ref>" >&2; \
exit 1; \
fi
@dev/bench/compare.sh $(REF)
bench-clean:
@dev/bench/compare.sh --clean 2>/dev/null || true
@rm -rf $(BENCH_DIR)
.PHONY: coverage
coverage:
@command -v lcov >/dev/null 2>&1 || { echo "coverage: lcov not found (brew install lcov / apt-get install lcov)" >&2; exit 1; }
@command -v genhtml >/dev/null 2>&1 || { echo "coverage: genhtml not found" >&2; exit 1; }
$(MAKE) clean
$(MAKE) CFLAGS="-g -O0 -Wall --std=c99 --pedantic -fprofile-arcs -ftest-coverage" test
@mkdir -p $(BUILD_DIR)/coverage
# Inner $(MAKE) ... test sets PAKKA_BUILD_MODE=test, so .gcno/.gcda
# land in build/obj-test/. Outer make sees no test goal and
# would otherwise resolve $(OBJ_DIR) to build/obj-prod/ — capture
# from the actual instrumented directory by name.
lcov --capture --directory $(BUILD_DIR)/obj-test \
--output-file $(BUILD_DIR)/coverage/coverage.info \
--rc geninfo_unexecuted_blocks=1
# --ignore-errors unused: lcov 2.x treats "exclude pattern matched
# zero files" as a hard error. /usr/* and /Library/* are platform-
# specific noise that may or may not be present in the .info file
# depending on which host ran the build; suppressing the unused-
# pattern check lets a single pattern set serve macOS + Linux.
lcov --remove $(BUILD_DIR)/coverage/coverage.info '*/src/vendor/*' '/usr/*' '/Library/*' \
--ignore-errors unused \
--output-file $(BUILD_DIR)/coverage/filtered.info
genhtml $(BUILD_DIR)/coverage/filtered.info --output-directory $(BUILD_DIR)/coverage/html \
--legend --quiet
@echo "==> Coverage report: $(BUILD_DIR)/coverage/html/index.html"
# Hard gate against non-pakka_ defined globals leaking out of
# libpakka.a. Prints the full list AND exits non-zero on any violation;
# `make test` depends on this. Filters NF==3 to skip nm's "filename:"
# lines and 2-field undefined refs. Includes 'C' (tentative/common)
# alongside T/D/B/R/S so an uninitialized global can't sneak past.
# Skips names containing '.' — those are compiler-emitted artifacts
# like gcc's i386 PIC thunks _x86.get_pc_thunk.{ax,bx,si}; legitimate
# C identifiers can't contain a dot, so this can't hide a pakka leak.
symbol-audit: $(LIBPAKKA)
@all=`$(NM) -g $(LIBPAKKA) | awk 'NF == 3 && $$2 ~ /^[TDBRSC]$$/ { sub(/^_/, "", $$3); if ($$3 ~ /\./) next; print $$3 }' | sort -u`; \
bad=`printf '%s\n' "$$all" | grep -v '^pakka_' | grep -Ev '^(_+(asan|ubsan|tsan|msan|hwasan|lsan)_|_*asan\.module_ctor|_*asan\.module_dtor)' || true`; \
printf '%s\n' "$$all"; \
if [ -n "$$bad" ]; then \
echo "" >&2; \
echo "symbol-audit FAILED: non-pakka_ defined globals in $(LIBPAKKA):" >&2; \
printf '%s\n' "$$bad" >&2; \
exit 1; \
fi
$(TARGET): $(CLI_OBJECTS) $(LIBPAKKA)
$(CC) $(CFLAGS) -o $(TARGET) $(CLI_OBJECTS) $(LIBPAKKA) $(LDLIBS)
# ar rcs: r = insert/replace, c = create silently, s = write index.
# Inline mkdir keeps us GNU make 3.79.1 compatible (no order-only prereqs).
$(LIBPAKKA): $(LIB_OBJECTS)
@mkdir -p $(LIB_DIR)
$(AR) rcs $@ $(LIB_OBJECTS)
# C-API test binary. Built against the public include/ surface only,
# linked against the static archive. Exercises every pakka_* public
# function: NULL tolerance, structured-error population, opaque-entry
# accessors, the streaming reader, add/delete/commit round-trips, and
# the verify report callback — none of which black-box CLI tests can
# reach.
C_API_TEST = $(TEST_DIR)/c_api_test
$(C_API_TEST): test/c_api_test.c $(LIBPAKKA)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -o $@ test/c_api_test.c $(LIBPAKKA) $(LDLIBS)
c_api_test: $(C_API_TEST)
# DK-codec exerciser. Unlike c_api_test (which is public-surface only),
# this test calls pakka_dk_inflate directly through src/common.h. The
# codec lives behind the library symbol audit (pakka_dk_inflate), so
# linking against $(LIBPAKKA) is enough — no separate object compile.
DK_CODEC_TEST = $(TEST_DIR)/dk_codec_test
$(DK_CODEC_TEST): test/dk_codec_test.c $(LIBPAKKA)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Iinclude -Isrc -o $@ test/dk_codec_test.c $(LIBPAKKA) $(LDLIBS)
dk_codec_test: $(DK_CODEC_TEST)
# Shared test-support library (test/support/*.c). Compiled once into a
# static archive linked by every C test binary. Provides assertion
# macros (test_macros.h), cross-platform process spawn (proc.{h,c}),
# and filesystem / text helpers.
TEST_SUPPORT_SRC := $(wildcard test/support/*.c)
TEST_SUPPORT_OBJ := $(patsubst test/support/%.c, $(TEST_DIR)/support/%.o, $(TEST_SUPPORT_SRC))
TEST_SUPPORT_LIB := $(TEST_DIR)/libtest_support.a
$(TEST_DIR)/support/%.o: test/support/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -c $< -o $@
$(TEST_SUPPORT_LIB): $(TEST_SUPPORT_OBJ)
$(AR) rcs $@ $(TEST_SUPPORT_OBJ)
# Self-test for the proc helper: spawns itself in "child mode" to
# exercise stdout / stderr capture, large-output deadlock avoidance,
# cwd and env override, timeout, and argv quoting.
PROC_SELF_TEST = $(TEST_DIR)/proc_self_test
$(PROC_SELF_TEST): test/proc_self_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/proc_self_test.d -o $@ test/proc_self_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
proc_self_test: $(PROC_SELF_TEST)
# Large-file regression — 32-bit fseek/ftell ceiling. Synthesizes a
# 2.6 GB sparse pak whose directory sits above LONG_MAX.
LARGE_FILE_TEST = $(TEST_DIR)/large_file_test
$(LARGE_FILE_TEST): test/large_file_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/large_file_test.d -o $@ test/large_file_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
large_file_test: $(LARGE_FILE_TEST)
# PK4 (Doom 3) container format tests. Builds DEFLATE fixtures via
# pakka -c --compress; covers list / extract / verify / create /
# delete-rebuild against the resulting archives.
PK4_TEST = $(TEST_DIR)/pk4_test
$(PK4_TEST): test/pk4_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/pk4_test.d -o $@ test/pk4_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
pk4_test: $(PK4_TEST)
# SiN pak format tests. Inline binary writer for the cases that
# synthesize SPAK paks directly; the rest drive pakka itself to build
# fixtures.
SIN_TEST = $(TEST_DIR)/sin_test
$(SIN_TEST): test/sin_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/sin_test.d -o $@ test/sin_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
sin_test: $(SIN_TEST)
# WAD (Doom IWAD/PWAD) tests. Inline WAD binary writer + header
# inspection; covers IWAD / PWAD / lump-directory paths.
WAD_TEST = $(TEST_DIR)/wad_test
$(WAD_TEST): test/wad_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/wad_test.d -o $@ test/wad_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
wad_test: $(WAD_TEST)
# Daikatana pak format tests. Inline DK binary writer (72-byte
# entries, literal-run opcode encoder) + directory probe; includes the
# real-fixture cross-validation against test/fixtures/dk/user.pak.
DK_TEST = $(TEST_DIR)/dk_test
$(DK_TEST): test/dk_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/dk_test.d -o $@ test/dk_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
dk_test: $(DK_TEST)
# Quake PAK format tests. End-to-end CLI surface against pak0.pak plus
# per-policy synthetic-pak cases (name validation, normalization-
# collision rejection, --tree rendering, bounds checks, --as alias).
# POSIX-only cases (symlink rejection, read-only chmod) gate on
# #ifndef _WIN32. Needs PAK0 env var pointing at the canonical fixture.
PAKKA_TEST = $(TEST_DIR)/pakka_test
$(PAKKA_TEST): test/pakka_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/pakka_test.d -o $@ test/pakka_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
pakka_test: $(PAKKA_TEST)
# PK3 (Quake 3 / ZIP) tests. Drives pakka through the CLI for the
# structural read/write surface and links libpakka for the in-process
# c-api harness (max_decompressed cap, commit/rebuild rollback,
# format-probe).
PK3_TEST = $(TEST_DIR)/pk3_test
$(PK3_TEST): test/pk3_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/pk3_test.d -o $@ test/pk3_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA) $(LDLIBS)
pk3_test: $(PK3_TEST)
# Q3 demo realpak tests against id's real Q3 demo pak0.pk3. Gated on
# Q3DEMO_PAK0_PK3 — every case SKIPs when unset, so this is safe to
# include in default `make test`. Links libpakka because the format-
# probe case calls pakka_open / pakka_format in-process.
PK3_Q3DEMO_TEST = $(TEST_DIR)/pk3_q3demo_test
$(PK3_Q3DEMO_TEST): test/pk3_q3demo_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/pk3_q3demo_test.d -o $@ test/pk3_q3demo_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA) $(LDLIBS)
pk3_q3demo_test: $(PK3_Q3DEMO_TEST)
# GoldSrc PAK realpak tests — Half-Life Uplink + Day One fixtures.
# Each is independently env-var gated; missing fixtures SKIP rather
# than fail. Links libpakka because the format-probe case calls
# pakka_open / pakka_format in-process.
PAK_GOLDSRC_TEST = $(TEST_DIR)/pak_goldsrc_test
$(PAK_GOLDSRC_TEST): test/pak_goldsrc_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/pak_goldsrc_test.d -o $@ test/pak_goldsrc_test.c $(TEST_SUPPORT_LIB) $(LIBPAKKA) $(LDLIBS)
pak_goldsrc_test: $(PAK_GOLDSRC_TEST)
# Unicode path handling. Exercises the UTF-8 argv flow on Windows
# (proc.c handles it via CreateProcessW + MultiByteToWideChar at the
# boundary) plus the legacy CP1251 substitution / sanitization paths
# on POSIX too.
UNICODE_PATHS_TEST = $(TEST_DIR)/unicode_paths_test
$(UNICODE_PATHS_TEST): test/unicode_paths_test.c $(TEST_SUPPORT_LIB)
@mkdir -p $(TEST_DIR)
$(CC) $(CFLAGS) -Itest/support -MMD -MP -MF $(TEST_DIR)/unicode_paths_test.d -o $@ test/unicode_paths_test.c $(TEST_SUPPORT_LIB) $(LDLIBS)
unicode_paths_test: $(UNICODE_PATHS_TEST)
# Header-dependency files emitted by -MMD. The leading minus silences
# the "no rule to make .d" complaint on a fresh tree (the .d files only
# exist after the corresponding .o or test binary is built once).
-include $(TEST_SUPPORT_OBJ:.o=.d)
-include $(TEST_DIR)/proc_self_test.d
-include $(TEST_DIR)/large_file_test.d
-include $(TEST_DIR)/pk4_test.d
-include $(TEST_DIR)/sin_test.d
-include $(TEST_DIR)/wad_test.d
-include $(TEST_DIR)/dk_test.d
-include $(TEST_DIR)/pakka_test.d
-include $(TEST_DIR)/pk3_test.d
-include $(TEST_DIR)/pk3_q3demo_test.d
-include $(TEST_DIR)/pak_goldsrc_test.d
-include $(TEST_DIR)/unicode_paths_test.d
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
# Order-only prereqs (`|`) arrived in GNU make 3.80; 3.79.1 errors on
# them, so we keep the directory creation inline.
$(QUAKE_TARBALL):
@mkdir -p $(TEST_DIR)
@echo "==> Downloading Quake shareware ($(QUAKE_URL))"
@curl -fsSL -o $(QUAKE_TARBALL) $(QUAKE_URL)
# Phony so the SHA check runs every build, including cache-restore hits
# where $(QUAKE_TARBALL) is already on disk and would otherwise be skipped.
verify-tarball: $(QUAKE_TARBALL)
@actual=`openssl dgst -sha256 $(QUAKE_TARBALL) | awk '{print $$NF}'`; \
if [ "$$actual" != "$(QUAKE_SHA256)" ]; then \
echo "==> SHA256 mismatch: expected $(QUAKE_SHA256), got $$actual"; \
rm -f $(QUAKE_TARBALL); \
exit 1; \
fi
$(PAK0): verify-tarball
@cd $(TEST_DIR) && tar xzf quakesw.tar.gz
@cp $(TEST_DIR)/id1/pak0.pak $(PAK0)
# Download + SHA-verify pak0.pak only. The Windows CTest path uses
# dev/win/fixtures.ps1 to produce the same fixture on the Windows side;
# this target is the Unix-Makefile entry point.
fixture: $(PAK0)
test: force-relink $(TARGET) $(PAK0) $(C_API_TEST) $(DK_CODEC_TEST) $(PROC_SELF_TEST) $(LARGE_FILE_TEST) $(PK4_TEST) $(SIN_TEST) $(WAD_TEST) $(DK_TEST) $(PAKKA_TEST) $(PK3_TEST) $(PK3_Q3DEMO_TEST) $(PAK_GOLDSRC_TEST) $(UNICODE_PATHS_TEST) symbol-audit
@echo "==> proc_self_test"
@$(PROC_SELF_TEST)
@echo "==> large_file_test"
@PAKKA=$(abspath $(TARGET)) LARGE_FILE_SCRATCH=$(abspath $(TEST_DIR))/large_file $(LARGE_FILE_TEST)
@echo "==> pk4_test"
@PAKKA=$(abspath $(TARGET)) PK4_TEST_SCRATCH=$(abspath $(TEST_DIR))/pk4 $(PK4_TEST)
@echo "==> sin_test"
@PAKKA=$(abspath $(TARGET)) SIN_TEST_SCRATCH=$(abspath $(TEST_DIR))/sin $(SIN_TEST)
@echo "==> wad_test"
@PAKKA=$(abspath $(TARGET)) WAD_TEST_SCRATCH=$(abspath $(TEST_DIR))/wad $(WAD_TEST)
@echo "==> dk_test"
@PAKKA=$(abspath $(TARGET)) DK_TEST_SCRATCH=$(abspath $(TEST_DIR))/dk REPO_ROOT=$(abspath .) $(DK_TEST)
@echo "==> pakka_test"
@PAKKA=$(abspath $(TARGET)) PAK0=$(abspath $(PAK0)) PAKKA_TEST_SCRATCH=$(abspath $(TEST_DIR))/pakka $(PAKKA_TEST)
@echo "==> pk3_test"
@PAKKA=$(abspath $(TARGET)) PK3_TEST_SCRATCH=$(abspath $(TEST_DIR))/pk3 $(PK3_TEST)
@echo "==> pk3_q3demo_test"
@PAKKA=$(abspath $(TARGET)) Q3DEMO_TEST_SCRATCH=$(abspath $(TEST_DIR))/q3demo_scratch $(PK3_Q3DEMO_TEST)
@echo "==> pak_goldsrc_test"
@PAKKA=$(abspath $(TARGET)) GOLDSRC_TEST_SCRATCH=$(abspath $(TEST_DIR))/goldsrc_scratch $(PAK_GOLDSRC_TEST)
@echo "==> unicode_paths_test"
@PAKKA=$(abspath $(TARGET)) UNICODE_TEST_SCRATCH=$(abspath $(TEST_DIR))/unicode $(UNICODE_PATHS_TEST)
@echo "==> dk_codec_test"
@$(DK_CODEC_TEST)
@echo "==> c_api_test"
@rm -rf $(TEST_DIR)/c_api_scratch
@mkdir -p $(TEST_DIR)/c_api_scratch
@$(C_API_TEST) $(PAK0) $(abspath $(TEST_DIR))/c_api_scratch
# Q3 demo wrapper download + SHA verify. archive.org gives SHA1; we
# re-compute SHA256 once at vendor time and pin that here.
$(Q3DEMO_ZIP):
@mkdir -p $(TEST_DIR)
@echo "==> Downloading Q3 demo wrapper ($(Q3DEMO_URL))"
@curl -fsSL -o $(Q3DEMO_ZIP) "$(Q3DEMO_URL)"
verify-q3demo: $(Q3DEMO_ZIP)
@actual=`openssl dgst -sha256 $(Q3DEMO_ZIP) | awk '{print $$NF}'`; \
if [ "$$actual" != "$(Q3DEMO_SHA256)" ]; then \
echo "==> SHA256 mismatch on Q3 demo: expected $(Q3DEMO_SHA256), got $$actual"; \
rm -f $(Q3DEMO_ZIP); \
exit 1; \
fi
# Extract the inner pak0.pk3 from the wrapper using pakka itself —
# tests pakka's PK3 reader against a real id-made archive on the way
# to producing the fixture.
$(Q3DEMO_PAK0_PK3): $(TARGET) verify-q3demo
@mkdir -p $(TEST_DIR)/q3demo_raw
./$(TARGET) -x -C $(TEST_DIR)/q3demo_raw $(Q3DEMO_ZIP) >/dev/null
@mkdir -p $(TEST_DIR)/q3demo
@cp $(TEST_DIR)/q3demo_raw/Quake\ 3\ Arena\ Demo/demoq3/pak0.pk3 $(Q3DEMO_PAK0_PK3)
@echo "==> Q3 demo pak0.pk3 ready: $(Q3DEMO_PAK0_PK3)"
# GoldSrc fixture download + SHA verify + extract. Both wrappers are
# plain ZIPs; we unzip then copy the inner pak file out to the
# canonical $(GOLDSRC_*_PAK0) path. The inner paths use the names
# Valve shipped (spaces, uppercase .PAK) — we normalize to lowercase
# valve/pak0.pak on copy so the realpak env vars
# (GOLDSRC_UPLINK_PAK0 / GOLDSRC_DAYONE_PAK0) point at a predictable
# location.
$(GOLDSRC_UPLINK_WRAPPER):
@mkdir -p $(TEST_DIR)
@echo "==> Downloading Half-Life Uplink demo ($(GOLDSRC_UPLINK_URL))"
@curl -fsSL -o $(GOLDSRC_UPLINK_WRAPPER) "$(GOLDSRC_UPLINK_URL)"
verify-goldsrc-uplink: $(GOLDSRC_UPLINK_WRAPPER)
@actual=`openssl dgst -sha256 $(GOLDSRC_UPLINK_WRAPPER) | awk '{print $$NF}'`; \
if [ "$$actual" != "$(GOLDSRC_UPLINK_SHA256)" ]; then \
echo "==> SHA256 mismatch on Half-Life Uplink: expected $(GOLDSRC_UPLINK_SHA256), got $$actual" >&2; \
rm -f $(GOLDSRC_UPLINK_WRAPPER); \
exit 1; \
fi
$(GOLDSRC_UPLINK_PAK0): verify-goldsrc-uplink
@command -v unzip >/dev/null 2>&1 || { echo "goldsrc fixture: unzip not found" >&2; exit 1; }
@mkdir -p $(TEST_DIR)/hl-uplink-raw $(TEST_DIR)/hl-uplink/valve
unzip -q -o -d $(TEST_DIR)/hl-uplink-raw $(GOLDSRC_UPLINK_WRAPPER)
@cp "$(TEST_DIR)/hl-uplink-raw/Half-LifeUplink/valve/pak0.PAK" $(GOLDSRC_UPLINK_PAK0)
@echo "==> Half-Life Uplink pak0.pak ready: $(GOLDSRC_UPLINK_PAK0)"
$(GOLDSRC_DAYONE_WRAPPER):
@mkdir -p $(TEST_DIR)
@echo "==> Downloading Half-Life: Day One demo ($(GOLDSRC_DAYONE_URL))"
@curl -fsSL -o $(GOLDSRC_DAYONE_WRAPPER) "$(GOLDSRC_DAYONE_URL)"
verify-goldsrc-dayone: $(GOLDSRC_DAYONE_WRAPPER)
@actual=`openssl dgst -sha256 $(GOLDSRC_DAYONE_WRAPPER) | awk '{print $$NF}'`; \
if [ "$$actual" != "$(GOLDSRC_DAYONE_SHA256)" ]; then \
echo "==> SHA256 mismatch on Half-Life: Day One: expected $(GOLDSRC_DAYONE_SHA256), got $$actual" >&2; \
rm -f $(GOLDSRC_DAYONE_WRAPPER); \
exit 1; \
fi
$(GOLDSRC_DAYONE_PAK0): verify-goldsrc-dayone
@command -v unzip >/dev/null 2>&1 || { echo "goldsrc fixture: unzip not found" >&2; exit 1; }
@mkdir -p $(TEST_DIR)/hl-dayone-raw $(TEST_DIR)/hl-dayone/valve
unzip -q -o -d $(TEST_DIR)/hl-dayone-raw $(GOLDSRC_DAYONE_WRAPPER)
@cp "$(TEST_DIR)/hl-dayone-raw/Half-Life Day One/valve/pak0.pak" $(GOLDSRC_DAYONE_PAK0)
@echo "==> Half-Life: Day One pak0.pak ready: $(GOLDSRC_DAYONE_PAK0)"
# Real-archive ("realpak") test suites. Exercise pakka against actual
# game-engine archives downloaded from archive.org rather than the
# synthetic Quake 1 shareware pak used by `make test`. The "realpak"
# label distinguishes them from `make test` (smaller, single-format
# fixture) — they're not slow in wall-clock terms, the C realpak
# tests finish in seconds; the only cost is the first-time fixture
# download, which is SHA-pinned and cached in CI.
# `make realpak-test` is the umbrella — runs both q3 and goldsrc.
realpak-test: realpak-test-q3 realpak-test-goldsrc
# Full PK3 suite against id's real Q3 demo pak0.pk3. Pulls 93 MiB from
# archive.org; CI caches the wrapper zip by dev/fixtures.mk hash so
# reruns skip the download until the pin changes.
realpak-test-q3: $(TARGET) $(Q3DEMO_PAK0_PK3) $(PK3_Q3DEMO_TEST) symbol-audit
@echo "==> pk3_q3demo_test"
@PAKKA=$(abspath $(TARGET)) Q3DEMO_PAK0_PK3=$(abspath $(Q3DEMO_PAK0_PK3)) \
Q3DEMO_TEST_SCRATCH=$(abspath $(TEST_DIR))/q3demo_scratch $(PK3_Q3DEMO_TEST)
# GoldSrc parity-confirmation suite. Kept separate from realpak-test-q3
# because the GoldSrc fixtures are heavier (~138 MiB combined) and add
# a second archive.org dependency on top of the Q3 demo path. Pulls
# the Uplink (48 MiB) and Day One (90 MiB) zip wrappers, extracts
# valve/pak0.pak from each, and runs pak_goldsrc_test against both
# real Valve-built archives.
realpak-test-goldsrc: $(TARGET) $(GOLDSRC_UPLINK_PAK0) $(GOLDSRC_DAYONE_PAK0) $(PAK_GOLDSRC_TEST) symbol-audit
@echo "==> pak_goldsrc_test"
@PAKKA=$(abspath $(TARGET)) \
GOLDSRC_UPLINK_PAK0=$(abspath $(GOLDSRC_UPLINK_PAK0)) \
GOLDSRC_DAYONE_PAK0=$(abspath $(GOLDSRC_DAYONE_PAK0)) \
GOLDSRC_TEST_SCRATCH=$(abspath $(TEST_DIR))/goldsrc_scratch $(PAK_GOLDSRC_TEST)