aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/preprocess.c
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 18:21:51 +0900
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-29 03:31:19 +0900
commited2a22f277c60308481ecea1e1b846cbf249af41 (patch)
treede91d6e6c9f17a34aa5ef643468aca147b35d3e5 /scripts/kconfig/preprocess.c
parent1175c02506ffc9cef9f3c520249d8740a3174b1f (diff)
downloadlinux-stericsson-ed2a22f277c60308481ecea1e1b846cbf249af41.tar.gz
kconfig: support append assignment operator
Support += operator. This appends a space and the text on the righthand side to a variable. The timing of the evaluation of the righthand side depends on the flavor of the variable. If the lefthand side was originally defined as a simple variable, the righthand side is expanded immediately. Otherwise, the expansion is deferred. Appending something to an undefined variable results in a recursive variable. To implement this, we need to remember the flavor of variables. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/kconfig/preprocess.c')
-rw-r--r--scripts/kconfig/preprocess.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index d103683b386e..56aa1f0bad04 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -222,11 +222,23 @@ void variable_add(const char *name, const char *value,
enum variable_flavor flavor)
{
struct variable *v;
+ char *new_value;
+ bool append = false;
v = variable_lookup(name);
if (v) {
- free(v->value);
+ /* For defined variables, += inherits the existing flavor */
+ if (flavor == VAR_APPEND) {
+ flavor = v->flavor;
+ append = true;
+ } else {
+ free(v->value);
+ }
} else {
+ /* For undefined variables, += assumes the recursive flavor */
+ if (flavor == VAR_APPEND)
+ flavor = VAR_RECURSIVE;
+
v = xmalloc(sizeof(*v));
v->name = xstrdup(name);
list_add_tail(&v->node, &variable_list);
@@ -235,9 +247,19 @@ void variable_add(const char *name, const char *value,
v->flavor = flavor;
if (flavor == VAR_SIMPLE)
- v->value = expand_string(value);
+ new_value = expand_string(value);
else
- v->value = xstrdup(value);
+ new_value = xstrdup(value);
+
+ if (append) {
+ v->value = xrealloc(v->value,
+ strlen(v->value) + strlen(new_value) + 2);
+ strcat(v->value, " ");
+ strcat(v->value, new_value);
+ free(new_value);
+ } else {
+ v->value = new_value;
+ }
}
static void variable_del(struct variable *v)