Skip to content

Commit

Permalink
kconfig: add 'filename' and 'lineno' built-in variables
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Masahiro Yamada committed May 28, 2018
1 parent 1d6272e commit a702a61
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/kconfig/preprocess.c
Original file line number Diff line number Diff line change
@@ -114,13 +114,27 @@ 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]);

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 },
};

0 comments on commit a702a61

Please sign in to comment.