]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/build/fixdep.c
2 * "Optimize" a list of dependencies as spit out by gcc -MD
3 * for the build framework.
6 * Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de>
8 * This code has been borrowed from kbuild's fixdep (scripts/basic/fixdep.c),
9 * Please check it for detailed explanation. This fixdep borow only the
10 * base transformation of dependecies without the CONFIG mangle.
13 #include <sys/types.h>
27 static void usage(void)
29 fprintf(stderr
, "Usage: fixdep <depfile> <target> <cmdline>\n");
34 * Print out the commandline prefixed with cmd_<target filename> :=
36 static void print_cmdline(void)
38 printf("cmd_%s := %s\n\n", target
, cmdline
);
42 * Important: The below generated source_foo.o and deps_foo.o variable
43 * assignments are parsed not only by make, but also by the rather simple
44 * parser in scripts/mod/sumversion.c.
46 static void parse_dep_file(void *map
, size_t len
)
52 int is_target
, has_target
= 0;
53 int saw_any_target
= 0;
57 /* Skip any "white space" */
58 while (m
< end
&& (*m
== ' ' || *m
== '\\' || *m
== '\n'))
60 /* Find next "white space" */
62 while (p
< end
&& *p
!= ' ' && *p
!= '\\' && *p
!= '\n')
64 /* Is the token we found a target name? */
65 is_target
= (*(p
-1) == ':');
66 /* Don't write any target names into the dependency file */
68 /* The /next/ file is the first dependency */
71 } else if (has_target
) {
72 /* Save this token/filename */
77 * Do not list the source file as dependency,
78 * so that kbuild is not confused if a .c file
79 * is rewritten into .S or vice versa. Storing
80 * it in source_* is needed for modpost to
81 * compute srcversions.
85 * If processing the concatenation of
86 * multiple dependency files, only
87 * process the first target name, which
88 * will be the original source name,
89 * and ignore any other target names,
90 * which will be intermediate temporary
93 if (!saw_any_target
) {
95 printf("source_%s := %s\n\n",
97 printf("deps_%s := \\\n",
102 printf(" %s \\\n", s
);
105 * Start searching for next token immediately after the first
106 * "whitespace" character that follows this token.
111 if (!saw_any_target
) {
112 fprintf(stderr
, "fixdep: parse error; no targets found\n");
116 printf("\n%s: $(deps_%s)\n\n", target
, target
);
117 printf("$(deps_%s):\n", target
);
120 static void print_deps(void)
126 fd
= open(depfile
, O_RDONLY
);
128 fprintf(stderr
, "fixdep: error opening depfile: ");
132 if (fstat(fd
, &st
) < 0) {
133 fprintf(stderr
, "fixdep: error fstat'ing depfile: ");
137 if (st
.st_size
== 0) {
138 fprintf(stderr
, "fixdep: %s is empty\n", depfile
);
142 map
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
143 if ((long) map
== -1) {
144 perror("fixdep: mmap");
149 parse_dep_file(map
, st
.st_size
);
151 munmap(map
, st
.st_size
);
156 int main(int argc
, char **argv
)