Mirai's Miscellaneous Misadventures
M26 / 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 models/all.c \
29 test/chapter.c
30
31exe = mimimi
32lib = lib$(exe)
33
34ifneq ($(engine),lib)
35src += engines/$(engine).c
36endif
37
38ifeq ($(engine),x86)
39
40$(exe).$(engine).img: $(src:.c=.$(engine).o) $(engine)/boot.$(engine).o $(engine)/main.$(engine).o $(engine)/vbe.$(engine).o
41 @echo ld $@
42 @$(CC) -m16 $(LDFLAGS) -nostdlib -static -T$(engine)/link.ld -o $@ $^ $(libs)
43
44%.$(engine).o: %.c x86/link.ld
45 @echo cc $<
46 @$(CC) -m16 $(CFLAGS) $(CPPFLAGS) -MMD -MF$(<:.c=.d) -MP -Iinclude -ffreestanding -c -o $@ $<
47
48%.$(engine).o: %.s x86/link.ld
49 @echo cc $<
50 @$(CC) -m16 $(ASFLAGS) -c -o $@ $<
51
52else ifeq ($(engine),wasm)
53
54$(exe).wasm: $(src:.c=.wasm)
55 @echo ld $@
56 @$(CC) $(LDFLAGS) --target=wasm32 -nostdlib -Wl,--no-entry \
57 -Wl,--export=mimimi_wasm_stamp \
58 -Wl,--export=mimimi_wasm_allocator \
59 -Wl,--export=mimimi_wasm_allocate \
60 -Wl,--export=mimimi_test \
61 -Wl,--allow-undefined \
62 -Wl,--export-table,--growable-table \
63 -o $@ $^ $(libs)
64
65$(lib).wasm.a: $(src:.c=.wasm)
66 @echo ar $@
67 @$(AR) rDsc $@ $^
68
69%.wasm: %.c
70 @echo cc $<
71 @$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
72
73else
74
75src += core/malloc.c
76
77$(exe): $(src:.c=.o) main/$(engine).o
78 @echo ld $@
79 @$(CC) $(LDFLAGS) -o $@ $^ $(libs)
80
81$(lib).a: $(src:.c=.o)
82 @echo ar $@
83 @$(AR) rDsc $@ $^
84
85%.o: %.c
86 @echo cc $<
87 @$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
88
89endif
90
91.PHONY: clean
92clean:
93 $(RM) $(exe) *.wasm *.img *.a */*.o */*.wasm */*.d
94
95-include $(src:.c=.d)