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