[PATCH 3/8] kbuild: add support for merged defconfigs

Ahmad Fatoum a.fatoum at pengutronix.de
Fri May 17 06:26:51 PDT 2024


We currently use scripts/kconfig/merge_config.sh only in MAKEALL.
Linux has been using it inside Kbuild as well to derive new defconfigs
from the existing ones that differ only by a few options, e.g. to enable
virtualization or to switch endianness.

This is useful for us in barebox as well to cut down on the number of
configs and to avoid bitrot in the less used ones, e.g. a lot of AT91
configs can probably be replaced with two lines in mach-at91/Makefile
each this way.

To support this, let's import scripts/Makefile.defconf from Linux, but
we do some barebox-specific changes on it:

  - We include it globally, instead of each architecture including it
  - We implement a global way for architecture Makefiles to register
    their generated defconfigs, so they are shown in the help text
  - We look in common/boards/configs/ for fragments if there is no
    architecture-specific fragment with the same name to allow sharing
    fragments for common features

As this adds configs that aren't located in the source tree,
scripts/list-defconfigs.sh is adjusted to parse the help text instead,
so CI is aware of the new targets.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile                   |  6 +++++-
 scripts/Makefile.defconf   | 37 +++++++++++++++++++++++++++++++++++++
 scripts/list-defconfigs.sh | 20 ++++++++++----------
 3 files changed, 52 insertions(+), 11 deletions(-)
 create mode 100644 scripts/Makefile.defconf

diff --git a/Makefile b/Makefile
index 517b54bd9e6d..93d0b58341b7 100644
--- a/Makefile
+++ b/Makefile
@@ -535,6 +535,8 @@ ifdef config-build
 # *config targets only - make sure prerequisites are updated, and descend
 # in scripts/kconfig to make the *config target
 
+include $(srctree)/scripts/Makefile.defconf
+
 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
 # KBUILD_DEFCONFIG may point out an alternative default configuration
 # used for 'make defconfig'
@@ -1225,7 +1227,9 @@ PHONY += compile_commands.json
 # ---------------------------------------------------------------------------
 
 boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
-boards := $(sort $(notdir $(boards)))
+boards := $(sort $(notdir $(boards)) $(generated_configs))
+
+PHONY += $(generated_configs)
 
 help:
 	@echo  'Cleaning targets:'
diff --git a/scripts/Makefile.defconf b/scripts/Makefile.defconf
new file mode 100644
index 000000000000..93c848bb5a12
--- /dev/null
+++ b/scripts/Makefile.defconf
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0
+# Configuration heplers
+
+# Creates 'merged defconfigs'
+# compared to the Linux versions, this also looks for global config fragments
+# in common/boards/configs/ if no global fragments exist.
+# ---------------------------------------------------------------------------
+# Usage:
+#   $(call merge_into_defconfig,base_config,config_fragment1 config_fragment2 ...)
+#
+# Input config fragments without '.config' suffix
+define merge_into_defconfig
+	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
+		-m -O $(objtree) $(srctree)/arch/$(SRCARCH)/configs/$(1) \
+		$(foreach config,$(2),$(firstword \
+			$(wildcard $(srctree)/arch/$(SRCARCH)/configs/$(config).config) \
+			$(wildcard $(srctree)/common/boards/configs/$(config).config) \
+		))
+	+$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
+endef
+
+
+# Creates 'merged defconfigs without warning about overrides'
+# ---------------------------------------------------------------------------
+# Usage:
+#   $(call merge_into_defconfig_override,base_config,config_fragment1 config_fragment2 ...)
+#
+# Input config fragments without '.config' suffix
+define merge_into_defconfig_override
+	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
+		-Q -m -O $(objtree) $(srctree)/arch/$(SRCARCH)/configs/$(1) \
+		$(foreach config,$(2),$(firstword \
+			$(wildcard $(srctree)/arch/$(SRCARCH)/configs/$(config).config) \
+			$(wildcard $(srctree)/common/boards/configs/$(config).config) \
+		))
+	+$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
+endef
diff --git a/scripts/list-defconfigs.sh b/scripts/list-defconfigs.sh
index eeae9fbfdc30..d7516425f8e3 100755
--- a/scripts/list-defconfigs.sh
+++ b/scripts/list-defconfigs.sh
@@ -2,14 +2,14 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 # Output json formatted defconfig list for Github Action consumption
+ARCH=${@:-$(for a in arch/*/; do basename $a; done)}
 
-ARCH=${@:-*}
-
-cd arch
-
-archs=$(for arch in $ARCH; do
-	ls -1 $arch/configs | xargs -i printf '{ "arch": "%s", "config": "%s" }\n' \
-		"$arch" "{}" | paste -sd ',' -
-done | paste -sd ',' -)
-
-echo '{ "include" : '" [ $archs ] }"
+echo '{ "include" : [ '
+for arch in $ARCH; do
+	make ARCH=$arch CROSS_COMPILE= help | \
+		awk '/_defconfig/ { print $1  }' | \
+		xargs -i printf '{ "arch": "%s", "config": "%s" }\n' \
+		"$arch" "{}" | \
+		paste -sd ',' -
+done | paste -sd ',' -
+echo '] }'
-- 
2.39.2




More information about the barebox mailing list