jw-pkg/make/cache.mk
Jan Lindemann 2b04e387df
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m5s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 5m0s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m41s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m33s
CI / Packaging test (push) Successful in 0s
cache.mk: Avoid recaching stale variable values
If $(CACHE_PROJECT_MK) AKA .cache-project.mk already exists but needs
to be remade because of dependencies, it is included, its content
read, then the content cached again to the same file. That way stale
variables can leak into the refreshed cache.

This commit fixes the situation by removing it, then invoking make
again to remake it, thereby clearing the variable database and
forcing make to fill the variables afresh.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-11 14:25:34 +02:00

49 lines
1.4 KiB
Makefile

# ----- define these variables
# CACHED_FILES = $(TOPDIR)/VERSION
# CACHED_VARS = VERSION
.PHONY: cache clean.cache
CACHED_FILES ?= $(VERSION_FILE) $(wildcard $(TOPDIR)/make/project.conf)
CACHED_VARS ?= PROJECT PREREQ_BUILD PREREQ_RUN PREREQ VERSION HEX_VERSION \
FULL_NAME WHICH PYTHON ECHO TEST BROWSER SED RM PWD ID CUT TR \
AWK GETENT XARGS FIND PRINTF PLATFORM_INFO OS_NAME_VERSION \
CAT BIN_INSTALL SUDO \
JW_PKG_LD_LIBRARY_PATH JW_PKG_EXE_PATH JW_PKG_PYTHON_PATH
CACHED_VARS_ONLY_PROJECT ?= \
PROJECT \
PREREQ_BUILD \
PREREQ_RUN \
PREREQ \
VERSION \
HEX_VERSION \
FULL_NAME \
JW_PKG_LD_LIBRARY_PATH \
JW_PKG_EXE_PATH \
JW_PKG_PYTHON_PATH
# We need this to cache JW_PKG_PYTHON_PATH
include $(JWBDIR)/make/py-path.mk
all: cache
clean: clean.cache
clean.cache:
rm -f $(CACHE_PROJECT_MK)
cache: $(CACHE_PROJECT_MK)
$(CACHE_PROJECT_MK): $(CACHED_FILES) $(JWBDIR)/make/cache.mk
ifneq ($(wildcard $(CACHE_PROJECT_MK)),)
rm -f $@
make $@
else
@echo 'ifneq ($$(JW_PKG_NO_CACHE),true)' | tee $@.tmp
@echo $(foreach v,$(CACHED_VARS),$v = $(value $(v)) EOL) | \
$(SED) 's/\s\+EOL/\n/g;' | \
$(SED) 's/\s*\(\S\+\)\s*=\s*\(.*\)\s*/ifndef \1\n \1 = \2\nendif\n/g;' | \
$(SED) 's|$(realpath $(TOPDIR))|$$(TOPDIR)|g' | \
$(SED) 's|$(realpath $(PROJECTS_DIR))|$$(PROJECTS_DIR)|g' | \
$(GREP) . | \
tee -a $@.tmp
@echo 'endif # ifneq ($$(JW_PKG_NO_CACHE),true)' | tee -a $@.tmp
mv $@.tmp $@
endif