Mirai's Miscellaneous Misadventures
M41 / makefile
1# copyright 2023 zamfofex
2# license: AGPLv3 or later
3
4engine = mfb
5
6LD = $(CC)
7WASM_OPT ?= wasm-opt
8
9libs =
10
11ifeq ($(engine),mfb)
12libs += -lminifb -lX11 -lGL
13endif
14
15exe = mimimi
16lib = lib$(exe)
17
18src = \
19 core/behaviors.c \
20 core/sprites.c \
21 core/controls.c \
22 core/cameras.c \
23 core/animations.c \
24 core/displays.c \
25 core/font.c \
26 core/text.c \
27 core/coroutines.c \
28 core/collisions.c \
29 core/allocators.c \
30 core/video.c \
31 core/version.c \
32 core/paths.c \
33 core/effects.c \
34 models/all.c \
35 engines/$(engine).c \
36 test/chapter.c
37
38ifeq ($(enable_ualyze),)
39src += core/text-basic.c
40else
41src += core/text-ualyze.c
42libs += -lualyze
43endif
44
45.PHONY: all clean check
46
47all:
48
49clean:
50 $(RM) $(exe) *.wasm *.a *.txt */*.o */*.wasm */*.d
51
52check:
53 $(MAKE) engine=check
54 valgrind --leak-check=full --error-exitcode=1 ./mimimi
55
56# note: the Wasm target uses 'wcc' from <https://github.com/tyfkda/xcc>
57
58ifeq ($(engine),wasm)
59
60src += core/malloc.c
61
62all: $(exe).wasm $(lib).txt
63
64$(exe).wasm: $(src) main/wasm.c
65 @echo cc $@
66 @$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -MMD -Iinclude \
67 --entry-point=main -e mimimi_wasm_behave \
68 -o $@ $^
69 @echo wo $@
70 @$(WASM_OPT) $(WASM_OPT_FLAGS) -o $@ $@
71
72$(lib).txt:
73 echo $(src) > $@
74
75else ifeq ($(engine),wasm-llvm)
76
77all: $(exe)-llvm.wasm $(lib).a
78
79$(exe)-llvm.wasm: $(src:.c=.wasm)
80 @echo ld $@
81 @$(LD) $(LDFLAGS) -nostdlib -Wl,--no-entry \
82 -Wl,--export=mimimi_wasm_llvm_texture \
83 -Wl,--export=mimimi_wasm_llvm_invalidate \
84 -Wl,--export=mimimi_wasm_llvm_stamp \
85 -Wl,--export=mimimi_wasm_llvm_allocator \
86 -Wl,--export=mimimi_wasm_llvm_allocate \
87 -Wl,--export=mimimi_test \
88 -Wl,--allow-undefined \
89 -Wl,--export-table,--growable-table \
90 -o $@ $^ $(libs)
91
92$(lib).a: $(src:.c=.wasm)
93 @echo ar $@
94 @$(AR) rDsc $@ $^
95
96%.wasm: %.c
97 @echo cc $<
98 @$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -ffreestanding -Iinclude -c -o $@ $<
99
100else
101
102src += core/malloc.c
103
104all: $(exe) $(lib).a
105
106$(exe): $(src:.c=.o) main/$(engine).o
107 @echo ld $@
108 @$(LD) $(LDFLAGS) -o $@ $^ $(libs)
109
110$(lib).a: $(src:.c=.o)
111 @echo ar $@
112 @$(AR) rDsc $@ $^
113
114%.o: %.c
115 @echo cc $<
116 @$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
117
118endif
119
120-include $(src:.c=.d)