* [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration
@ 2026-11-19 18:45 Peter Korsgaard
2026-12-04 8:28 ` Peter Korsgaard
0 siblings, 1 reply; 2+ messages in thread
From: Peter Korsgaard @ 2026-11-19 18:45 UTC (permalink / raw)
To: buildroot
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration
2026-11-19 18:45 [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration Peter Korsgaard
@ 2026-12-04 8:28 ` Peter Korsgaard
0 siblings, 0 replies; 2+ messages in thread
From: Peter Korsgaard @ 2026-12-04 8:28 UTC (permalink / raw)
To: buildroot
>>>>> "Peter" == Peter Korsgaard <peter@korsgaard.com> writes:
> 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>
2 weeks without any objections - So committed, thanks.
--
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 8:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 18:45 [Buildroot] [PATCH-NEXT] Makefile: support config fragments for the Buildroot configuration Peter Korsgaard
2026-12-04 8:28 ` Peter Korsgaard
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.