Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v1] pkg-config.mk: introduce savefragment subcommand
@ 2023-08-18 10:17 Alexey Romanov via buildroot
  2023-08-19 13:42 ` Yann E. MORIN
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Romanov via buildroot @ 2023-08-18 10:17 UTC (permalink / raw)
  To: patrickdepinguin, yann.morin.1998, thomas.petazzoni
  Cc: kernel, ddrokosov, Dmitry Rokosov, Alexey Romanov, buildroot

Useful subcommand designed for run savedefconfig with fragment files.
Simple example of usage:

m linux-savefragment fragment=radio1_a_debug.fragment

The saved fragment for such fragment will be in:

out/$(target)/build/linux-custom/arch/$(arch)/configs/$(target).fragment

Signed-off-by: Alexey Romanov <avromanov@sberdevices.ru>
Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>
---
 package/pkg-kconfig.mk | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/package/pkg-kconfig.mk b/package/pkg-kconfig.mk
index 32dcfea0bc..7e5c7d88a1 100644
--- a/package/pkg-kconfig.mk
+++ b/package/pkg-kconfig.mk
@@ -37,6 +37,40 @@ define kconfig-package-savedefconfig
 		$(PKG_KCONFIG_COMMON_OPTS) $($(1)_KCONFIG_OPTS) savedefconfig
 endef
 
+FRAGMENT_CONFIG_PATH=arch/$(KERNEL_ARCH)/configs
+
+# Macro to save the fragment file
+# $(1): the name of the package in upper-case letters
+# $(2): the fragment name
+define kconfig-package-savefragment
+	$(eval ORIG_CONFIG=$(shell mktemp))
+	$(eval CHANGED_CONFIG=$(shell mktemp))
+	$(eval DIFF_CONFIG=$(shell mktemp))
+	$(eval NEW_FRAGMENT=$(shell mktemp))
+
+	$(Q) cp $($(1)_DIR)/.config $(CHANGED_CONFIG)
+
+	$($(1)_MAKE_ENV) $($(1)_MAKE) -C $($(1)_DIR) \
+		$(PKG_KCONFIG_COMMON_OPTS) $($(1)_KCONFIG_OPTS) \
+		$($(1)_KCONFIG_DEFCONFIG)
+
+	$(Q) cp $($(1)_DIR)/.config $(ORIG_CONFIG)
+
+	$(Q) $($(1)_DIR)/scripts/diffconfig -m $(ORIG_CONFIG) \
+		$(CHANGED_CONFIG) > $(DIFF_CONFIG)
+	$(Q) KCONFIG_CONFIG=$(NEW_FRAGMENT) \
+		$($(1)_DIR)/scripts/kconfig/merge_config.sh \
+		-m $($(1)_DIR)/$(FRAGMENT_CONFIG_PATH)/$(2) $(DIFF_CONFIG)
+	$(Q) sed -E -e 's/.*(CONFIG_[^ =]+).*/\1 \0/' $(NEW_FRAGMENT) \
+		| sort -k1 |  cut -d " " -f 2- > \
+		$($(1)_DIR)/$(FRAGMENT_CONFIG_PATH)/$(2)
+
+	$(Q) cp $(CHANGED_CONFIG) $($(1)_DIR)/.config
+
+	$(Q) rm -f $(ORIG_CONFIG) $(CHANGED_CONFIG) \
+		$(DIFF_CONFIG) $(NEW_FRAGMENT)
+endef
+
 # The correct way to regenerate a .config file is to use 'make olddefconfig'.
 # For historical reasons, the target name is 'oldnoconfig' between Linux kernel
 # versions 2.6.36 and 3.6, and remains as an alias in later versions.
@@ -282,6 +316,12 @@ $(1)-savedefconfig: $(1)-check-configuration-done
 	$$(call kconfig-package-savedefconfig,$(2))
 endif
 
+ifeq ($$($(2)_KCONFIG_SUPPORTS_DEFCONFIG),YES)
+.PHONY: $(1)-savefragment
+$(1)-savefragment: $(1)-check-configuration-done
+	$$(call kconfig-package-savefragment,$(2),$(fragment))
+endif
+
 ifeq ($$($(2)_KCONFIG_DEFCONFIG),)
 # Target to copy back the configuration to the source configuration file
 # Even though we could use 'cp --preserve-timestamps' here, the separate
-- 
2.30.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-19 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 10:17 [Buildroot] [PATCH v1] pkg-config.mk: introduce savefragment subcommand Alexey Romanov via buildroot
2023-08-19 13:42 ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox