topdir.mk: Add dynamic file creation machinery

Add generic machinery to dynamically create files in $(TOPDIR). The need arises because version controlled configuration files for linters are going to be introduced.

For that, this commit introduces a variable $(TD_GENERATE_FILES), which target all depends on, and which topdir.clean removes.

It defaults to another variable also introduced by this commit, $(TD_COPY_FILES), which in turn defaults to $(TOPDIR)/conf/topdir.

This commit also adds support for JW_PKG_TOPDIR_COPY_PATH. It supports a PATH-style syntax, which allows pointing to multiple directories to be checked for source files. If they exist, they will be appended to the files found in $(TOPDIR)/conf/topdir after copying. Defining arbitray files to copy is not supported before security implications during CI runs are better understood.

Having the copy prerequisites work comes at the cost of having to add .SECONDEXPANSION. Since it's limited to the toplevel Makefile, I suppose that's acceptable.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-05-26 10:34:17 +02:00
commit f21ff8e713
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 30 additions and 4 deletions

6
conf/topdir/Makefile Normal file
View file

@ -0,0 +1,6 @@
TOPDIR = ../..
CONFIG_SUBDIR = $(notdir $(shell pwd))
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/conf.mk

View file

@ -1,3 +1,6 @@
# Need second expansion for TD_COPY_XXX concatenation rule to work
.SECONDEXPANSION:
.PHONY: \
FORCE \
all \
@ -107,10 +110,18 @@ STREAMLINE_PROJECT ?= bash $(JWB_SCRIPT_DIR)/streamline-project.sh
INSTALLED_TOPDIR_FILES = $(addprefix $(INSTALL_DOCDIR)/, $(DOCS))
TD_CONF_DIR ?= $(JW_PKG_CONF_BASE_DIR)/topdir
TD_COPY_SRC ?= $(TD_CONF_DIR)
TD_COPY_FILES ?= $(filter-out Makefile,$(notdir $(wildcard $(TD_COPY_SRC)/*)))
# -- Internal variables, define JW_PKG_TOPDIR_COPY_PATH if you want to
# add more files appended to the target files
TD_COPY_SRC_PATH = $(subst :,$(space),$(JW_PKG_TOPDIR_COPY_PATH))
TD_GENERATE_FILES += $(TD_COPY_FILES)
all: config
format:
check-syntax:
check-format:
check-syntax: topdir
check-format: topdir
check: check-syntax check-format
install: topdir.install
clean: topdir.clean
@ -129,10 +140,13 @@ local-%: FORCE
unlocal:
$(RM) -f $(shell find . -name local.mk)
topdir: $(TD_GENERATE_FILES)
topdir.clean:
$(RM) -rf *.done $(TD_GENERATE_FILES)
clean: topdir.clean
topdir.distclean: topdir.clean
$(RM) -rf dist *.dist
topdir.clean:
$(RM) -rf *.done
distclean: topdir.distclean
topdir.mrproper: topdir.distclean
find . -name '*.rep' | xargs -r $(RM) -f
@ -282,3 +296,9 @@ recache-vars:
canonicalize-remotes:
$(PYTHON) $(JWB_SCRIPT_DIR)/jw-pkg.py projects canonicalize-remotes
Makefile: ;
%: $(TD_COPY_SRC)/% $$(foreach path,$$(TD_COPY_SRC_PATH),$$(wildcard $$(addprefix $$(path)/,$$@))) $$(wildcard $$@.*)
cat $^ > $@.tmp
mv $@.tmp $@