From f21ff8e71367832069a254b7863f02b3eab5f27f Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 26 May 2026 10:34:17 +0200 Subject: [PATCH] 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 --- conf/topdir/Makefile | 6 ++++++ make/topdir.mk | 28 ++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 conf/topdir/Makefile diff --git a/conf/topdir/Makefile b/conf/topdir/Makefile new file mode 100644 index 00000000..7f6e10f5 --- /dev/null +++ b/conf/topdir/Makefile @@ -0,0 +1,6 @@ +TOPDIR = ../.. + +CONFIG_SUBDIR = $(notdir $(shell pwd)) + +include $(TOPDIR)/make/proj.mk +include $(JWBDIR)/make/conf.mk diff --git a/make/topdir.mk b/make/topdir.mk index 9830022d..cde44114 100644 --- a/make/topdir.mk +++ b/make/topdir.mk @@ -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 $@