Mirai's Miscellaneous Misadventures
M21 / makefile
# copyright 2022 zamfofex
# license: AGPLv3 or later
.PHONY: build clean
engine = mfb
libs =
ifeq ($(engine),sdl2)
libs += -lSDL2
endif
ifeq ($(engine),mfb)
libs += -lminifb -lX11 -lGL
CFLAGS += -Wno-discarded-qualifiers
endif
src = \
core/behaviors.c \
core/sprites.c \
core/controls.c \
core/cameras.c \
core/animations.c \
core/displays.c \
core/fonts.c core/font.c \
core/text.c \
core/noise.c \
models/all.c \
test/chapter.c \
engines/$(engine).c
exe = mimimi
ifeq ($(engine),x86)
$(exe).$(engine).img: $(src:.c=.$(engine).o) $(engine)/boot.$(engine).o $(engine)/main.$(engine).o $(engine)/vbe.$(engine).o
@echo $(CC) -o $@
@$(CC) -m16 $(LDFLAGS) -nostdlib -T$(engine)/link.ld -o $@ $^ $(libs)
%.$(engine).o: %.c
@echo $(CC) -c $<
@$(CC) -m16 $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -ffreestanding -c -o $@ $<
%.$(engine).o: %.s
@echo $(CC) -c $<
@$(CC) -m16 $(ASFLAGS) -c -o $@ $<
else ifeq ($(engine),wasm)
$(exe).wasm: $(src:.c=.wasm)
@echo $(CC) -o $@
@$(CC) $(LDFLAGS) --target=wasm32 -nostdlib -Wl,--no-entry \
-Wl,--export=mimimi_wasm_stamp \
-Wl,--export=mimimi_wasm_allocator \
-Wl,--export=mimimi_wasm_allocate \
-Wl,--export=mimimi_test \
-Wl,--allow-undefined \
-Wl,--export-table,--growable-table \
-o $@ $^ $(libs)
%.wasm: %.c
@echo $(CC) -c $<
@$(CC) $(CFLAGS) $(CPPFLAGS) --target=wasm32 -ffreestanding -MMD -MP -Iinclude -c -o $@ $<
else
src += core/malloc.c
$(exe): $(src:.c=.o) main/$(engine).o
@echo $(CC) -o $@
@$(CC) $(LDFLAGS) -o $@ $^ $(libs)
%.o: %.c
@echo $(CC) -c $<
@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -Iinclude -c -o $@ $<
endif
clean:
$(RM) $(exe) $(exe).wasm $(exe).*.img */*.o */*.wasm */*.d
-include $(src:.c=.d)