Mirai's Miscellaneous Misadventures
M19 / makefile
1# copyright 2022 zamfofex
2# license: AGPLv3 or later
3
4.PHONY: build clean
5
6engine = mfb
7
8libs =
9
10ifeq ($(engine),sdl2)
11libs += -lSDL2
12endif
13
14ifeq ($(engine),mfb)
15libs += -lminifb -lX11 -lGL
16CFLAGS += -Wno-discarded-qualifiers
17endif
18
19src = \
20 core/behaviors.c \
21 core/sprites.c \
22 core/controls.c \
23 core/cameras.c \
24 core/appearances.c \
25 core/displays.c \
26 core/fonts.c core/font.c \
27 core/text.c \
28 models/all.c \
29 test/chapter.c \
30 engines/$(engine).c
31
32exe = mimimi
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%.wasm: %.c
62 @echo $(CC) -c $<
63 @$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
64
65else
66
67src += core/malloc.c
68
69$(exe): $(src:.c=.o) main/$(engine).o
70 @echo $(CC) -o $@
71 @$(CC) $(LDFLAGS) -o $@ $^ $(libs)
72
73%.o: %.c
74 @echo $(CC) -c $<
75 @$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
76
77endif
78
79clean:
80 $(RM) $(exe) $(exe).wasm $(exe).*.img */*.o */*.wasm */*.d
81
82-include $(src:.c=.d)