Mirai's Miscellaneous Misadventures
M30 / 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
14CFLAGS += -Wno-discarded-qualifiers
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/fonts.c 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 models/all.c \
32 test/chapter.c
33
34exe = mimimi
35lib = lib$(exe)
36
37ifneq ($(engine),lib)
38src += engines/$(engine).c
39endif
40
41ifeq ($(engine),x86)
42
43$(exe).$(engine).img: $(src:.c=.$(engine).o) $(engine)/boot.$(engine).o $(engine)/main.$(engine).o $(engine)/vbe.$(engine).o
44 @echo ld $@
45 @$(CC) -m16 $(LDFLAGS) -nostdlib -static -T$(engine)/link.ld -o $@ $^ $(libs)
46
47%.$(engine).o: %.c x86/link.ld
48 @echo cc $<
49 @$(CC) -m16 $(CFLAGS) $(CPPFLAGS) -MMD -MF$(<:.c=.d) -MP -Iinclude -ffreestanding -c -o $@ $<
50
51%.$(engine).o: %.s x86/link.ld
52 @echo cc $<
53 @$(CC) -m16 $(ASFLAGS) -c -o $@ $<
54
55else ifeq ($(engine),wasm)
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) -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
77
78else ifeq ($(engine),psx)
79
80src += psx/malloc.c
81
82libs += -lpsxgpu -lpsxgte -lpsxspu -lpsxcd -lpsxpress -lpsxsio -lpsxetc -lpsxapi -llzp -lc
83
84$(exe).exe: $(src:.c=.o) main/$(engine).o
85 @echo ld $@
86 @$(CC) $(LDFLAGS) -nostdlib -static -o $(exe) $^ $(libs)
87 @elf2x -q $(exe) $@
88
89%.o: %.c
90 @echo cc $<
91 @$(CC) $(CFLAGS) $(CPPFLAGS) -march=r3000 -msoft-float -mabi=32 -mdivide-breaks -ffreestanding -mno-abicalls -MMD -MP -Iinclude -c -o $@ $<
92
93else
94
95src += core/malloc.c
96
97$(exe): $(src:.c=.o) main/$(engine).o
98 @echo ld $@
99 @$(CC) $(LDFLAGS) -o $@ $^ $(libs)
100
101$(lib).a: $(src:.c=.o)
102 @echo ar $@
103 @$(AR) rDsc $@ $^
104
105%.o: %.c
106 @echo cc $<
107 @$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
108
109endif
110
111.PHONY: clean check
112
113clean:
114 $(RM) $(exe) *.exe *.wasm *.img *.a */*.o */*.wasm */*.d
115
116check:
117 $(MAKE) engine=check
118 valgrind --leak-check=full --error-exitcode=1 ./mimimi
119
120-include $(src:.c=.d)