diff mbox series

[v2,2/5] package/pkg-utils: add KCONFIG_APPEND_OPT

Message ID 20221014065900.3311604-3-angelo@amarulasolutions.com
State Rejected
Headers show
Series Lichee RV and Lichee RV dock support | expand

Commit Message

Angelo Compagnucci Oct. 14, 2022, 6:58 a.m. UTC
This macro can be used to append a value to a previously configured
option where the intent is to join the old value with the new one.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
---
 package/pkg-utils.mk | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
index 0945e6ed31..d812946934 100644
--- a/package/pkg-utils.mk
+++ b/package/pkg-utils.mk
@@ -33,6 +33,16 @@  define KCONFIG_ENABLE_OPT
 		$(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2)); \
 	fi
 endef
+# KCONFIG_APPEND_OPT (option, value, [, file])
+# If the option is already set append, else add new.
+define KCONFIG_APPEND_OPT
+	$(Q)if ! grep -q '^$(strip $(1))' $(call KCONFIG_DOT_CONFIG,$(3)); then \
+		$(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=$(2), $(3)); \
+	else \
+		grep -E '$(strip $(1)).*$(strip $(2))' $(call KCONFIG_DOT_CONFIG,$(3)) || \
+		$(SED) 's|$(1)="\(.*\)"|$(1)="\1 $(2)"|g' $(call KCONFIG_DOT_CONFIG,$(3)); \
+	fi
+endef
 # KCONFIG_SET_OPT (option, value [, file])
 KCONFIG_SET_OPT     = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=$(2), $(3))
 # KCONFIG_DISABLE_OPT  (option [, file])