.. | .. |
---|
77 | 77 | * dependencies on include/config/my/option.h for every |
---|
78 | 78 | * CONFIG_MY_OPTION encountered in any of the prerequisites. |
---|
79 | 79 | * |
---|
80 | | - * It will also filter out all the dependencies on *.ver. We need |
---|
81 | | - * to make sure that the generated version checksum are globally up |
---|
82 | | - * to date before even starting the recursive build, so it's too late |
---|
83 | | - * at this point anyway. |
---|
84 | | - * |
---|
85 | 80 | * We don't even try to really parse the header files, but |
---|
86 | 81 | * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will |
---|
87 | 82 | * be picked up as well. It's not a problem with respect to |
---|
.. | .. |
---|
99 | 94 | #include <unistd.h> |
---|
100 | 95 | #include <fcntl.h> |
---|
101 | 96 | #include <string.h> |
---|
| 97 | +#include <stdarg.h> |
---|
102 | 98 | #include <stdlib.h> |
---|
103 | 99 | #include <stdio.h> |
---|
104 | 100 | #include <ctype.h> |
---|
105 | 101 | |
---|
106 | 102 | static void usage(void) |
---|
107 | 103 | { |
---|
108 | | - fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); |
---|
109 | | - fprintf(stderr, " -e insert extra dependencies given on stdin\n"); |
---|
| 104 | + fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); |
---|
110 | 105 | exit(1); |
---|
| 106 | +} |
---|
| 107 | + |
---|
| 108 | +/* |
---|
| 109 | + * In the intended usage of this program, the stdout is redirected to .*.cmd |
---|
| 110 | + * files. The return value of printf() and putchar() must be checked to catch |
---|
| 111 | + * any error, e.g. "No space left on device". |
---|
| 112 | + */ |
---|
| 113 | +static void xprintf(const char *format, ...) |
---|
| 114 | +{ |
---|
| 115 | + va_list ap; |
---|
| 116 | + int ret; |
---|
| 117 | + |
---|
| 118 | + va_start(ap, format); |
---|
| 119 | + ret = vprintf(format, ap); |
---|
| 120 | + if (ret < 0) { |
---|
| 121 | + perror("fixdep"); |
---|
| 122 | + exit(1); |
---|
| 123 | + } |
---|
| 124 | + va_end(ap); |
---|
| 125 | +} |
---|
| 126 | + |
---|
| 127 | +static void xputchar(int c) |
---|
| 128 | +{ |
---|
| 129 | + int ret; |
---|
| 130 | + |
---|
| 131 | + ret = putchar(c); |
---|
| 132 | + if (ret == EOF) { |
---|
| 133 | + perror("fixdep"); |
---|
| 134 | + exit(1); |
---|
| 135 | + } |
---|
111 | 136 | } |
---|
112 | 137 | |
---|
113 | 138 | /* |
---|
.. | .. |
---|
117 | 142 | { |
---|
118 | 143 | int c, prev_c = '/', i; |
---|
119 | 144 | |
---|
120 | | - printf(" $(wildcard %s/", dir); |
---|
| 145 | + xprintf(" $(wildcard %s/", dir); |
---|
121 | 146 | for (i = 0; i < slen; i++) { |
---|
122 | 147 | c = m[i]; |
---|
123 | 148 | if (c == '_') |
---|
.. | .. |
---|
125 | 150 | else |
---|
126 | 151 | c = tolower(c); |
---|
127 | 152 | if (c != '/' || prev_c != '/') |
---|
128 | | - putchar(c); |
---|
| 153 | + xputchar(c); |
---|
129 | 154 | prev_c = c; |
---|
130 | 155 | } |
---|
131 | | - printf(".h) \\\n"); |
---|
132 | | -} |
---|
133 | | - |
---|
134 | | -static void do_extra_deps(void) |
---|
135 | | -{ |
---|
136 | | - char buf[80]; |
---|
137 | | - |
---|
138 | | - while (fgets(buf, sizeof(buf), stdin)) { |
---|
139 | | - int len = strlen(buf); |
---|
140 | | - |
---|
141 | | - if (len < 2 || buf[len - 1] != '\n') { |
---|
142 | | - fprintf(stderr, "fixdep: bad data on stdin\n"); |
---|
143 | | - exit(1); |
---|
144 | | - } |
---|
145 | | - print_dep(buf, len - 1, "include/ksym"); |
---|
146 | | - } |
---|
| 156 | + xprintf(".h) \\\n"); |
---|
147 | 157 | } |
---|
148 | 158 | |
---|
149 | 159 | struct item { |
---|
150 | 160 | struct item *next; |
---|
151 | 161 | unsigned int len; |
---|
152 | 162 | unsigned int hash; |
---|
153 | | - char name[0]; |
---|
| 163 | + char name[]; |
---|
154 | 164 | }; |
---|
155 | 165 | |
---|
156 | 166 | #define HASHSZ 256 |
---|
.. | .. |
---|
236 | 246 | } |
---|
237 | 247 | p += 7; |
---|
238 | 248 | q = p; |
---|
239 | | - while (*q && (isalnum(*q) || *q == '_')) |
---|
| 249 | + while (isalnum(*q) || *q == '_') |
---|
240 | 250 | q++; |
---|
241 | 251 | if (str_ends_with(p, q - p, "_MODULE")) |
---|
242 | 252 | r = q - 7; |
---|
.. | .. |
---|
284 | 294 | static int is_ignored_file(const char *s, int len) |
---|
285 | 295 | { |
---|
286 | 296 | return str_ends_with(s, len, "include/generated/autoconf.h") || |
---|
287 | | - str_ends_with(s, len, "include/generated/autoksyms.h") || |
---|
288 | | - str_ends_with(s, len, ".ver"); |
---|
| 297 | + str_ends_with(s, len, "include/generated/autoksyms.h"); |
---|
289 | 298 | } |
---|
290 | 299 | |
---|
291 | 300 | /* |
---|
.. | .. |
---|
293 | 302 | * assignments are parsed not only by make, but also by the rather simple |
---|
294 | 303 | * parser in scripts/mod/sumversion.c. |
---|
295 | 304 | */ |
---|
296 | | -static void parse_dep_file(char *m, const char *target, int insert_extra_deps) |
---|
| 305 | +static void parse_dep_file(char *m, const char *target) |
---|
297 | 306 | { |
---|
298 | 307 | char *p; |
---|
299 | 308 | int is_last, is_target; |
---|
.. | .. |
---|
340 | 349 | */ |
---|
341 | 350 | if (!saw_any_target) { |
---|
342 | 351 | saw_any_target = 1; |
---|
343 | | - printf("source_%s := %s\n\n", |
---|
344 | | - target, m); |
---|
345 | | - printf("deps_%s := \\\n", target); |
---|
| 352 | + xprintf("source_%s := %s\n\n", |
---|
| 353 | + target, m); |
---|
| 354 | + xprintf("deps_%s := \\\n", target); |
---|
346 | 355 | } |
---|
347 | 356 | is_first_dep = 0; |
---|
348 | 357 | } else { |
---|
349 | | - printf(" %s \\\n", m); |
---|
| 358 | + xprintf(" %s \\\n", m); |
---|
350 | 359 | } |
---|
351 | 360 | |
---|
352 | 361 | buf = read_file(m); |
---|
.. | .. |
---|
369 | 378 | exit(1); |
---|
370 | 379 | } |
---|
371 | 380 | |
---|
372 | | - if (insert_extra_deps) |
---|
373 | | - do_extra_deps(); |
---|
374 | | - |
---|
375 | | - printf("\n%s: $(deps_%s)\n\n", target, target); |
---|
376 | | - printf("$(deps_%s):\n", target); |
---|
| 381 | + xprintf("\n%s: $(deps_%s)\n\n", target, target); |
---|
| 382 | + xprintf("$(deps_%s):\n", target); |
---|
377 | 383 | } |
---|
378 | 384 | |
---|
379 | 385 | int main(int argc, char *argv[]) |
---|
380 | 386 | { |
---|
381 | 387 | const char *depfile, *target, *cmdline; |
---|
382 | | - int insert_extra_deps = 0; |
---|
383 | 388 | void *buf; |
---|
384 | 389 | |
---|
385 | | - if (argc == 5 && !strcmp(argv[1], "-e")) { |
---|
386 | | - insert_extra_deps = 1; |
---|
387 | | - argv++; |
---|
388 | | - } else if (argc != 4) |
---|
| 390 | + if (argc != 4) |
---|
389 | 391 | usage(); |
---|
390 | 392 | |
---|
391 | 393 | depfile = argv[1]; |
---|
392 | 394 | target = argv[2]; |
---|
393 | 395 | cmdline = argv[3]; |
---|
394 | 396 | |
---|
395 | | - printf("cmd_%s := %s\n\n", target, cmdline); |
---|
| 397 | + xprintf("cmd_%s := %s\n\n", target, cmdline); |
---|
396 | 398 | |
---|
397 | 399 | buf = read_file(depfile); |
---|
398 | | - parse_dep_file(buf, target, insert_extra_deps); |
---|
| 400 | + parse_dep_file(buf, target); |
---|
399 | 401 | free(buf); |
---|
400 | 402 | |
---|
401 | 403 | return 0; |
---|