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 | |
| 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).
| -rw-r--r-- | .gitignore | 9 | ||||
| -rw-r--r-- | Makefile | 121 | ||||
| -rw-r--r-- | makefiles/carts.mk | 15 | ||||
| -rw-r--r-- | makefiles/stbi.mk | 12 | ||||
| -rw-r--r-- | makefiles/system.mk | 21 | ||||
| -rw-r--r-- | makefiles/tools.mk | 6 | ||||
| -rw-r--r-- | makefiles/wamr.mk | 54 |
7 files changed, 100 insertions, 138 deletions
@@ -1,11 +1,4 @@ -carts/*.html -carts/*.js carts/*.p8.png -carts/*.p8.rom -carts/*.wasm -picow +config.mk src/sysroot.c -system/ target/ -tools/*.exe -**/*.o @@ -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/ diff --git a/makefiles/carts.mk b/makefiles/carts.mk deleted file mode 100644 index 5dba32c..0000000 --- a/makefiles/carts.mk +++ /dev/null @@ -1,15 +0,0 @@ -PICO8 ?= pico8 - -.PHONY: carts -carts: carts/pico8.p8.png ; - -carts/%.p8.png: carts/%.p8 - $(PICO8) $< -export $@ - -carts/%.html carts/%.js carts/%.wasm: carts/%.w ; -carts/%.w: carts/%.p8 - $(PICO8) $< -export "-w $(@:.w=.html)" - -.PHONY: clean-carts -clean-carts: - rm -f carts/*.html carts/*.js carts/*.wasm carts/*.p8.png diff --git a/makefiles/stbi.mk b/makefiles/stbi.mk deleted file mode 100644 index 0f03c15..0000000 --- a/makefiles/stbi.mk +++ /dev/null @@ -1,12 +0,0 @@ -STBI_SRC = lib/stb/stbi.c -STBI_OBJ = $(patsubst %.c,%.o,$(STBI_SRC)) - -.PHONY: stbi -stbi: $(STBI_OBJ) ; - -lib/stb/%.o: lib/stb/%.c - $(CC) $(CFLAGS) -Wno-unused-function -c $< -o $@ - -.PHONY: clean-stbi -clean-stbi: - rm -f $(STBI_OBJ) diff --git a/makefiles/system.mk b/makefiles/system.mk deleted file mode 100644 index 73fb9ae..0000000 --- a/makefiles/system.mk +++ /dev/null @@ -1,21 +0,0 @@ -PICO8 ?= pico8 - -src/sysroot.c: tools/generate-sysroot.exe system/pico8.data.pod system/pico8.wasm system/unknown.p8.png - $< system > $@ - -system/pico8.data.pod: carts/pico8.js tools/extract-data-pod.exe - @mkdir -p system - tools/extract-data-pod.exe $< $@ - -system/pico8.wasm: carts/pico8.wasm - @mkdir -p system - cp $< $@ - -system/unknown.p8.png: carts/unknown.p8.png - @mkdir -p system - cp $< $@ - -.PHONY: clean-system -clean-system: - rm -f src/sysroot.c - rm -rf system/ diff --git a/makefiles/tools.mk b/makefiles/tools.mk deleted file mode 100644 index ab25382..0000000 --- a/makefiles/tools.mk +++ /dev/null @@ -1,6 +0,0 @@ -tools/%.exe: tools/%.c - $(CC) $(CFLAGS) $< -o $@ - -.PHONY: clean-tools -clean-tools: - rm -f tools/*.exe diff --git a/makefiles/wamr.mk b/makefiles/wamr.mk deleted file mode 100644 index e250509..0000000 --- a/makefiles/wamr.mk +++ /dev/null @@ -1,54 +0,0 @@ -WAMR_SRC = lib/wamr/core/iwasm/common/wasm_application.c \ - lib/wamr/core/iwasm/common/wasm_blocking_op.c \ - lib/wamr/core/iwasm/common/wasm_c_api.c \ - lib/wamr/core/iwasm/common/wasm_exec_env.c \ - lib/wamr/core/iwasm/common/wasm_loader_common.c \ - lib/wamr/core/iwasm/common/wasm_memory.c \ - lib/wamr/core/iwasm/common/wasm_native.c \ - lib/wamr/core/iwasm/common/wasm_runtime_common.c \ - lib/wamr/core/iwasm/common/wasm_shared_memory.c \ - lib/wamr/core/iwasm/interpreter/wasm_interp_fast.c \ - lib/wamr/core/iwasm/interpreter/wasm_loader.c \ - lib/wamr/core/iwasm/interpreter/wasm_runtime.c \ - lib/wamr/core/shared/mem-alloc/ems/ems_alloc.c \ - lib/wamr/core/shared/mem-alloc/ems/ems_gc.c \ - lib/wamr/core/shared/mem-alloc/ems/ems_hmu.c \ - lib/wamr/core/shared/mem-alloc/ems/ems_kfc.c \ - lib/wamr/core/shared/mem-alloc/mem_alloc.c \ - lib/wamr/core/shared/utils/bh_assert.c \ - lib/wamr/core/shared/utils/bh_bitmap.c \ - lib/wamr/core/shared/utils/bh_common.c \ - lib/wamr/core/shared/utils/bh_hashmap.c \ - lib/wamr/core/shared/utils/bh_leb128.c \ - lib/wamr/core/shared/utils/bh_list.c \ - lib/wamr/core/shared/utils/bh_log.c \ - lib/wamr/core/shared/utils/bh_queue.c \ - lib/wamr/core/shared/utils/bh_vector.c \ - lib/wamr/core/shared/utils/runtime_timer.c \ - lib/wamr/custom/platform.c \ - lib/wamr/custom/runtime.c - -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_OBJ = $(patsubst %.c,%.o,$(WAMR_SRC)) - -.PHONY: wamr -wamr: $(WAMR_OBJ) ; - -lib/wamr/%.o: lib/wamr/%.c - $(CC) -c -o $@ $< $(WAMR_CFLAGS) -DBH_DEBUG - -.PHONY: clean-wamr -clean-wamr: - rm -f $(WAMR_OBJ) |
