From 93a202d1fa6cd05b494bbf7175d79c6da075f333 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Thu, 29 Oct 2026 16:09:56 +0100 Subject: Prebuild System Files In order to make it easier to build `picow` on systems _without_ PICO-8 support (which what this project targets...), we added a system for producing a `system.tar.gz` tarball that contains the generated system source required for building PICO-w (namely, the `pico8.wasm` transpiled to C, and the `sysroot` with the embedded data files needed by the application). I also moved away from `a b c: ...` style recipes, as they run multiple times in parallelized builds. I made it compatible with older `make`s, and it will hopefully generally work. --- Makefile | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 6ed6297..fa4909a 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,12 @@ AR ?= ar HOSTCC ?= cc PICO8 ?= pico8 WASM2C ?= wasm2c +TAR ?= tar ARCH ?= $(shell uname -m) CFLAGS ?= -std=c99 -Wall -Wextra -O2 -MMD -Isrc -Ilib -I$(SYSTEM) \ - $(shell pkg-config sdl3 --cflags) -HOSTCFLAGS ?= -std=c99 -Wall -Wextra -O2 -MMD + $(shell pkg-config sdl3 --cflags) +HOSTCFLAGS ?= -std=c99 -Wall -Wextra -O2 LDFLAGS ?= $(shell pkg-config sdl3 --libs) -lm W2CFLAGS ?= --disable-tail-call @@ -20,6 +21,7 @@ SYSTEM := build/system SRC := $(wildcard src/*.c) $(SYSTEM)/pico8.c $(SYSTEM)/sysroot.c OBJ := $(patsubst %.c,$(OUT)/%.o,$(SRC:build/%=%)) +SYS := $(addprefix $(SYSTEM)/,pico8.c pico8.h sysroot.c sysroot.h wasm-rt.h) .PHONY: all all: $(TARGET)/picow ; @@ -37,17 +39,37 @@ $(OUT)/system/%.o: $(SYSTEM)/%.c @ mkdir -p $(dir $@) @ $(CC) $(CFLAGS) -Wno-unused -Wno-unused-parameter -c $< -o $@ -$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c: $(SYSTEM)/pico8.wasm +ifdef SYSTEMTAR + +$(SYS): $(SYSTEM)/.systemtar ; +$(SYSTEM)/.systemtar: $(SYSTEMTAR) + @ echo "TAR\t$(SYS)" + @ mkdir -p $(dir $@) + @ $(TAR) -xzf $< -C $(dir $@) + @ touch -c $(SYS) + @ touch $@ + +else + +$(SYSTEM)/system.tar.gz: $(SYS) + @ echo "TAR\t$@" + @ $(TAR) -czf $@ -C $(SYSTEM) $(^:$(SYSTEM)/%=%) + +$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c $(SYSTEM)/wasm-rt.h: $(SYSTEM)/.pico8 ; +$(SYSTEM)/.pico8: $(SYSTEM)/pico8.wasm @ echo "WASM2C\t$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c" @ $(WASM2C) $(W2CFLAGS) $< -o $(SYSTEM)/pico8.c @ echo '#include "wasmrt.h"' > $(SYSTEM)/wasm-rt.h + @ touch $@ -$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c: $(TOOLS)/generate-sysroot \ - $(SYSTEM)/pico8.data.pod \ - $(SYSTEM)/unknown.p8.png \ - $(SYSTEM)/font.png +$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c: $(SYSTEM)/.sysroot ; +$(SYSTEM)/.sysroot: $(TOOLS)/generate-sysroot \ + $(SYSTEM)/pico8.data.pod \ + $(SYSTEM)/unknown.p8.png \ + $(SYSTEM)/font.png @ echo "TOOL\t$(SYSTEM)/sysroot.h $(SYSTEM)/sysroot.c" @ $< $(SYSTEM) + @ touch $@ $(SYSTEM)/pico8.data.pod: $(TOOLS)/extract-data-pod $(SYSTEM)/pico8.js @ echo "TOOL\t$@" @@ -68,6 +90,8 @@ $(SYSTEM)/%.png: carts/%.p8 @ mkdir -p $(dir $@) @ $(PICO8) $< -export $@ >/dev/null +endif + $(TOOLS)/%: tools/%.c @ echo "CC\t$@" @ mkdir -p $(dir $@) -- cgit v1.2.3