jw-pkg/make/cache.mk
Jan Lindemann 262be57741
cache.mk: Don't overwrite defined variables

Check with ifndef if a variable is defined before hard defining it in cache.mk. This gives more flexibility when overriding variables with local.mk.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-05 16:57:00 +02:00

30 lines
843 B
Makefile

# ----- define these variables
# CACHED_FILES = $(TOPDIR)/VERSION
# CACHED_VARS = VERSION
.PHONY: cache clean-cache clean-cache-projects
CACHE_PROJECT_MK ?= .cache-project.mk
CACHED_VARS_ONLY_PROJECT ?= \
PROJECT \
PREREQ \
VERSION \
HEX_VERSION \
FULL_NAME \
JW_PKG_LD_LIBRARY_PATH \
JW_PKG_EXE_PATH \
JW_PKG_PYTHON_PATH
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
@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 $@.tmp
mv $@.tmp $@