summaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/util.c
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 05:21:40 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 14:28:58 -0400
commit104daea149c45cc84842ce77a9bd6436d19f3dd8 (patch)
tree7f0aaa24e9fa03154a74b2bd7bcb93f24d678ea4 /scripts/kconfig/util.c
parentf1089c92da791034af73478159626007cba7f092 (diff)
kconfig: reference environment variables directly and remove 'option env='
To get access to environment variables, Kconfig needs to define a symbol using "option env=" syntax. It is tedious to add a symbol entry for each environment variable given that we need to define much more such as 'CC', 'AS', 'srctree' etc. to evaluate the compiler capability in Kconfig. Adding '$' for symbol references is grammatically inconsistent. Looking at the code, the symbols prefixed with 'S' are expanded by: - conf_expand_value() This is used to expand 'arch/$ARCH/defconfig' and 'defconfig_list' - sym_expand_string_value() This is used to expand strings in 'source' and 'mainmenu' All of them are fixed values independent of user configuration. So, they can be changed into the direct expansion instead of symbols. This change makes the code much cleaner. The bounce symbols 'SRCARCH', 'ARCH', 'SUBARCH', 'KERNELVERSION' are gone. sym_init() hard-coding 'UNAME_RELEASE' is also gone. 'UNAME_RELEASE' should be replaced with an environment variable. ARCH_DEFCONFIG is a normal symbol, so it should be simply referenced without '$' prefix. The new syntax is addicted by Make. The variable reference needs parentheses, like $(FOO), but you can omit them for single-letter variables, like $F. Yet, in Makefiles, people tend to use the parenthetical form for consistency / clarification. At this moment, only the environment variable is supported, but I will extend the concept of 'variable' later on. The variables are expanded in the lexer so we can simplify the token handling on the parser side. For example, the following code works. [Example code] config MY_TOOLCHAIN_LIST string default "My tools: CC=$(CC), AS=$(AS), CPP=$(CPP)" [Result] $ make -s alldefconfig && tail -n 1 .config CONFIG_MY_TOOLCHAIN_LIST="My tools: CC=gcc, AS=as, CPP=gcc -E" Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'scripts/kconfig/util.c')
-rw-r--r--scripts/kconfig/util.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index c6f6e21b809f..703ee4904613 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -34,8 +34,6 @@ struct file *file_lookup(const char *name)
34/* write a dependency file as used by kbuild to track dependencies */ 34/* write a dependency file as used by kbuild to track dependencies */
35int file_write_dep(const char *name) 35int file_write_dep(const char *name)
36{ 36{
37 struct symbol *sym, *env_sym;
38 struct expr *e;
39 struct file *file; 37 struct file *file;
40 FILE *out; 38 FILE *out;
41 39
@@ -54,21 +52,7 @@ int file_write_dep(const char *name)
54 fprintf(out, "\n%s: \\\n" 52 fprintf(out, "\n%s: \\\n"
55 "\t$(deps_config)\n\n", conf_get_autoconfig_name()); 53 "\t$(deps_config)\n\n", conf_get_autoconfig_name());
56 54
57 expr_list_for_each_sym(sym_env_list, e, sym) { 55 env_write_dep(out, conf_get_autoconfig_name());
58 struct property *prop;
59 const char *value;
60
61 prop = sym_get_env_prop(sym);
62 env_sym = prop_get_symbol(prop);
63 if (!env_sym)
64 continue;
65 value = getenv(env_sym->name);
66 if (!value)
67 value = "";
68 fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
69 fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name());
70 fprintf(out, "endif\n");
71 }
72 56
73 fprintf(out, "\n$(deps_config): ;\n"); 57 fprintf(out, "\n$(deps_config): ;\n");
74 fclose(out); 58 fclose(out);
@@ -165,3 +149,14 @@ char *xstrdup(const char *s)
165 fprintf(stderr, "Out of memory.\n"); 149 fprintf(stderr, "Out of memory.\n");
166 exit(1); 150 exit(1);
167} 151}
152
153char *xstrndup(const char *s, size_t n)
154{
155 char *p;
156
157 p = strndup(s, n);
158 if (p)
159 return p;
160 fprintf(stderr, "Out of memory.\n");
161 exit(1);
162}