Mirai's Miscellaneous Misadventures

M17 / makefile

1# copyright 2022 zamfofex
2# license: AGPLv3 or later
3
4.PHONY: build clean
5
6engine ?= sdl2
7
8libs =
9
10ifeq ($(engine),sdl2)
11libs += -lSDL2
12endif
13
14ifeq ($(engine),mfb)
15libs += -lminifb -lX11 -lGL
16endif
17
18src = core/game.c core/appearances.c core/behaviors.c core/fonts.c core/font.c models/all.c test/chapter.c engines/$(engine).c
19
20exe = mimimi
21
22CPPFLAGS := $(CPPFLAGS)
23CPPFLAGS += -MMD -MP -Iinclude
24
25ifeq ($(engine),wasm)
26build: $(exe).wasm
27else
28build: $(exe)
29src += main/$(engine).c
30endif
31
32clean:
33	$(RM) $(exe) *.o */*.o *.wasm */*.wasm *.d */*.d
34
35ifneq ($(engine),wasm)
36
37$(exe): $(src:.c=.o)
38	$(CC) $(LDFLAGS) -o $@ $^ $(libs)
39
40else
41
42$(exe).wasm: $(src:.c=.wasm)
43	$(CC) $(LDFLAGS) --target=wasm32 -nostdlib -Wl,--no-entry \
44		-Wl,--export=mimimi_game_size \
45		-Wl,--export=mimimi_width \
46		-Wl,--export=mimimi_height \
47		-Wl,--export=mimimi_start \
48		-Wl,--export=mimimi_step \
49		-Wl,--export=mimimi_wasm_stamp \
50		-Wl,--export=mimimi_wasm_allocate \
51		-Wl,--export=mimimi_test \
52		-Wl,--export=__heap_base \
53		-Wl,--allow-undefined \
54		-Wl,--export-table,--growable-table \
55		-o $@ $^ $(libs)
56
57%.wasm: %.c
58	$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -c -o $@ $<
59
60endif
61
62-include $(src:.c=.d)