[Buildroot] [PATCH 2/3] support/kconfig: Allow appending to config

Charlie Jenkins charlie at rivosinc.com
Fri Apr 11 02:35:19 UTC 2025


Using a "+=" instead of a "=" when setting a config to be merged, will
cause the value on the right side to be appended to the values of other
configs of the same name.

Note: The value must be enclosed in quotes.

Signed-off-by: Charlie Jenkins <charlie at rivosinc.com>
---
 support/kconfig/merge_config.sh | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/support/kconfig/merge_config.sh b/support/kconfig/merge_config.sh
index daaa055b70dbe790578148255b490b6010815c30..26bf41cab53ea54993a15b8be4ff40940a62e793 100755
--- a/support/kconfig/merge_config.sh
+++ b/support/kconfig/merge_config.sh
@@ -123,6 +123,8 @@ fi
 MERGE_LIST=$*
 SED_CONFIG_EXP1="s/^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)=.*/\1/p"
 SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p"
+APPEND_EXP="^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)+=\"\(.*\)\""
+SED_CONFIG_APPEND_EXP="s/$APPEND_EXP/\1,\2/p"
 
 TMP_FILE=$(mktemp -t .tmp.config.XXXXXXXXXX)
 
@@ -152,7 +154,23 @@ for MERGE_FILE in $MERGE_LIST ; do
 		fi
 		sed -i "/$CFG[ =]/d" $TMP_FILE
 	done
-	cat $MERGE_FILE >> $TMP_FILE
+
+	CFG_APPEND_LIST=$(sed -n -e "$SED_CONFIG_APPEND_EXP" $MERGE_FILE)
+
+	for CFG in $CFG_APPEND_LIST ; do
+		OLDIFS=$IFS
+		IFS=','
+		set -- $CFG # Config name ends up in $1 and value in $2
+		IFS=$OLDIFS
+
+		if grep -q -w $1 $TMP_FILE ; then
+			sed -i -e "s/$1=\"\(.*\)\"/$1=\"\1 $2\"/" $TMP_FILE
+		else
+			echo "$1=\"$2\"" | cat >> $TMP_FILE
+		fi
+	done
+
+	sed -e "/$APPEND_EXP/d" $MERGE_FILE | cat >> $TMP_FILE
 done
 
 if [ "$RUNMAKE" = "false" ]; then

-- 
2.43.0



More information about the buildroot mailing list