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. --- tools/extract-data-pod.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'tools/extract-data-pod.c') diff --git a/tools/extract-data-pod.c b/tools/extract-data-pod.c index 50beadc..9a7bbdb 100644 --- a/tools/extract-data-pod.c +++ b/tools/extract-data-pod.c @@ -27,7 +27,10 @@ int main(int argc, char *argv[argc + 1]) { FILE *f = fopen(argv[1], "r"); check(f, "fopen(input)"); - char buffer[1024 * 1024]; + // 1 MiB is quite large for the stack, we also assume that the data.pod + // lives entirely within the first part of the file. This is true for the + // current version, and we can change this if it ever changes. + static char buffer[1024 * 1024]; size_t n = fread(buffer, 1, sizeof(buffer) - 1, f); check(n, "fread(input)"); buffer[n] = '\0'; @@ -46,16 +49,20 @@ int main(int argc, char *argv[argc + 1]) { for (char *s = strtok(start, sep); s; s = strtok(NULL, sep)) { long b = strtol(s, &s, 10); - ensure(b < 256 && *s == '\0', "failed to read byte"); + ensure(b >= 0 && b < 256 && *s == '\0', "failed to read byte"); + ensure((size_t)(dataptr - data) < sizeof(data), "data pod too large"); *(dataptr++) = (uint8_t)b; } } + size_t datalen = (size_t)(dataptr - data); + ensure(datalen, "failed to decode data.pod"); + FILE *o = fopen(argv[2], "wb"); check(o, "fopen(output)"); - size_t datalen = (size_t)(dataptr - data); check(datalen == fwrite(data, 1, datalen, o), "fwrite(output)"); + check(!fclose(o), "fclose(output)"); return EXIT_SUCCESS; } -- cgit v1.2.3