From 337b171ac4a079a7c21701c0822377beb40c7fe2 Mon Sep 17 00:00:00 2001 From: DrDoof <8052722+DrDoof@users.noreply.github.com> Date: Tue, 29 Sep 2026 07:15:21 +0200 Subject: [PATCH] build: minify the web files only when they change html_min was phony, so every make deleted output/html_min and minified all of html/ again, even with nothing changed. A stamp file now stands for the minified copy and depends on the sources and on minify.py. A list of the source names, rewritten only when it changes, is a dependency too, so adding or removing a file in html/ still redoes the copy and a removed file does not stay behind in the image. If output/html_min is missing, the stamp is remade in the same run. The note on version.h in webui-compression.md still said it was phony. --- Makefile | 18 ++++++++++++++---- doc/webui-compression.md | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5754ee08..f0950a8a 100644 --- a/Makefile +++ b/Makefile @@ -145,13 +145,23 @@ HTML := $(shell find html -name '*.js' -or -name '*.html' -or -name '*.svg' -or # The raw html/ sources stay untouched for development; the minified # copy is a build artifact under output/. HTML_MIN := $(BUILDDIR)/html_min +HTML_MIN_LIST := $(BUILDDIR)/html_min.list +HTML_MIN_STAMP := $(BUILDDIR)/html_min.stamp .PHONY: html_min -html_min: $(HTML) +html_min: $(HTML_MIN_STAMP) + +$(HTML_MIN_LIST): FORCE + @mkdir -p $(BUILDDIR) + @echo $(sort $(HTML)) > $@.tmp + @cmp -s $@.tmp $@ && rm -f $@.tmp || mv $@.tmp $@ + +$(HTML_MIN_STAMP): $(HTML) $(HTML_MIN_LIST) tools/minify.py $(if $(wildcard $(HTML_MIN)),,FORCE) rm -rf $(HTML_MIN) mkdir -p $(HTML_MIN) @for f in $(HTML); do python3 tools/minify.py $$f $(HTML_MIN)/$$(basename $$f) || exit 1; done + @touch $@ -html_data.c html_data.h &: $(HTML) | tools html_min +html_data.c html_data.h &: $(HTML_MIN_STAMP) | tools tools/$(BUILDDIR)/fileadder -a $(HTML_LOCATION) -s $(IMAGESIZE) -b BANK1 -z -d $(HTML_MIN) -p html_data $(VERSION_HEADER): FORCE @@ -169,11 +179,11 @@ $(SUBDIRS): $(MAKE) -C $@ BUILDDIR=$(BUILDDIR) clean: $(SUBDIRSCLEAN) - -rm -f html_data.c html_data.h $(VERSION_HEADER) + -rm -f html_data.c html_data.h $(VERSION_HEADER) $(HTML_MIN_LIST) $(HTML_MIN_STAMP) -if [ -d $(BUILDDIR) ]; then find $(BUILDDIR) -type f ! -name "*.bin" -delete; fi distclean: $(SUBDIRSCLEAN) - -rm -f html_data.c html_data.h $(VERSION_HEADER) + -rm -f html_data.c html_data.h $(VERSION_HEADER) $(HTML_MIN_LIST) $(HTML_MIN_STAMP) -rm -rf $(BUILDDIR) $(SUBDIRSCLEAN): diff --git a/doc/webui-compression.md b/doc/webui-compression.md index 1765609f..9e5185da 100644 --- a/doc/webui-compression.md +++ b/doc/webui-compression.md @@ -79,8 +79,11 @@ JSON polling of the visible section). computation no longer depends on uninitialised buffer content. - `version.h` is now written by a single atomic `printf` (change from upstream) instead of five separate `echo`s, so a parallel build - (`make -j`) can no longer read a half-written copy. It stays in - `.PHONY` so it is regenerated on every build. + (`make -j`) can no longer read a half-written copy. It depends on + `FORCE`, so its recipe runs on every build, but the file is only + rewritten when its content changes. The minified copy in + `output/html_min/` is redone only when a web file, the list of web + files or `tools/minify.py` changes. ## Verification