Mirai's Miscellaneous Misadventures

M18 / 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/appearances.c \
	core/displays.c \
	core/fonts.c core/font.c \
	core/text.c \
	models/all.c \
	test/chapter.c \
	engines/$(engine).c

exe = mimimi

ifneq ($(engine),wasm)

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 $@ $<

else

$(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 $@ $<

endif

clean:
	$(RM) $(exe) $(exe).wasm */*.o */*.wasm */*.d

-include $(src:.c=.d)