]> git.ozlabs.org Git - ccan/blob - tools/configurator/configurator.c
tools/configurator: set HAVE_CLOCK_GETTIME even if it's in -lrt.
[ccan] / tools / configurator / configurator.c
1 /* Simple tool to create config.h.
2  * Would be much easier with ccan modules, but deliberately standalone.
3  *
4  * Copyright 2011 Rusty Russell <rusty@rustcorp.com.au>.  MIT license.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <err.h>
29 #include <sys/types.h>
30 #include <sys/wait.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <string.h>
34
35 #define DEFAULT_COMPILER "cc"
36 #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
37
38 #define OUTPUT_FILE "configurator.out"
39 #define INPUT_FILE "configuratortest.c"
40
41 static int verbose;
42
43 enum test_style {
44         OUTSIDE_MAIN            = 0x1,
45         DEFINES_FUNC            = 0x2,
46         INSIDE_MAIN             = 0x4,
47         DEFINES_EVERYTHING      = 0x8,
48         MAY_NOT_COMPILE         = 0x10,
49         EXECUTE                 = 0x8000
50 };
51
52 struct test {
53         const char *name;
54         enum test_style style;
55         const char *depends;
56         const char *link;
57         const char *fragment;
58         const char *overrides; /* On success, force this to '1' */
59         bool done;
60         bool answer;
61 };
62
63 static struct test tests[] = {
64         { "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
65           "#include <sys/types.h>\n"
66           "int main(int argc, char *argv[]) {\n"
67           "     return sizeof(off_t) == 4 ? 0 : 1;\n"
68           "}\n" },
69         { "HAVE_ALIGNOF", INSIDE_MAIN, NULL, NULL,
70           "return __alignof__(double) > 0 ? 0 : 1;" },
71         { "HAVE_ASPRINTF", DEFINES_FUNC, NULL, NULL,
72           "#define _GNU_SOURCE\n"
73           "#include <stdio.h>\n"
74           "static char *func(int x) {"
75           "     char *p;\n"
76           "     if (asprintf(&p, \"%u\", x) == -1) p = NULL;"
77           "     return p;\n"
78           "}" },
79         { "HAVE_ATTRIBUTE_COLD", DEFINES_FUNC, NULL, NULL,
80           "static int __attribute__((cold)) func(int x) { return x; }" },
81         { "HAVE_ATTRIBUTE_CONST", DEFINES_FUNC, NULL, NULL,
82           "static int __attribute__((const)) func(int x) { return x; }" },
83         { "HAVE_ATTRIBUTE_PURE", DEFINES_FUNC, NULL, NULL,
84           "static int __attribute__((pure)) func(int x) { return x; }" },
85         { "HAVE_ATTRIBUTE_MAY_ALIAS", OUTSIDE_MAIN, NULL, NULL,
86           "typedef short __attribute__((__may_alias__)) short_a;" },
87         { "HAVE_ATTRIBUTE_NORETURN", DEFINES_FUNC, NULL, NULL,
88           "#include <stdlib.h>\n"
89           "static void __attribute__((noreturn)) func(int x) { exit(x); }" },
90         { "HAVE_ATTRIBUTE_PRINTF", DEFINES_FUNC, NULL, NULL,
91           "static void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }" },
92         { "HAVE_ATTRIBUTE_UNUSED", OUTSIDE_MAIN, NULL, NULL,
93           "static int __attribute__((unused)) func(int x) { return x; }" },
94         { "HAVE_ATTRIBUTE_USED", OUTSIDE_MAIN, NULL, NULL,
95           "static int __attribute__((used)) func(int x) { return x; }" },
96         { "HAVE_BACKTRACE", DEFINES_FUNC, NULL, NULL,
97           "#include <execinfo.h>\n"
98           "static int func(int x) {"
99           "     void *bt[10];\n"
100           "     return backtrace(bt, 10) < x;\n"
101           "}" },
102         { "HAVE_BIG_ENDIAN", INSIDE_MAIN|EXECUTE, NULL, NULL,
103           "union { int i; char c[sizeof(int)]; } u;\n"
104           "u.i = 0x01020304;\n"
105           "return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;" },
106         { "HAVE_BSWAP_64", DEFINES_FUNC, "HAVE_BYTESWAP_H", NULL,
107           "#include <byteswap.h>\n"
108           "static int func(int x) { return bswap_64(x); }" },
109         { "HAVE_BUILTIN_CHOOSE_EXPR", INSIDE_MAIN, NULL, NULL,
110           "return __builtin_choose_expr(1, 0, \"garbage\");" },
111         { "HAVE_BUILTIN_CLZ", INSIDE_MAIN, NULL, NULL,
112           "return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;" },
113         { "HAVE_BUILTIN_CLZL", INSIDE_MAIN, NULL, NULL,
114           "return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;" },
115         { "HAVE_BUILTIN_CLZLL", INSIDE_MAIN, NULL, NULL,
116           "return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;" },
117         { "HAVE_BUILTIN_CONSTANT_P", INSIDE_MAIN, NULL, NULL,
118           "return __builtin_constant_p(1) ? 0 : 1;" },
119         { "HAVE_BUILTIN_EXPECT", INSIDE_MAIN, NULL, NULL,
120           "return __builtin_expect(argc == 1, 1) ? 0 : 1;" },
121         { "HAVE_BUILTIN_FFSL", INSIDE_MAIN, NULL, NULL,
122           "return __builtin_ffsl(0L) == 0 ? 0 : 1;" },
123         { "HAVE_BUILTIN_FFSLL", INSIDE_MAIN, NULL, NULL,
124           "return __builtin_ffsll(0LL) == 0 ? 0 : 1;" },
125         { "HAVE_BUILTIN_POPCOUNTL", INSIDE_MAIN, NULL, NULL,
126           "return __builtin_popcountl(255L) == 8 ? 0 : 1;" },
127         { "HAVE_BUILTIN_TYPES_COMPATIBLE_P", INSIDE_MAIN, NULL, NULL,
128           "return __builtin_types_compatible_p(char *, int) ? 1 : 0;" },
129         { "HAVE_BYTESWAP_H", OUTSIDE_MAIN, NULL, NULL,
130           "#include <byteswap.h>\n" },
131         { "HAVE_CLOCK_GETTIME",
132           DEFINES_FUNC, "HAVE_STRUCT_TIMESPEC", NULL,
133           "#include <time.h>\n"
134           "static struct timespec func(void) {\n"
135           "     struct timespec ts;\n"
136           "     clock_gettime(CLOCK_REALTIME, &ts);\n"
137           "     return ts;\n"
138           "}\n" },
139         { "HAVE_CLOCK_GETTIME_IN_LIBRT",
140           DEFINES_FUNC,
141           "HAVE_STRUCT_TIMESPEC !HAVE_CLOCK_GETTIME",
142           "-lrt",
143           "#include <time.h>\n"
144           "static struct timespec func(void) {\n"
145           "     struct timespec ts;\n"
146           "     clock_gettime(CLOCK_REALTIME, &ts);\n"
147           "     return ts;\n"
148           "}\n",
149           /* This means HAVE_CLOCK_GETTIME, too */
150           "HAVE_CLOCK_GETTIME" },
151         { "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
152           "int *foo = (int[]) { 1, 2, 3, 4 };\n"
153           "return foo[0] ? 0 : 1;" },
154         { "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
155           "#include <sys/types.h>\n"
156           "#include <sys/stat.h>\n"
157           "#include <fcntl.h>\n"
158           "#include <unistd.h>\n"
159           "int main(void) {\n"
160           "     int fd = open(\"..\", O_RDONLY);\n"
161           "     return fchdir(fd) == 0 ? 0 : 1;\n"
162           "}\n" },
163         { "HAVE_ERR_H", DEFINES_FUNC, NULL, NULL,
164           "#include <err.h>\n"
165           "static void func(int arg) {\n"
166           "     if (arg == 0)\n"
167           "             err(1, \"err %u\", arg);\n"
168           "     if (arg == 1)\n"
169           "             errx(1, \"err %u\", arg);\n"
170           "     if (arg == 3)\n"
171           "             warn(\"warn %u\", arg);\n"
172           "     if (arg == 4)\n"
173           "             warnx(\"warn %u\", arg);\n"
174           "}\n" },
175         { "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
176           "HAVE_32BIT_OFF_T", NULL,
177           "#define _FILE_OFFSET_BITS 64\n"
178           "#include <sys/types.h>\n"
179           "int main(int argc, char *argv[]) {\n"
180           "     return sizeof(off_t) == 8 ? 0 : 1;\n"
181           "}\n" },
182         { "HAVE_FOR_LOOP_DECLARATION", INSIDE_MAIN, NULL, NULL,
183           "for (int i = 0; i < argc; i++) { return 0; };\n"
184           "return 1;" },
185         { "HAVE_FLEXIBLE_ARRAY_MEMBER", OUTSIDE_MAIN, NULL, NULL,
186           "struct foo { unsigned int x; int arr[]; };" },
187         { "HAVE_GETPAGESIZE", DEFINES_FUNC, NULL, NULL,
188           "#include <unistd.h>\n"
189           "static int func(void) { return getpagesize(); }" },
190         { "HAVE_ISBLANK", DEFINES_FUNC, NULL, NULL,
191           "#define _GNU_SOURCE\n"
192           "#include <ctype.h>\n"
193           "static int func(void) { return isblank(' '); }" },
194         { "HAVE_LITTLE_ENDIAN", INSIDE_MAIN|EXECUTE, NULL, NULL,
195           "union { int i; char c[sizeof(int)]; } u;\n"
196           "u.i = 0x01020304;\n"
197           "return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;" },
198         { "HAVE_MEMMEM", DEFINES_FUNC, NULL, NULL,
199           "#define _GNU_SOURCE\n"
200           "#include <string.h>\n"
201           "static void *func(void *h, size_t hl, void *n, size_t nl) {\n"
202           "return memmem(h, hl, n, nl);"
203           "}\n", },
204         { "HAVE_MMAP", DEFINES_FUNC, NULL, NULL,
205           "#include <sys/mman.h>\n"
206           "static void *func(int fd) {\n"
207           "     return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
208           "}" },
209         { "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
210           "#include <sys/types.h>\n"
211           "#include <sys/stat.h>\n"
212           "#include <fcntl.h>\n"
213           "int main(void) {\n"
214           "     return open(\"/proc/self/maps\", O_RDONLY) != -1 ? 0 : 1;\n"
215           "}\n" },
216         { "HAVE_QSORT_R_PRIVATE_LAST",
217           DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
218           "#define _GNU_SOURCE 1\n"
219           "#include <stdlib.h>\n"
220           "static int cmp(const void *lp, const void *rp, void *priv) {\n"
221           " *(unsigned int *)priv = 1;\n"
222           " return *(const int *)lp - *(const int *)rp; }\n"
223           "int main(void) {\n"
224           " int array[] = { 9, 2, 5 };\n"
225           " unsigned int called = 0;\n"
226           " qsort_r(array, 3, sizeof(int), cmp, &called);\n"
227           " return called && array[0] == 2 && array[1] == 5 && array[2] == 9 ? 0 : 1;\n"
228           "}\n" },
229         { "HAVE_STRUCT_TIMESPEC",
230           DEFINES_FUNC, NULL, NULL,
231           "#include <time.h>\n"
232           "static void func(void) {\n"
233           "     struct timespec ts;\n"
234           "     ts.tv_sec = ts.tv_nsec = 1;\n"
235           "}\n" },
236         { "HAVE_SECTION_START_STOP",
237           DEFINES_FUNC, NULL, NULL,
238           "static void *__attribute__((__section__(\"mysec\"))) p = &p;\n"
239           "static int func(void) {\n"
240           "     extern void *__start_mysec[], *__stop_mysec[];\n"
241           "     return __stop_mysec - __start_mysec;\n"
242           "}\n" },
243         { "HAVE_STACK_GROWS_UPWARDS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
244           "static long nest(const void *base, unsigned int i)\n"
245           "{\n"
246           "     if (i == 0)\n"
247           "             return (const char *)&i - (const char *)base;\n"
248           "     return nest(base, i-1);\n"
249           "}\n"
250           "int main(int argc, char *argv[]) {\n"
251           "     return (nest(&argc, argc) > 0) ? 0 : 1\n;"
252           "}\n" },
253         { "HAVE_STATEMENT_EXPR", INSIDE_MAIN, NULL, NULL,
254           "return ({ int x = argc; x == argc ? 0 : 1; });" },
255         { "HAVE_SYS_FILIO_H", OUTSIDE_MAIN, NULL, NULL, /* Solaris needs this for FIONREAD */
256           "#include <sys/filio.h>\n" },
257         { "HAVE_SYS_TERMIOS_H", OUTSIDE_MAIN, NULL, NULL,
258           "#include <sys/termios.h>\n" },
259         { "HAVE_TYPEOF", INSIDE_MAIN, NULL, NULL,
260           "__typeof__(argc) i; i = argc; return i == argc ? 0 : 1;" },
261         { "HAVE_UTIME", DEFINES_FUNC, NULL, NULL,
262           "#include <sys/types.h>\n"
263           "#include <utime.h>\n"
264           "static int func(const char *filename) {\n"
265           "     struct utimbuf times = { 0 };\n"
266           "     return utime(filename, &times);\n"
267           "}" },
268         { "HAVE_WARN_UNUSED_RESULT", DEFINES_FUNC, NULL, NULL,
269           "#include <sys/types.h>\n"
270           "#include <utime.h>\n"
271           "static __attribute__((warn_unused_result)) int func(int i) {\n"
272           "     return i + 1;\n"
273           "}" },
274 };
275
276 static char *grab_fd(int fd)
277 {
278         int ret;
279         size_t max, size = 0;
280         char *buffer;
281
282         max = 16384;
283         buffer = malloc(max+1);
284         while ((ret = read(fd, buffer + size, max - size)) > 0) {
285                 size += ret;
286                 if (size == max)
287                         buffer = realloc(buffer, max *= 2);
288         }
289         if (ret < 0)
290                 err(1, "reading from command");
291         buffer[size] = '\0';
292         return buffer;
293 }
294
295 static char *run(const char *cmd, int *exitstatus)
296 {
297         pid_t pid;
298         int p[2];
299         char *ret;
300         int status;
301
302         if (pipe(p) != 0)
303                 err(1, "creating pipe");
304
305         pid = fork();
306         if (pid == -1)
307                 err(1, "forking");
308
309         if (pid == 0) {
310                 if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
311                     || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
312                     || close(p[0]) != 0
313                     || close(STDIN_FILENO) != 0
314                     || open("/dev/null", O_RDONLY) != STDIN_FILENO)
315                         exit(128);
316
317                 status = system(cmd);
318                 if (WIFEXITED(status))
319                         exit(WEXITSTATUS(status));
320                 /* Here's a hint... */
321                 exit(128 + WTERMSIG(status));
322         }
323
324         close(p[1]);
325         ret = grab_fd(p[0]);
326         /* This shouldn't fail... */
327         if (waitpid(pid, &status, 0) != pid)
328                 err(1, "Failed to wait for child");
329         close(p[0]);
330         if (WIFEXITED(status))
331                 *exitstatus = WEXITSTATUS(status);
332         else
333                 *exitstatus = -WTERMSIG(status);
334         return ret;
335 }
336
337 static char *connect_args(const char *argv[], const char *extra)
338 {
339         unsigned int i, len = strlen(extra) + 1;
340         char *ret;
341
342         for (i = 1; argv[i]; i++)
343                 len += 1 + strlen(argv[i]);
344
345         ret = malloc(len);
346         len = 0;
347         for (i = 1; argv[i]; i++) {
348                 strcpy(ret + len, argv[i]);
349                 len += strlen(argv[i]);
350                 if (argv[i+1])
351                         ret[len++] = ' ';
352         }
353         strcpy(ret + len, extra);
354         return ret;
355 }
356
357 static struct test *find_test(const char *name)
358 {
359         unsigned int i;
360
361         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
362                 if (strcmp(tests[i].name, name) == 0)
363                         return &tests[i];
364         }
365         abort();
366 }
367
368 #define PRE_BOILERPLATE "/* Test program generated by configurator. */\n"
369 #define MAIN_START_BOILERPLATE "int main(int argc, char *argv[]) {\n"
370 #define USE_FUNC_BOILERPLATE "(void)func;\n"
371 #define MAIN_BODY_BOILERPLATE "return 0;\n"
372 #define MAIN_END_BOILERPLATE "}\n"
373
374 static bool run_test(const char *cmd, struct test *test)
375 {
376         char *output;
377         FILE *outf;
378         int status;
379
380         if (test->done)
381                 return test->answer;
382
383         if (test->depends) {
384                 size_t len;
385                 const char *deps = test->depends;
386                 char *dep;
387
388                 /* Space-separated dependencies, could be ! for inverse. */
389                 while ((len = strcspn(deps, " "))) {
390                         bool positive = true;
391                         if (deps[len]) {
392                                 dep = strdup(deps);
393                                 dep[len] = '\0';
394                         } else {
395                                 dep = (char *)deps;
396                         }
397
398                         if (dep[0] == '!') {
399                                 dep++;
400                                 positive = false;
401                         }
402                         if (run_test(cmd, find_test(dep)) != positive) {
403                                 test->answer = false;
404                                 test->done = true;
405                                 return test->answer;
406                         }
407                         deps += len;
408                         deps += strspn(deps, " ");
409                 }
410         }
411
412         outf = fopen(INPUT_FILE, "w");
413         if (!outf)
414                 err(1, "creating %s", INPUT_FILE);
415
416         fprintf(outf, "%s", PRE_BOILERPLATE);
417         switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) {
418         case INSIDE_MAIN:
419                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
420                 fprintf(outf, "%s", test->fragment);
421                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
422                 break;
423         case OUTSIDE_MAIN:
424                 fprintf(outf, "%s", test->fragment);
425                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
426                 fprintf(outf, "%s", MAIN_BODY_BOILERPLATE);
427                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
428                 break;
429         case DEFINES_FUNC:
430                 fprintf(outf, "%s", test->fragment);
431                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
432                 fprintf(outf, "%s", USE_FUNC_BOILERPLATE);
433                 fprintf(outf, "%s", MAIN_BODY_BOILERPLATE);
434                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
435                 break;
436         case DEFINES_EVERYTHING:
437                 fprintf(outf, "%s", test->fragment);
438                 break;
439         default:
440                 abort();
441
442         }
443         fclose(outf);
444
445         if (verbose > 1)
446                 if (system("cat " INPUT_FILE) == -1);
447
448         if (test->link) {
449                 char *newcmd;
450                 newcmd = malloc(strlen(cmd) + strlen(" ")
451                                 + strlen(test->link) + 1);
452                 sprintf(newcmd, "%s %s", cmd, test->link);
453                 if (verbose > 1)
454                         printf("Extra link line: %s", newcmd);
455                 cmd = newcmd;
456         }
457
458         output = run(cmd, &status);
459         if (status != 0 || strstr(output, "warning")) {
460                 if (verbose)
461                         printf("Compile %s for %s, status %i: %s\n",
462                                status ? "fail" : "warning",
463                                test->name, status, output);
464                 if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE))
465                         errx(1, "Test for %s did not compile:\n%s",
466                              test->name, output);
467                 test->answer = false;
468                 free(output);
469         } else {
470                 /* Compile succeeded. */
471                 free(output);
472                 /* We run INSIDE_MAIN tests for sanity checking. */
473                 if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
474                         output = run("./" OUTPUT_FILE, &status);
475                         if (!(test->style & EXECUTE) && status != 0)
476                                 errx(1, "Test for %s failed with %i:\n%s",
477                                      test->name, status, output);
478                         if (verbose && status)
479                                 printf("%s exited %i\n", test->name, status);
480                         free(output);
481                 }
482                 test->answer = (status == 0);
483         }
484         test->done = true;
485
486         if (test->answer && test->overrides) {
487                 struct test *override = find_test(test->overrides);
488                 override->done = true;
489                 override->answer = true;
490         }
491         return test->answer;
492 }
493
494 int main(int argc, const char *argv[])
495 {
496         char *cmd;
497         unsigned int i;
498         const char *default_args[]
499                 = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
500
501         if (argc > 1) {
502                 if (strcmp(argv[1], "--help") == 0) {
503                         printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
504                                "  <compiler> <flags> will have \"-o <outfile> <infile.c>\" appended\n"
505                                "Default: %s %s\n",
506                                DEFAULT_COMPILER, DEFAULT_FLAGS);
507                         exit(0);
508                 }
509                 if (strcmp(argv[1], "-v") == 0) {
510                         argc--;
511                         argv++;
512                         verbose = 1;
513                 } else if (strcmp(argv[1], "-vv") == 0) {
514                         argc--;
515                         argv++;
516                         verbose = 2;
517                 }
518         }
519
520         if (argc == 1)
521                 argv = default_args;
522
523         cmd = connect_args(argv, " -o " OUTPUT_FILE " " INPUT_FILE);
524         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
525                 run_test(cmd, &tests[i]);
526
527         unlink(OUTPUT_FILE);
528         unlink(INPUT_FILE);
529
530         printf("/* Generated by CCAN configurator */\n"
531                "#ifndef CCAN_CONFIG_H\n"
532                "#define CCAN_CONFIG_H\n");
533         printf("#ifndef _GNU_SOURCE\n");
534         printf("#define _GNU_SOURCE /* Always use GNU extensions. */\n");
535         printf("#endif\n");
536         printf("#define CCAN_COMPILER \"%s\"\n", argv[1]);
537         printf("#define CCAN_CFLAGS \"%s\"\n\n", connect_args(argv+1, ""));
538         /* This one implies "#include <ccan/..." works, eg. for tdb2.h */
539         printf("#define HAVE_CCAN 1\n");
540         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
541                 printf("#define %s %u\n", tests[i].name, tests[i].answer);
542         printf("#endif /* CCAN_CONFIG_H */\n");
543         return 0;
544 }