aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 05:21:54 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 14:31:19 -0400
commita702a6176e2fea9ae366a7345247eb886e4cc730 (patch)
treee08bdefac418225fec1a8ac0aff85d379df03c0e /scripts/kconfig
parent1d6272e6fe43bc45c7ee58170d91d7242a71296b (diff)
kconfig: add 'filename' and 'lineno' built-in variables
The special variables, $(filename) and $(lineno), are expanded to a file name and its line number being parsed, respectively. Suggested-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'scripts/kconfig')
-rw-r--r--scripts/kconfig/preprocess.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index 5ee58eeb9a7d..0574039238c6 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -114,6 +114,11 @@ static char *do_error_if(int argc, char *argv[])
114 return NULL; 114 return NULL;
115} 115}
116 116
117static char *do_filename(int argc, char *argv[])
118{
119 return xstrdup(current_file->name);
120}
121
117static char *do_info(int argc, char *argv[]) 122static char *do_info(int argc, char *argv[])
118{ 123{
119 printf("%s\n", argv[0]); 124 printf("%s\n", argv[0]);
@@ -121,6 +126,15 @@ static char *do_info(int argc, char *argv[])
121 return xstrdup(""); 126 return xstrdup("");
122} 127}
123 128
129static char *do_lineno(int argc, char *argv[])
130{
131 char buf[16];
132
133 sprintf(buf, "%d", yylineno);
134
135 return xstrdup(buf);
136}
137
124static char *do_shell(int argc, char *argv[]) 138static char *do_shell(int argc, char *argv[])
125{ 139{
126 FILE *p; 140 FILE *p;
@@ -173,7 +187,9 @@ static char *do_warning_if(int argc, char *argv[])
173static const struct function function_table[] = { 187static const struct function function_table[] = {
174 /* Name MIN MAX Function */ 188 /* Name MIN MAX Function */
175 { "error-if", 2, 2, do_error_if }, 189 { "error-if", 2, 2, do_error_if },
190 { "filename", 0, 0, do_filename },
176 { "info", 1, 1, do_info }, 191 { "info", 1, 1, do_info },
192 { "lineno", 0, 0, do_lineno },
177 { "shell", 1, 1, do_shell }, 193 { "shell", 1, 1, do_shell },
178 { "warning-if", 2, 2, do_warning_if }, 194 { "warning-if", 2, 2, do_warning_if },
179}; 195};