From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/8] kbuild: add support for merged defconfigs
Date: Fri, 17 May 2024 15:26:51 +0200 [thread overview]
Message-ID: <20240517132656.3151273-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240517132656.3151273-1-a.fatoum@pengutronix.de>
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@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
next prev parent reply other threads:[~2024-05-17 13:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 13:26 [PATCH 0/8] kconfig: cut down on duplication with " Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 1/8] test: move common config fragments into common/boards/configs Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 2/8] kconfig: merge_config.sh: sync with Linux v6.9 Ahmad Fatoum
2024-05-17 13:26 ` Ahmad Fatoum [this message]
2024-05-17 13:26 ` [PATCH 4/8] MIPS: make use of merged defconfigs Ahmad Fatoum
2024-05-20 10:23 ` [PATCH] fixup! " Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 5/8] sandbox: stdio: fix ctrlc link error when CONFIG_CONSOLE_NONE=y Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 6/8] net: fix build with CONFIG_SHELL_NONE Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 7/8] power: reset: reboot-mode: fix link error without globalvar Ahmad Fatoum
2024-05-17 13:26 ` [PATCH 8/8] sandbox: add headless_defconfig Ahmad Fatoum
2024-05-21 6:20 ` [PATCH 0/8] kconfig: cut down on duplication with merged defconfigs Sascha Hauer
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=20240517132656.3151273-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox