hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/scripts/basic/fixdep.c
....@@ -77,11 +77,6 @@
7777 * dependencies on include/config/my/option.h for every
7878 * CONFIG_MY_OPTION encountered in any of the prerequisites.
7979 *
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
- *
8580 * We don't even try to really parse the header files, but
8681 * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
8782 * be picked up as well. It's not a problem with respect to
....@@ -99,15 +94,45 @@
9994 #include <unistd.h>
10095 #include <fcntl.h>
10196 #include <string.h>
97
+#include <stdarg.h>
10298 #include <stdlib.h>
10399 #include <stdio.h>
104100 #include <ctype.h>
105101
106102 static void usage(void)
107103 {
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");
110105 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
+ }
111136 }
112137
113138 /*
....@@ -117,7 +142,7 @@
117142 {
118143 int c, prev_c = '/', i;
119144
120
- printf(" $(wildcard %s/", dir);
145
+ xprintf(" $(wildcard %s/", dir);
121146 for (i = 0; i < slen; i++) {
122147 c = m[i];
123148 if (c == '_')
....@@ -125,32 +150,17 @@
125150 else
126151 c = tolower(c);
127152 if (c != '/' || prev_c != '/')
128
- putchar(c);
153
+ xputchar(c);
129154 prev_c = c;
130155 }
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");
147157 }
148158
149159 struct item {
150160 struct item *next;
151161 unsigned int len;
152162 unsigned int hash;
153
- char name[0];
163
+ char name[];
154164 };
155165
156166 #define HASHSZ 256
....@@ -236,7 +246,7 @@
236246 }
237247 p += 7;
238248 q = p;
239
- while (*q && (isalnum(*q) || *q == '_'))
249
+ while (isalnum(*q) || *q == '_')
240250 q++;
241251 if (str_ends_with(p, q - p, "_MODULE"))
242252 r = q - 7;
....@@ -284,8 +294,7 @@
284294 static int is_ignored_file(const char *s, int len)
285295 {
286296 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");
289298 }
290299
291300 /*
....@@ -293,7 +302,7 @@
293302 * assignments are parsed not only by make, but also by the rather simple
294303 * parser in scripts/mod/sumversion.c.
295304 */
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)
297306 {
298307 char *p;
299308 int is_last, is_target;
....@@ -340,13 +349,13 @@
340349 */
341350 if (!saw_any_target) {
342351 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);
346355 }
347356 is_first_dep = 0;
348357 } else {
349
- printf(" %s \\\n", m);
358
+ xprintf(" %s \\\n", m);
350359 }
351360
352361 buf = read_file(m);
....@@ -369,33 +378,26 @@
369378 exit(1);
370379 }
371380
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);
377383 }
378384
379385 int main(int argc, char *argv[])
380386 {
381387 const char *depfile, *target, *cmdline;
382
- int insert_extra_deps = 0;
383388 void *buf;
384389
385
- if (argc == 5 && !strcmp(argv[1], "-e")) {
386
- insert_extra_deps = 1;
387
- argv++;
388
- } else if (argc != 4)
390
+ if (argc != 4)
389391 usage();
390392
391393 depfile = argv[1];
392394 target = argv[2];
393395 cmdline = argv[3];
394396
395
- printf("cmd_%s := %s\n\n", target, cmdline);
397
+ xprintf("cmd_%s := %s\n\n", target, cmdline);
396398
397399 buf = read_file(depfile);
398
- parse_dep_file(buf, target, insert_extra_deps);
400
+ parse_dep_file(buf, target);
399401 free(buf);
400402
401403 return 0;