aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: df2eb4d039eac10a52c4e0455ecae25d48acc730 (plain) (blame)
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
# LibreForts build helpers — thin wrappers around the Podman workflow.
#
# Everything COMPILES inside the container (Fedora + every dependency prebuilt
# in /usr/local, see Containerfile). The binary RUNS on the host, which supplies
# SDL3 and a display. `make run` does both halves in the right place.
#
# Recipe lines are indented with TABs; make requires it.

IMAGE    := forts-clone-dev
BUILDDIR := builddir
BIN      := $(BUILDDIR)/forts-clone

# Run a command in the dev image with the repo bind-mounted at /src.
PODMAN_RUN := podman run --rm -v "$(CURDIR)":/src:Z --userns=keep-id \
	localhost/$(IMAGE):latest bash -c

.DEFAULT_GOAL := build
.PHONY: help image build reconfigure run check check-lua shell clean clean-image

help:
	@echo "LibreForts:"
	@echo "  make image        build the Podman dev image (once, and after"
	@echo "                    editing Containerfile)"
	@echo "  make build        compile in the container (default target)"
	@echo "  make run          compile, then run the game on the host"
	@echo "  make check        compile + validate the Lua data (do this before"
	@echo "                    claiming a change works)"
	@echo "  make check-lua    validate the Lua data only"
	@echo "  make reconfigure  re-run meson setup, after editing meson.build"
	@echo "  make shell        interactive shell in the dev container"
	@echo "  make clean        remove $(BUILDDIR)"
	@echo "  make clean-image  remove the Podman dev image"

image:
	podman build -t $(IMAGE) .

# Configures builddir on first use, then compiles. Re-running is cheap.
build:
	$(PODMAN_RUN) 'cd /src && { [ -f $(BUILDDIR)/build.ninja ] || \
		meson setup $(BUILDDIR); } && meson compile -C $(BUILDDIR)'

# meson refuses a plain re-setup on a configured dir; this is the escape hatch.
reconfigure:
	$(PODMAN_RUN) 'cd /src && meson setup $(BUILDDIR) --reconfigure && \
		meson compile -C $(BUILDDIR)'

# Runs on the HOST, from the repo root: data/ is resolved relative to CWD.
run: build
	./$(BIN)

check: build check-lua

# The GUI cannot run headless here, so parsing the Lua is the other half of
# "it works". Mods are validated LAYERED (base file first), because they
# table.insert into globals the base defines — running one alone always fails.
check-lua:
	@command -v lua >/dev/null 2>&1 || \
		{ echo "check-lua: no 'lua' on the host, skipping"; exit 0; }
	@set -e; \
	for f in data/*.lua; do \
		lua -e "dofile('$$f')"; \
		echo "  OK   $$f"; \
	done; \
	for f in data/mods/*/*.lua; do \
		[ -e "$$f" ] || continue; \
		base="data/$$(basename "$$f")"; \
		if [ -f "$$base" ]; then \
			lua -e "dofile('$$base'); dofile('$$f')"; \
			echo "  OK   $$f (layered on $$base)"; \
		else \
			lua -e "dofile('$$f')"; \
			echo "  OK   $$f"; \
		fi; \
	done

shell:
	podman run --rm -it -v "$(CURDIR)":/src:Z --userns=keep-id \
		localhost/$(IMAGE):latest bash

clean:
	rm -rf $(BUILDDIR)

clean-image:
	-podman rmi localhost/$(IMAGE):latest