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