Mirai's Miscellaneous Misadventures

M36 / 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	core/effects.c \
32	models/all.c \
33	test/chapter.c
34
35exe = mimimi
36lib = lib$(exe)
37
38ifneq ($(engine),lib)
39src += engines/$(engine).c
40endif
41
42.PHONY: all clean check
43
44all:
45
46clean:
47	$(RM) $(exe) *.wasm *.a */*.o */*.wasm */*.d
48
49check:
50	$(MAKE) engine=check
51	valgrind --leak-check=full --error-exitcode=1 ./mimimi
52
53ifeq ($(engine),wasm)
54
55all: $(exe).wasm $(lib).a
56
57$(exe).wasm: $(src:.c=.wasm)
58	@echo ld $@
59	@$(CC) $(LDFLAGS) -nostdlib -Wl,--no-entry \
60		-Wl,--export=mimimi_wasm_texture \
61		-Wl,--export=mimimi_wasm_invalidate \
62		-Wl,--export=mimimi_wasm_stamp \
63		-Wl,--export=mimimi_wasm_allocator \
64		-Wl,--export=mimimi_wasm_allocate \
65		-Wl,--export=mimimi_test \
66		-Wl,--allow-undefined \
67		-Wl,--export-table,--growable-table \
68		-o $@ $^ $(libs)
69
70$(lib).a: $(src:.c=.wasm)
71	@echo ar $@
72	@$(AR) rDsc $@ $^
73
74%.wasm: %.c
75	@echo cc $<
76	@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -ffreestanding -Iinclude -c -o $@ $<
77
78else
79
80all: $(exe) $(lib).a
81
82src += core/malloc.c
83
84$(exe): $(src:.c=.o) main/$(engine).o
85	@echo ld $@
86	@$(CC) $(LDFLAGS) -o $@ $^ $(libs)
87
88$(lib).a: $(src:.c=.o)
89	@echo ar $@
90	@$(AR) rDsc $@ $^
91
92%.o: %.c
93	@echo cc $<
94	@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
95
96endif
97
98-include $(src:.c=.d)