fixdep: Re-sync with Linux 5.7-rc1

fixdep is a standalone host program, so we can just re-sync it with
the latest Linux in one commit.

I kept the U-Boot own code block surrounded by
/* hack for U-Boot */ ... /* U-boot hack end */.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
Masahiro Yamada 2020-04-16 14:01:45 +09:00 committed by Tom Rini
parent 9d88a0aae8
commit 308c6b0d4b

View file

@ -77,11 +77,6 @@
* dependencies on include/config/my/option.h for every * dependencies on include/config/my/option.h for every
* CONFIG_MY_OPTION encountered in any of the prerequisites. * CONFIG_MY_OPTION encountered in any of the prerequisites.
* *
* It will also filter out all the dependencies on *.ver. We need
* to make sure that the generated version checksum are globally up
* to date before even starting the recursive build, so it's too late
* at this point anyway.
*
* We don't even try to really parse the header files, but * We don't even try to really parse the header files, but
* merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
* be picked up as well. It's not a problem with respect to * be picked up as well. It's not a problem with respect to
@ -99,6 +94,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@ -107,11 +103,40 @@ char tmp_buf[256]; /* hack for U-Boot */
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
fprintf(stderr, " -e insert extra dependencies given on stdin\n");
exit(1); exit(1);
} }
/*
* In the intended usage of this program, the stdout is redirected to .*.cmd
* files. The return value of printf() and putchar() must be checked to catch
* any error, e.g. "No space left on device".
*/
static void xprintf(const char *format, ...)
{
va_list ap;
int ret;
va_start(ap, format);
ret = vprintf(format, ap);
if (ret < 0) {
perror("fixdep");
exit(1);
}
va_end(ap);
}
static void xputchar(int c)
{
int ret;
ret = putchar(c);
if (ret == EOF) {
perror("fixdep");
exit(1);
}
}
/* /*
* Print out a dependency path from a symbol name * Print out a dependency path from a symbol name
*/ */
@ -119,7 +144,7 @@ static void print_dep(const char *m, int slen, const char *dir)
{ {
int c, prev_c = '/', i; int c, prev_c = '/', i;
printf(" $(wildcard %s/", dir); xprintf(" $(wildcard %s/", dir);
for (i = 0; i < slen; i++) { for (i = 0; i < slen; i++) {
c = m[i]; c = m[i];
if (c == '_') if (c == '_')
@ -127,25 +152,10 @@ static void print_dep(const char *m, int slen, const char *dir)
else else
c = tolower(c); c = tolower(c);
if (c != '/' || prev_c != '/') if (c != '/' || prev_c != '/')
putchar(c); xputchar(c);
prev_c = c; prev_c = c;
} }
printf(".h) \\\n"); xprintf(".h) \\\n");
}
static void do_extra_deps(void)
{
char buf[80];
while (fgets(buf, sizeof(buf), stdin)) {
int len = strlen(buf);
if (len < 2 || buf[len - 1] != '\n') {
fprintf(stderr, "fixdep: bad data on stdin\n");
exit(1);
}
print_dep(buf, len - 1, "include/ksym");
}
} }
struct item { struct item {
@ -238,7 +248,7 @@ static void parse_config_file(const char *p)
} }
p += 7; p += 7;
q = p; q = p;
while (*q && (isalnum(*q) || *q == '_')) while (isalnum(*q) || *q == '_')
q++; q++;
if (str_ends_with(p, q - p, "_MODULE")) if (str_ends_with(p, q - p, "_MODULE"))
r = q - 7; r = q - 7;
@ -309,8 +319,7 @@ static void *read_file(const char *filename)
static int is_ignored_file(const char *s, int len) static int is_ignored_file(const char *s, int len)
{ {
return str_ends_with(s, len, "include/generated/autoconf.h") || return str_ends_with(s, len, "include/generated/autoconf.h") ||
str_ends_with(s, len, "include/generated/autoksyms.h") || str_ends_with(s, len, "include/generated/autoksyms.h");
str_ends_with(s, len, ".ver");
} }
/* /*
@ -318,7 +327,7 @@ static int is_ignored_file(const char *s, int len)
* 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
* parser in scripts/mod/sumversion.c. * parser in scripts/mod/sumversion.c.
*/ */
static void parse_dep_file(char *m, const char *target, int insert_extra_deps) static void parse_dep_file(char *m, const char *target)
{ {
char *p; char *p;
int is_last, is_target; int is_last, is_target;
@ -365,13 +374,13 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
*/ */
if (!saw_any_target) { if (!saw_any_target) {
saw_any_target = 1; saw_any_target = 1;
printf("source_%s := %s\n\n", xprintf("source_%s := %s\n\n",
target, m); target, m);
printf("deps_%s := \\\n", target); xprintf("deps_%s := \\\n", target);
} }
is_first_dep = 0; is_first_dep = 0;
} else { } else {
printf(" %s \\\n", m); xprintf(" %s \\\n", m);
} }
buf = read_file(m); buf = read_file(m);
@ -394,23 +403,16 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
exit(1); exit(1);
} }
if (insert_extra_deps) xprintf("\n%s: $(deps_%s)\n\n", target, target);
do_extra_deps(); xprintf("$(deps_%s):\n", target);
printf("\n%s: $(deps_%s)\n\n", target, target);
printf("$(deps_%s):\n", target);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *depfile, *target, *cmdline; const char *depfile, *target, *cmdline;
int insert_extra_deps = 0;
void *buf; void *buf;
if (argc == 5 && !strcmp(argv[1], "-e")) { if (argc != 4)
insert_extra_deps = 1;
argv++;
} else if (argc != 4)
usage(); usage();
depfile = argv[1]; depfile = argv[1];
@ -424,10 +426,10 @@ int main(int argc, char *argv[])
strcpy(tmp_buf, "TPL_"); strcpy(tmp_buf, "TPL_");
/* end U-Boot hack */ /* end U-Boot hack */
printf("cmd_%s := %s\n\n", target, cmdline); xprintf("cmd_%s := %s\n\n", target, cmdline);
buf = read_file(depfile); buf = read_file(depfile);
parse_dep_file(buf, target, insert_extra_deps); parse_dep_file(buf, target);
free(buf); free(buf);
return 0; return 0;