From: Peter Korsgaard <peter@korsgaard.com>
To: buildroot@buildroot.org
Subject: [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration
Date: Thu, 19 Nov 2026 19:45:39 +0100 [thread overview]
Message-ID: <20261119184541.652770-1-peter@korsgaard.com> (raw)
We have had the merge_config.sh config fragments script for many years and
logic in the kconfig infrastructure to handle them, but so far no builtin
logic to use config fragments for the Buildroot configuration itself, so add
logic to apply config fragments from .config files stored under configs/,
similar to how it is done for the Linux kernel or U-Boot.
E.G. given a config fragment:
cat debug.config
BR2_PACKAGE_DROPBEAR=y
Then running:
make raspberrypi_defconfig debug.config
Would configure Buildroot for the Raspberry Pi and then apply the config
fragment in debug.config on top to enable dropbear.
Add logic similar to what we have for defconfigs to look for config
fragments in Buildroot and any br2-external trees and also add a "make
list-fragments" make target, similar to how we have "make list-defconfigs"
for listing the available fragments and mention it in the manual.
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
Makefile | 47 +++++++++++++++++++
.../manual/customize-directory-structure.adoc | 1 +
docs/manual/customize-outside-br.adoc | 8 ++++
3 files changed, 56 insertions(+)
diff --git a/Makefile b/Makefile
index 8077ee1834..0493e1b21a 100644
--- a/Makefile
+++ b/Makefile
@@ -1052,6 +1052,22 @@ defconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
$(COMMON_CONFIG_ENV) BR2_DEFCONFIG=$${defconfig} \
$< --defconfig=$${defconfig} $(CONFIG_CONFIG_IN)
+# needed to ensure below rule isn't triggered by the BR2_CONFIG include above
+$(BR2_CONFIG): ;
+
+%.config: $(BUILD_DIR)/buildroot-config/conf outputmakefile
+ @config=$(or \
+ $(firstword \
+ $(foreach d, \
+ $(call reverse,$(TOPDIR) $(BR2_EXTERNAL_DIRS)), \
+ $(wildcard $(d)/configs/$@) \
+ ) \
+ ), \
+ $(error "Can't find $@") \
+ ); \
+ CONFIG_="" $(TOPDIR)/support/kconfig/merge_config.sh -m \
+ -O $(dir $(BR2_CONFIG)) $(BR2_CONFIG) $${config}
+
update-defconfig: savedefconfig
savedefconfig: $(BUILD_DIR)/buildroot-config/conf outputmakefile
@@ -1214,6 +1230,7 @@ help:
@echo ' graph-depends - generate graph of the dependency tree'
@echo ' graph-size - generate stats of the filesystem size'
@echo ' list-defconfigs - list all defconfigs (pre-configured minimal systems)'
+ @echo ' list-fragments - list all config fragments'
@echo
@echo 'Miscellaneous:'
@echo ' source - download all sources needed for offline-build'
@@ -1264,6 +1281,36 @@ list-defconfigs:
$(call list-defconfigs,$(BR2_EXTERNAL_$(name)_PATH),\
$(BR2_EXTERNAL_$(name)_DESC))$(sep))
+# List the config fragment files
+# $(1): base directory
+# $(2): br2-external name, empty for bundled
+define list-fragments
+ @first=true; \
+ for config in $$([ -d $(1)/configs ] && find $(1)/configs -name '*.config' |sort); do \
+ [ -f "$${config}" ] || continue; \
+ if $${first}; then \
+ if [ "$(2)" ]; then \
+ printf 'External config fragments in "%s":\n' "$(call qstrip,$(2))"; \
+ else \
+ printf "Built-in config fragments:\n"; \
+ fi; \
+ first=false; \
+ fi; \
+ config="$${config#$(1)/configs/}"; \
+ printf " %-35s - Configure for %s\n" "$${config}" "$${config%.config}"; \
+ done; \
+ $${first} || printf "\n"
+endef
+
+# We iterate over BR2_EXTERNAL_NAMES rather than BR2_EXTERNAL_DIRS,
+# because we want to display the name of the br2-external tree.
+.PHONY: list-fragments
+list-fragments:
+ $(call list-fragments,$(TOPDIR))
+ $(foreach name,$(BR2_EXTERNAL_NAMES),\
+ $(call list-fragments,$(BR2_EXTERNAL_$(name)_PATH),\
+ $(BR2_EXTERNAL_$(name)_DESC))$(sep))
+
release: OUT = buildroot-$(BR2_VERSION)
# Create release tarballs. We need to fiddle a bit to add the generated
diff --git a/docs/manual/customize-directory-structure.adoc b/docs/manual/customize-directory-structure.adoc
index aab225811b..963e7a59ae 100644
--- a/docs/manual/customize-directory-structure.adoc
+++ b/docs/manual/customize-directory-structure.adoc
@@ -36,6 +36,7 @@ to you.
|
+-- configs/
| +-- <boardname>_defconfig
+| +-- <tweak>.config (if config fragment are used)
|
+-- package/
| +-- <company>/
diff --git a/docs/manual/customize-outside-br.adoc b/docs/manual/customize-outside-br.adoc
index 8a76f3a998..d8937888ba 100644
--- a/docs/manual/customize-outside-br.adoc
+++ b/docs/manual/customize-outside-br.adoc
@@ -182,6 +182,14 @@ normal +make <name>_defconfig+ command. They will be visible in the
'make list-defconfigs' output, below an +External configs+ label that
contains the name of the br2-external tree they are defined in.
+Likewise, config fragments can also be stored in the +configs+
+subdirectory of the br2-external tree. Buildroot will automatically
+show them in the output of +make list-fragments+ and allow them to be
+loaded with the normal +make <name>.config+ command. They will be
+visible in the 'make list-fragments' output, below an +External
+configs+ label that contains the name of the br2-external tree they
+are defined in.
+
.Note:
If a defconfig file is present in more than one br2-external tree, then
the one from the last br2-external tree is used. It is thus possible
--
2.47.3
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next reply other threads:[~2026-11-19 18:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:45 Peter Korsgaard [this message]
2026-12-04 8:28 ` [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration Peter Korsgaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119184541.652770-1-peter@korsgaard.com \
--to=peter@korsgaard.com \
--cc=buildroot@buildroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.