[Buildroot] [PATCH v1] pkg-config.mk: introduce savefragment subcommand

Yann E. MORIN yann.morin.1998 at free.fr
Sat Aug 19 13:42:38 UTC 2023


Alexey, All,

On 2023-08-18 13:17 +0300, Alexey Romanov via buildroot spake thusly:
> Useful subcommand designed for run savedefconfig with fragment files.
> Simple example of usage:
> 
> m linux-savefragment fragment=radio1_a_debug.fragment

Generating a new fragment is not usually that useful; indeed, whether a
configuration item changed (enabled, disabled, set to something) is
important, and only a human can decide what part of the configuration
files such change in setting should go: main configuration file, or one
of the following fragments.

To help achioeve this, there is already a command to generate a diff of
the current configuration against the "configured-known" one:

    $ make linux-diff-config

Then the user can decide to update the existing main configuration file,
update an existing fragment, or create a new fragment.

This is however not documented, and if we need something, it is
documentation for that existing command rather than a new one;
see lines 100-onward.

Can you look into that instead, please?

Regards,
Yann E. MORIN.

> 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 at sberdevices.ru>
> Signed-off-by: Dmitry Rokosov <ddrokosov at 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 at buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'



More information about the buildroot mailing list