Commit 87b95a81 authored by Masahiro Yamada's avatar Masahiro Yamada

fixdep: refactor parse_dep_file()

parse_dep_file() has too much indentation, and puts the code far to
the right.  This commit refactors the code and reduces the one level
of indentation.

strrcmp() computes 'slen' by itself, but the caller already knows the
length of the token, so 'slen' can be passed via function argument.
With this, we can swap the order of strrcmp() and "*p = \0;"

Also, strrcmp() is an ambiguous function name.  Flip the logic and
rename it to str_ends_with().

I added a new helper is_ignored_file() - this returns 1 if the token
represents a file that should be ignored.
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 5d1ef76f
...@@ -239,15 +239,14 @@ static void parse_config_file(const char *p) ...@@ -239,15 +239,14 @@ static void parse_config_file(const char *p)
} }
/* test if s ends in sub */ /* test if s ends in sub */
static int strrcmp(const char *s, const char *sub) static int str_ends_with(const char *s, int slen, const char *sub)
{ {
int slen = strlen(s);
int sublen = strlen(sub); int sublen = strlen(sub);
if (sublen > slen) if (sublen > slen)
return 1; return 0;
return memcmp(s + slen - sublen, sub, sublen); return !memcmp(s + slen - sublen, sub, sublen);
} }
static void *read_file(const char *filename) static void *read_file(const char *filename)
...@@ -282,6 +281,16 @@ static void *read_file(const char *filename) ...@@ -282,6 +281,16 @@ static void *read_file(const char *filename)
return buf; return buf;
} }
/* Ignore certain dependencies */
static int is_ignored_file(const char *s, int len)
{
return str_ends_with(s, len, "include/generated/autoconf.h") ||
str_ends_with(s, len, "include/generated/autoksyms.h") ||
str_ends_with(s, len, "arch/um/include/uml-config.h") ||
str_ends_with(s, len, "include/linux/kconfig.h") ||
str_ends_with(s, len, ".ver");
}
/* /*
* Important: The below generated source_foo.o and deps_foo.o variable * Important: The below generated source_foo.o and deps_foo.o variable
* assignments are parsed not only by make, but also by the rather simple * assignments are parsed not only by make, but also by the rather simple
...@@ -314,48 +323,39 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) ...@@ -314,48 +323,39 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
if (is_target) { if (is_target) {
/* The /next/ file is the first dependency */ /* The /next/ file is the first dependency */
is_first_dep = 1; is_first_dep = 1;
} else { } else if (!is_ignored_file(m, p - m)) {
*p = '\0'; *p = '\0';
/* Ignore certain dependencies */
if (strrcmp(m, "include/generated/autoconf.h") &&
strrcmp(m, "include/generated/autoksyms.h") &&
strrcmp(m, "arch/um/include/uml-config.h") &&
strrcmp(m, "include/linux/kconfig.h") &&
strrcmp(m, ".ver")) {
/* /*
* Do not list the source file as dependency, * Do not list the source file as dependency, so that
* so that kbuild is not confused if a .c file * kbuild is not confused if a .c file is rewritten
* is rewritten into .S or vice versa. Storing * into .S or vice versa. Storing it in source_* is
* it in source_* is needed for modpost to * needed for modpost to compute srcversions.
* compute srcversions.
*/ */
if (is_first_dep) { if (is_first_dep) {
/* /*
* If processing the concatenation of * If processing the concatenation of multiple
* multiple dependency files, only * dependency files, only process the first
* process the first target name, which * target name, which will be the original
* will be the original source name, * source name, and ignore any other target
* and ignore any other target names, * names, which will be intermediate temporary
* which will be intermediate temporary
* files. * files.
*/ */
if (!saw_any_target) { if (!saw_any_target) {
saw_any_target = 1; saw_any_target = 1;
printf("source_%s := %s\n\n", printf("source_%s := %s\n\n",
target, m); target, m);
printf("deps_%s := \\\n", printf("deps_%s := \\\n", target);
target);
} }
is_first_dep = 0; is_first_dep = 0;
} else } else {
printf(" %s \\\n", m); printf(" %s \\\n", m);
}
buf = read_file(m); buf = read_file(m);
parse_config_file(buf); parse_config_file(buf);
free(buf); free(buf);
} }
}
if (is_last) if (is_last)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment