aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/basic/fixdep.c
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-01-11 08:05:45 -0500
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-01-17 19:37:39 -0500
commit87b95a81357dd6ec679a786cebfe34d0e797f752 (patch)
tree4ff8959f557331f671428f59bc7a19e544be8708 /scripts/basic/fixdep.c
parent5d1ef76f5a22ea07120671c5fcddafd365000cc9 (diff)
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: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/basic/fixdep.c')
-rw-r--r--scripts/basic/fixdep.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index d33b5a4c9ecb..0abc15778f56 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -239,15 +239,14 @@ static void parse_config_file(const char *p)
239} 239}
240 240
241/* test if s ends in sub */ 241/* test if s ends in sub */
242static int strrcmp(const char *s, const char *sub) 242static int str_ends_with(const char *s, int slen, const char *sub)
243{ 243{
244 int slen = strlen(s);
245 int sublen = strlen(sub); 244 int sublen = strlen(sub);
246 245
247 if (sublen > slen) 246 if (sublen > slen)
248 return 1; 247 return 0;
249 248
250 return memcmp(s + slen - sublen, sub, sublen); 249 return !memcmp(s + slen - sublen, sub, sublen);
251} 250}
252 251
253static void *read_file(const char *filename) 252static void *read_file(const char *filename)
@@ -282,6 +281,16 @@ static void *read_file(const char *filename)
282 return buf; 281 return buf;
283} 282}
284 283
284/* Ignore certain dependencies */
285static int is_ignored_file(const char *s, int len)
286{
287 return str_ends_with(s, len, "include/generated/autoconf.h") ||
288 str_ends_with(s, len, "include/generated/autoksyms.h") ||
289 str_ends_with(s, len, "arch/um/include/uml-config.h") ||
290 str_ends_with(s, len, "include/linux/kconfig.h") ||
291 str_ends_with(s, len, ".ver");
292}
293
285/* 294/*
286 * Important: The below generated source_foo.o and deps_foo.o variable 295 * Important: The below generated source_foo.o and deps_foo.o variable
287 * assignments are parsed not only by make, but also by the rather simple 296 * assignments are parsed not only by make, but also by the rather simple
@@ -314,47 +323,38 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
314 if (is_target) { 323 if (is_target) {
315 /* The /next/ file is the first dependency */ 324 /* The /next/ file is the first dependency */
316 is_first_dep = 1; 325 is_first_dep = 1;
317 } else { 326 } else if (!is_ignored_file(m, p - m)) {
318 *p = '\0'; 327 *p = '\0';
319 328
320 /* Ignore certain dependencies */ 329 /*
321 if (strrcmp(m, "include/generated/autoconf.h") && 330 * Do not list the source file as dependency, so that
322 strrcmp(m, "include/generated/autoksyms.h") && 331 * kbuild is not confused if a .c file is rewritten
323 strrcmp(m, "arch/um/include/uml-config.h") && 332 * into .S or vice versa. Storing it in source_* is
324 strrcmp(m, "include/linux/kconfig.h") && 333 * needed for modpost to compute srcversions.
325 strrcmp(m, ".ver")) { 334 */
335 if (is_first_dep) {
326 /* 336 /*
327 * Do not list the source file as dependency, 337 * If processing the concatenation of multiple
328 * so that kbuild is not confused if a .c file 338 * dependency files, only process the first
329 * is rewritten into .S or vice versa. Storing 339 * target name, which will be the original
330 * it in source_* is needed for modpost to 340 * source name, and ignore any other target
331 * compute srcversions. 341 * names, which will be intermediate temporary
342 * files.
332 */ 343 */
333 if (is_first_dep) { 344 if (!saw_any_target) {
334 /* 345 saw_any_target = 1;
335 * If processing the concatenation of 346 printf("source_%s := %s\n\n",
336 * multiple dependency files, only 347 target, m);
337 * process the first target name, which 348 printf("deps_%s := \\\n", target);
338 * will be the original source name, 349 }
339 * and ignore any other target names, 350 is_first_dep = 0;
340 * which will be intermediate temporary 351 } else {
341 * files. 352 printf(" %s \\\n", m);
342 */
343 if (!saw_any_target) {
344 saw_any_target = 1;
345 printf("source_%s := %s\n\n",
346 target, m);
347 printf("deps_%s := \\\n",
348 target);
349 }
350 is_first_dep = 0;
351 } else
352 printf(" %s \\\n", m);
353
354 buf = read_file(m);
355 parse_config_file(buf);
356 free(buf);
357 } 353 }
354
355 buf = read_file(m);
356 parse_config_file(buf);
357 free(buf);
358 } 358 }
359 359
360 if (is_last) 360 if (is_last)