Mirai's Miscellaneous Misadventures

M35 / makefile

1# copyright 2022 zamfofex
2# license: AGPLv3 or later
3
4engine ?= mfb
5
6libs =
7
8ifeq ($(engine),sdl2)
9libs += -lSDL2
10endif
11
12ifeq ($(engine),mfb)
13libs += -lminifb -lX11 -lGL
14endif
15
16src = \
17	core/behaviors.c \
18	core/sprites.c \
19	core/controls.c \
20	core/cameras.c \
21	core/animations.c \
22	core/displays.c \
23	core/font.c \
24	core/text.c \
25	core/coroutines.c \
26	core/collisions.c \
27	core/allocators.c \
28	core/video.c \
29	core/version.c \
30	core/paths.c \
31	models/all.c \
32	test/chapter.c
33
34exe = mimimi
35lib = lib$(exe)
36
37ifneq ($(engine),lib)
38src += engines/$(engine).c
39endif
40
41.PHONY: all clean check
42
43all:
44
45clean:
46	$(RM) $(exe) *.wasm *.a */*.o */*.wasm */*.d
47
48check:
49	$(MAKE) engine=check
50	valgrind --leak-check=full --error-exitcode=1 ./mimimi
51
52ifeq ($(engine),wasm)
53
54all: $(exe).wasm $(lib).a
55
56$(exe).wasm: $(src:.c=.wasm)
57	@echo ld $@
58	@$(CC) $(LDFLAGS) -nostdlib -Wl,--no-entry \
59		-Wl,--export=mimimi_wasm_texture \
60		-Wl,--export=mimimi_wasm_invalidate \
61		-Wl,--export=mimimi_wasm_stamp \
62		-Wl,--export=mimimi_wasm_allocator \
63		-Wl,--export=mimimi_wasm_allocate \
64		-Wl,--export=mimimi_test \
65		-Wl,--allow-undefined \
66		-Wl,--export-table,--growable-table \
67		-o $@ $^ $(libs)
68
69$(lib).a: $(src:.c=.wasm)
70	@echo ar $@
71	@$(AR) rDsc $@ $^
72
73%.wasm: %.c
74	@echo cc $<
75	@$(CC) $(CFLAGS) $(CPPFLAGS) -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
76
77else
78
79all: $(exe) $(lib).a
80
81src += core/malloc.c
82
83$(exe): $(src:.c=.o) main/$(engine).o
84	@echo ld $@
85	@$(CC) $(LDFLAGS) -o $@ $^ $(libs)
86
87$(lib).a: $(src:.c=.o)
88	@echo ar $@
89	@$(AR) rDsc $@ $^
90
91%.o: %.c
92	@echo cc $<
93	@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
94
95endif
96
97-include $(src:.c=.d)