Mirai's Miscellaneous Misadventures

M38 / makefile

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