Mirai's Miscellaneous Misadventures

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