From: Masahiro Yamada Date: Mon, 28 May 2018 09:21:54 +0000 (+0900) Subject: kconfig: add 'filename' and 'lineno' built-in variables X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=6598140e430d622be926aed43ec19fec8326cd11;p=carl9170fw.git 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 Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Signed-off-by: Christian Lamparter --- diff --git a/config/preprocess.c b/config/preprocess.c index 5ee58ee..0574039 100644 --- a/config/preprocess.c +++ b/config/preprocess.c @@ -114,6 +114,11 @@ static char *do_error_if(int argc, char *argv[]) return NULL; } +static char *do_filename(int argc, char *argv[]) +{ + return xstrdup(current_file->name); +} + static char *do_info(int argc, char *argv[]) { printf("%s\n", argv[0]); @@ -121,6 +126,15 @@ static char *do_info(int argc, char *argv[]) return xstrdup(""); } +static char *do_lineno(int argc, char *argv[]) +{ + char buf[16]; + + sprintf(buf, "%d", yylineno); + + return xstrdup(buf); +} + static char *do_shell(int argc, char *argv[]) { FILE *p; @@ -173,7 +187,9 @@ static char *do_warning_if(int argc, char *argv[]) static const struct function function_table[] = { /* Name MIN MAX Function */ { "error-if", 2, 2, do_error_if }, + { "filename", 0, 0, do_filename }, { "info", 1, 1, do_info }, + { "lineno", 0, 0, do_lineno }, { "shell", 1, 1, do_shell }, { "warning-if", 2, 2, do_warning_if }, };