Mirai's Miscellaneous Misadventures

M8 / makefile

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