Mirai's Miscellaneous Misadventures

M25 / 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	core/coroutines.c \
28	models/all.c \
29	test/chapter.c \
30	engines/$(engine).c
31
32exe = mimimi
33lib = libmimimi
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$(lib).a: $(src:.c=.wasm)
63	@echo $(AR) ur $@
64	@$(AR) rDsc $@ $^
65
66%.wasm: %.c
67	@echo $(CC) -c $<
68	@$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
69
70else
71
72src += core/malloc.c
73
74$(exe): $(src:.c=.o) main/$(engine).o
75	@echo $(CC) -o $@
76	@$(CC) $(LDFLAGS) -o $@ $^ $(libs)
77
78%.o: %.c
79	@echo $(CC) -c $<
80	@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
81
82endif
83
84.PHONY: clean
85clean:
86	$(RM) $(exe) $(exe).wasm $(exe).*.img $(lib).a */*.o */*.wasm */*.d
87
88-include $(src:.c=.d)