diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-09-13 22:00:18 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-09-13 22:22:17 +0200 |
| commit | 674abec04cc06de1b451d4efbbb52ca8b202beee (patch) | |
| tree | 721e15d63f03a954d97fa58a95e62bf7bec6749a /Makefile | |
| parent | cfa3a680b679b3fbcd5967e0175207aef71f80c9 (diff) | |
Refactor Makefile... Again
We now have a monolithic Makefile which is, IMO, easier to grok.
Additionally, all building happens in the `target/` directory to
keep things cleaner.
The makefile also considers cross-compilation by distinguishing
between the target C compiler and a host C compiler (used for tools
needed for code generation).
Lastly, dependencies are compiled into static libraries, to keep
the process more organized (we used to just link a bunch of object
files as a final step, now we pack the dependencies into archives
and link them as a final step; so no effective difference).
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 121 |
1 files changed, 99 insertions, 22 deletions
@@ -1,30 +1,107 @@ -CC = gcc -CFLAGS = -std=c99 -Wextra -O2 -Ilib/ $(shell pkg-config SDL3 --cflags) -LDFLAGS = $(shell pkg-config SDL3 --libs) +-include config.mk -SRC = src/picow.c src/sysroot.c -OBJ = $(patsubst %.c,%.o,$(SRC)) +CC ?= cc +AR ?= ar +HOSTCC ?= cc +PICO8 ?= pico8 + +ARCH ?= $(shell uname -m) +CFLAGS += -std=c99 -Wextra -O2 +SDL3_CFLAGS ?= $(shell pkg-config SDL3 --cflags) +SDL3_LIBS ?= $(shell pkg-config SDL3 --libs) + +TARGET := target/$(ARCH) +BUILD := $(TARGET)/build +TOOLS := target/tools +SYSTEM := target/system + +PICOW_CFLAGS := $(CFLAGS) $(SDL3_CFLAGS) -Ilib/ +PICOW_LDFLAGS := $(LDFLAGS) $(SDL3_LIBS) -L$(TARGET) -lstb -lwamr +PICOW_SRC := $(sort $(wildcard src/*.c) src/sysroot.c) +PICOW_OBJ := $(patsubst %.c,$(BUILD)/%.o,$(PICOW_SRC)) + +STB_CFLAGS := $(CFLAGS) $(SDL3_CFLAGS) -Wno-unused-function +STB_SRC := $(wildcard lib/stb/*.c) +STB_OBJ := $(patsubst %.c,$(BUILD)/%.o,$(STB_SRC)) + +WAMR_CFLAGS := $(CFLAGS) -Wno-unused-parameter \ + -DBH_FREE=wasm_runtime_free \ + -DBH_MALLOC=wasm_runtime_malloc \ + -DWASM_ENABLE_FAST_INTERP=1 \ + -DWASM_ENABLE_INTERP=1 \ + -Ilib/wamr/core/iwasm/common \ + -Ilib/wamr/core/iwasm/include \ + -Ilib/wamr/core/iwasm/interpreter \ + -Ilib/wamr/core/shared/mem-alloc \ + -Ilib/wamr/core/shared/platform/include \ + -Ilib/wamr/core/shared/utils \ + -Ilib/wamr/custom +WAMR_SRC := $(shell find lib/wamr -name '*.c') +WAMR_OBJ := $(patsubst %.c,$(BUILD)/%.o,$(WAMR_SRC)) + +CARTS := $(patsubst %,%.png,$(wildcard carts/*.p8)) .PHONY: all -all: picow carts ; +all: $(TARGET)/picow $(CARTS) ; -include makefiles/carts.mk -include makefiles/stbi.mk -include makefiles/system.mk -include makefiles/tools.mk -include makefiles/wamr.mk +$(TARGET)/picow: $(PICOW_OBJ) $(TARGET)/libstb.a $(TARGET)/libwamr.a + @ echo "CC\t$@" + @ $(CC) $(PICOW_OBJ) -o $@ $(PICOW_LDFLAGS) -picow: $(OBJ) $(STBI_OBJ) $(WAMR_OBJ) - $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) +$(BUILD)/src/%.o: src/%.c + @ echo "CC\t$@" + @ mkdir -p $(dir $@) + @ $(CC) $(PICOW_CFLAGS) -c $< -o $@ -.PHONY: lint -lint: - clang-format -i src/*.[ch] - clang-tidy --quiet src/*.[ch] -- -Ilib/ +$(TARGET)/libstb.a: $(STB_OBJ) + @ echo "AR\t$@" + @ $(AR) rcs $@ $^ -.PHONY: clean -clean: clean-carts clean-stbi clean-system clean-tools clean-wamr - rm -f picow $(OBJ) +$(BUILD)/lib/stb/%.o: lib/stb/%.c + @ echo "CC\t$@" + @ mkdir -p $(dir $@) + @ $(CC) $(STB_CFLAGS) -c $< -o $@ + +$(TARGET)/libwamr.a: $(WAMR_OBJ) + @ echo "AR\t$@" + @ $(AR) rcs $@ $^ -src/%.o: src/%.c - $(CC) $(CFLAGS) -c $< -o $@ +$(BUILD)/lib/wamr/%.o: lib/wamr/%.c + @ echo "CC\t$@" + @ mkdir -p $(dir $@) + @ $(CC) $(WAMR_CFLAGS) -c $< -o $@ + +src/sysroot.c: $(TOOLS)/generate-sysroot \ + $(SYSTEM)/pico8.data.pod \ + $(SYSTEM)/pico8.wasm \ + $(SYSTEM)/unknown.p8.png + @ echo "TOOL\t$@" + @ $< $(SYSTEM) >$@ + +$(SYSTEM)/pico8.data.pod: $(TOOLS)/extract-data-pod $(SYSTEM)/pico8.js + @ echo "TOOL\t$@" + @ $< $(SYSTEM)/pico8.js $@ + +$(SYSTEM)/%.html $(SYSTEM)/%.js $(SYSTEM)/%.wasm: $(SYSTEM)/%.w ; +$(SYSTEM)/%.w: carts/%.p8 + @ echo "PICO8\t$(@:.w=.html)" + @ mkdir -p $(dir $@) + @ $(PICO8) $< -export "-w $(@:.w=.html)" >/dev/null + +$(SYSTEM)/%.p8.png: carts/%.p8.png + @ echo "CP\t$@" + @ mkdir -p $(dir $@) + @ cp $< $@ + +$(TOOLS)/%: tools/%.c + @ echo "CC\t$@" + @ mkdir -p $(dir $@) + @ $(HOSTCC) $(CFLAGS) $< -o $@ + +carts/%.p8.png: carts/%.p8 + @ echo "PICO8\t$@" + @ $(PICO8) $< -export $@ >/dev/null + +.PHONY: clean +clean: + rm -rf $(CARTS) src/sysroot.c target/ |
