Mirai's Miscellaneous Misadventures

M15 / makefile

1.PHONY: build clean
2
3engine ?= sdl2
4
5libs =
6
7ifeq ($(engine),sdl2)
8libs += -lSDL2
9endif
10
11ifeq ($(engine),mfb)
12libs += -lminifb -lX11 -lGL
13endif
14
15src = game.c
16src += engines/$(engine).c
17
18exe = mimimi
19
20CPPFLAGS += -MMD -MP
21
22ifeq ($(engine),wasm)
23build: $(exe).wasm
24else
25build: $(exe)
26endif
27
28clean:
29	$(RM) $(exe) *.o *.wasm *.d engines/*.o engines/*.wasm engines/*.d
30
31ifneq ($(engine),wasm)
32
33$(exe): $(src:.c=.o)
34	$(CC) $(LDFLAGS) -o $@ $^ $(libs)
35
36else
37
38$(exe).wasm: $(src:.c=.wasm)
39	$(CC) $(LDFLAGS) --target=wasm32 -nostdlib -Wl,--no-entry \
40		-Wl,--export=mirai_game_size \
41		-Wl,--export=mirai_width \
42		-Wl,--export=mirai_height \
43		-Wl,--export=mirai_start \
44		-Wl,--export=mirai_step \
45		-Wl,--export=mirai_assets \
46		-Wl,--export=mirai_wasm_stamp \
47		-Wl,--export=__heap_base \
48		-Wl,--allow-undefined \
49		-Wl,--export-table,--growable-table \
50		-o $@ $^ $(libs)
51
52%.wasm: %.c
53	$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -c -o $@ $<
54
55endif
56
57-include $(src:.c=.d)