]> git.ozlabs.org Git - ccan/blob - tools/configurator/configurator.c
compiler: Add PURE_FUNCTION
[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         bool done;
59         bool answer;
60 };
61
62 static struct test tests[] = {
63         { "HAVE_32BIT_OFF_T", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
64           "#include <sys/types.h>\n"
65           "int main(int argc, char *argv[]) {\n"
66           "     return sizeof(off_t) == 4 ? 0 : 1;\n"
67           "}\n" },
68         { "HAVE_ALIGNOF", INSIDE_MAIN, NULL, NULL,
69           "return __alignof__(double) > 0 ? 0 : 1;" },
70         { "HAVE_ASPRINTF", DEFINES_FUNC, NULL, NULL,
71           "#define _GNU_SOURCE\n"
72           "#include <stdio.h>\n"
73           "static char *func(int x) {"
74           "     char *p;\n"
75           "     if (asprintf(&p, \"%u\", x) == -1) p = NULL;"
76           "     return p;\n"
77           "}" },
78         { "HAVE_ATTRIBUTE_COLD", DEFINES_FUNC, NULL, NULL,
79           "static int __attribute__((cold)) func(int x) { return x; }" },
80         { "HAVE_ATTRIBUTE_CONST", DEFINES_FUNC, NULL, NULL,
81           "static int __attribute__((const)) func(int x) { return x; }" },
82         { "HAVE_ATTRIBUTE_PURE", DEFINES_FUNC, NULL, NULL,
83           "static int __attribute__((pure)) func(int x) { return x; }" },
84         { "HAVE_ATTRIBUTE_MAY_ALIAS", OUTSIDE_MAIN, NULL, NULL,
85           "typedef short __attribute__((__may_alias__)) short_a;" },
86         { "HAVE_ATTRIBUTE_NORETURN", DEFINES_FUNC, NULL, NULL,
87           "#include <stdlib.h>\n"
88           "static void __attribute__((noreturn)) func(int x) { exit(x); }" },
89         { "HAVE_ATTRIBUTE_PRINTF", DEFINES_FUNC, NULL, NULL,
90           "static void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }" },
91         { "HAVE_ATTRIBUTE_UNUSED", OUTSIDE_MAIN, NULL, NULL,
92           "static int __attribute__((unused)) func(int x) { return x; }" },
93         { "HAVE_ATTRIBUTE_USED", OUTSIDE_MAIN, NULL, NULL,
94           "static int __attribute__((used)) func(int x) { return x; }" },
95         { "HAVE_BACKTRACE", DEFINES_FUNC, NULL, NULL,
96           "#include <execinfo.h>\n"
97           "static int func(int x) {"
98           "     void *bt[10];\n"
99           "     return backtrace(bt, 10) < x;\n"
100           "}" },
101         { "HAVE_BIG_ENDIAN", INSIDE_MAIN|EXECUTE, NULL, NULL,
102           "union { int i; char c[sizeof(int)]; } u;\n"
103           "u.i = 0x01020304;\n"
104           "return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;" },
105         { "HAVE_BSWAP_64", DEFINES_FUNC, "HAVE_BYTESWAP_H", NULL,
106           "#include <byteswap.h>\n"
107           "static int func(int x) { return bswap_64(x); }" },
108         { "HAVE_BUILTIN_CHOOSE_EXPR", INSIDE_MAIN, NULL, NULL,
109           "return __builtin_choose_expr(1, 0, \"garbage\");" },
110         { "HAVE_BUILTIN_CLZ", INSIDE_MAIN, NULL, NULL,
111           "return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;" },
112         { "HAVE_BUILTIN_CLZL", INSIDE_MAIN, NULL, NULL,
113           "return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;" },
114         { "HAVE_BUILTIN_CLZLL", INSIDE_MAIN, NULL, NULL,
115           "return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;" },
116         { "HAVE_BUILTIN_CONSTANT_P", INSIDE_MAIN, NULL, NULL,
117           "return __builtin_constant_p(1) ? 0 : 1;" },
118         { "HAVE_BUILTIN_EXPECT", INSIDE_MAIN, NULL, NULL,
119           "return __builtin_expect(argc == 1, 1) ? 0 : 1;" },
120         { "HAVE_BUILTIN_FFSL", INSIDE_MAIN, NULL, NULL,
121           "return __builtin_ffsl(0L) == 0 ? 0 : 1;" },
122         { "HAVE_BUILTIN_FFSLL", INSIDE_MAIN, NULL, NULL,
123           "return __builtin_ffsll(0LL) == 0 ? 0 : 1;" },
124         { "HAVE_BUILTIN_POPCOUNTL", INSIDE_MAIN, NULL, NULL,
125           "return __builtin_popcountl(255L) == 8 ? 0 : 1;" },
126         { "HAVE_BUILTIN_TYPES_COMPATIBLE_P", INSIDE_MAIN, NULL, NULL,
127           "return __builtin_types_compatible_p(char *, int) ? 1 : 0;" },
128         { "HAVE_BYTESWAP_H", OUTSIDE_MAIN, NULL, NULL,
129           "#include <byteswap.h>\n" },
130         { "HAVE_CLOCK_GETTIME",
131           DEFINES_FUNC, "HAVE_STRUCT_TIMESPEC", NULL,
132           "#include <time.h>\n"
133           "static struct timespec func(void) {\n"
134           "     struct timespec ts;\n"
135           "     clock_gettime(CLOCK_REALTIME, &ts);\n"
136           "     return ts;\n"
137           "}\n" },
138         { "HAVE_CLOCK_GETTIME_IN_LIBRT",
139           DEFINES_FUNC,
140           "HAVE_STRUCT_TIMESPEC !HAVE_CLOCK_GETTIME",
141           "-lrt",
142           "#include <time.h>\n"
143           "static struct timespec func(void) {\n"
144           "     struct timespec ts;\n"
145           "     clock_gettime(CLOCK_REALTIME, &ts);\n"
146           "     return ts;\n"
147           "}\n" },
148         { "HAVE_COMPOUND_LITERALS", INSIDE_MAIN, NULL, NULL,
149           "int *foo = (int[]) { 1, 2, 3, 4 };\n"
150           "return foo[0] ? 0 : 1;" },
151         { "HAVE_FCHDIR", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
152           "#include <sys/types.h>\n"
153           "#include <sys/stat.h>\n"
154           "#include <fcntl.h>\n"
155           "#include <unistd.h>\n"
156           "int main(void) {\n"
157           "     int fd = open(\"..\", O_RDONLY);\n"
158           "     return fchdir(fd) == 0 ? 0 : 1;\n"
159           "}\n" },
160         { "HAVE_ERR_H", DEFINES_FUNC, NULL, NULL,
161           "#include <err.h>\n"
162           "static void func(int arg) {\n"
163           "     if (arg == 0)\n"
164           "             err(1, \"err %u\", arg);\n"
165           "     if (arg == 1)\n"
166           "             errx(1, \"err %u\", arg);\n"
167           "     if (arg == 3)\n"
168           "             warn(\"warn %u\", arg);\n"
169           "     if (arg == 4)\n"
170           "             warnx(\"warn %u\", arg);\n"
171           "}\n" },
172         { "HAVE_FILE_OFFSET_BITS", DEFINES_EVERYTHING|EXECUTE,
173           "HAVE_32BIT_OFF_T", NULL,
174           "#define _FILE_OFFSET_BITS 64\n"
175           "#include <sys/types.h>\n"
176           "int main(int argc, char *argv[]) {\n"
177           "     return sizeof(off_t) == 8 ? 0 : 1;\n"
178           "}\n" },
179         { "HAVE_FOR_LOOP_DECLARATION", INSIDE_MAIN, NULL, NULL,
180           "for (int i = 0; i < argc; i++) { return 0; };\n"
181           "return 1;" },
182         { "HAVE_FLEXIBLE_ARRAY_MEMBER", OUTSIDE_MAIN, NULL, NULL,
183           "struct foo { unsigned int x; int arr[]; };" },
184         { "HAVE_GETPAGESIZE", DEFINES_FUNC, NULL, NULL,
185           "#include <unistd.h>\n"
186           "static int func(void) { return getpagesize(); }" },
187         { "HAVE_ISBLANK", DEFINES_FUNC, NULL, NULL,
188           "#define _GNU_SOURCE\n"
189           "#include <ctype.h>\n"
190           "static int func(void) { return isblank(' '); }" },
191         { "HAVE_LITTLE_ENDIAN", INSIDE_MAIN|EXECUTE, NULL, NULL,
192           "union { int i; char c[sizeof(int)]; } u;\n"
193           "u.i = 0x01020304;\n"
194           "return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;" },
195         { "HAVE_MEMMEM", DEFINES_FUNC, NULL, NULL,
196           "#define _GNU_SOURCE\n"
197           "#include <string.h>\n"
198           "static void *func(void *h, size_t hl, void *n, size_t nl) {\n"
199           "return memmem(h, hl, n, nl);"
200           "}\n", },
201         { "HAVE_MMAP", DEFINES_FUNC, NULL, NULL,
202           "#include <sys/mman.h>\n"
203           "static void *func(int fd) {\n"
204           "     return mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);\n"
205           "}" },
206         { "HAVE_PROC_SELF_MAPS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
207           "#include <sys/types.h>\n"
208           "#include <sys/stat.h>\n"
209           "#include <fcntl.h>\n"
210           "int main(void) {\n"
211           "     return open(\"/proc/self/maps\", O_RDONLY) != -1 ? 0 : 1;\n"
212           "}\n" },
213         { "HAVE_QSORT_R_PRIVATE_LAST",
214           DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE, NULL, NULL,
215           "#define _GNU_SOURCE 1\n"
216           "#include <stdlib.h>\n"
217           "static int cmp(const void *lp, const void *rp, void *priv) {\n"
218           " *(unsigned int *)priv = 1;\n"
219           " return *(const int *)lp - *(const int *)rp; }\n"
220           "int main(void) {\n"
221           " int array[] = { 9, 2, 5 };\n"
222           " unsigned int called = 0;\n"
223           " qsort_r(array, 3, sizeof(int), cmp, &called);\n"
224           " return called && array[0] == 2 && array[1] == 5 && array[2] == 9 ? 0 : 1;\n"
225           "}\n" },
226         { "HAVE_STRUCT_TIMESPEC",
227           DEFINES_FUNC, NULL, NULL,
228           "#include <time.h>\n"
229           "static void func(void) {\n"
230           "     struct timespec ts;\n"
231           "     ts.tv_sec = ts.tv_nsec = 1;\n"
232           "}\n" },
233         { "HAVE_SECTION_START_STOP",
234           DEFINES_FUNC, NULL, NULL,
235           "static void *__attribute__((__section__(\"mysec\"))) p = &p;\n"
236           "static int func(void) {\n"
237           "     extern void *__start_mysec[], *__stop_mysec[];\n"
238           "     return __stop_mysec - __start_mysec;\n"
239           "}\n" },
240         { "HAVE_STACK_GROWS_UPWARDS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL,
241           "static long nest(const void *base, unsigned int i)\n"
242           "{\n"
243           "     if (i == 0)\n"
244           "             return (const char *)&i - (const char *)base;\n"
245           "     return nest(base, i-1);\n"
246           "}\n"
247           "int main(int argc, char *argv[]) {\n"
248           "     return (nest(&argc, argc) > 0) ? 0 : 1\n;"
249           "}\n" },
250         { "HAVE_STATEMENT_EXPR", INSIDE_MAIN, NULL, NULL,
251           "return ({ int x = argc; x == argc ? 0 : 1; });" },
252         { "HAVE_SYS_FILIO_H", OUTSIDE_MAIN, NULL, NULL, /* Solaris needs this for FIONREAD */
253           "#include <sys/filio.h>\n" },
254         { "HAVE_SYS_TERMIOS_H", OUTSIDE_MAIN, NULL, NULL,
255           "#include <sys/termios.h>\n" },
256         { "HAVE_TYPEOF", INSIDE_MAIN, NULL, NULL,
257           "__typeof__(argc) i; i = argc; return i == argc ? 0 : 1;" },
258         { "HAVE_UTIME", DEFINES_FUNC, NULL, NULL,
259           "#include <sys/types.h>\n"
260           "#include <utime.h>\n"
261           "static int func(const char *filename) {\n"
262           "     struct utimbuf times = { 0 };\n"
263           "     return utime(filename, &times);\n"
264           "}" },
265         { "HAVE_WARN_UNUSED_RESULT", DEFINES_FUNC, NULL, NULL,
266           "#include <sys/types.h>\n"
267           "#include <utime.h>\n"
268           "static __attribute__((warn_unused_result)) int func(int i) {\n"
269           "     return i + 1;\n"
270           "}" },
271 };
272
273 static char *grab_fd(int fd)
274 {
275         int ret;
276         size_t max, size = 0;
277         char *buffer;
278
279         max = 16384;
280         buffer = malloc(max+1);
281         while ((ret = read(fd, buffer + size, max - size)) > 0) {
282                 size += ret;
283                 if (size == max)
284                         buffer = realloc(buffer, max *= 2);
285         }
286         if (ret < 0)
287                 err(1, "reading from command");
288         buffer[size] = '\0';
289         return buffer;
290 }
291
292 static char *run(const char *cmd, int *exitstatus)
293 {
294         pid_t pid;
295         int p[2];
296         char *ret;
297         int status;
298
299         if (pipe(p) != 0)
300                 err(1, "creating pipe");
301
302         pid = fork();
303         if (pid == -1)
304                 err(1, "forking");
305
306         if (pid == 0) {
307                 if (dup2(p[1], STDOUT_FILENO) != STDOUT_FILENO
308                     || dup2(p[1], STDERR_FILENO) != STDERR_FILENO
309                     || close(p[0]) != 0
310                     || close(STDIN_FILENO) != 0
311                     || open("/dev/null", O_RDONLY) != STDIN_FILENO)
312                         exit(128);
313
314                 status = system(cmd);
315                 if (WIFEXITED(status))
316                         exit(WEXITSTATUS(status));
317                 /* Here's a hint... */
318                 exit(128 + WTERMSIG(status));
319         }
320
321         close(p[1]);
322         ret = grab_fd(p[0]);
323         /* This shouldn't fail... */
324         if (waitpid(pid, &status, 0) != pid)
325                 err(1, "Failed to wait for child");
326         close(p[0]);
327         if (WIFEXITED(status))
328                 *exitstatus = WEXITSTATUS(status);
329         else
330                 *exitstatus = -WTERMSIG(status);
331         return ret;
332 }
333
334 static char *connect_args(const char *argv[], const char *extra)
335 {
336         unsigned int i, len = strlen(extra) + 1;
337         char *ret;
338
339         for (i = 1; argv[i]; i++)
340                 len += 1 + strlen(argv[i]);
341
342         ret = malloc(len);
343         len = 0;
344         for (i = 1; argv[i]; i++) {
345                 strcpy(ret + len, argv[i]);
346                 len += strlen(argv[i]);
347                 if (argv[i+1])
348                         ret[len++] = ' ';
349         }
350         strcpy(ret + len, extra);
351         return ret;
352 }
353
354 static struct test *find_test(const char *name)
355 {
356         unsigned int i;
357
358         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
359                 if (strcmp(tests[i].name, name) == 0)
360                         return &tests[i];
361         }
362         abort();
363 }
364
365 #define PRE_BOILERPLATE "/* Test program generated by configurator. */\n"
366 #define MAIN_START_BOILERPLATE "int main(int argc, char *argv[]) {\n"
367 #define USE_FUNC_BOILERPLATE "(void)func;\n"
368 #define MAIN_BODY_BOILERPLATE "return 0;\n"
369 #define MAIN_END_BOILERPLATE "}\n"
370
371 static bool run_test(const char *cmd, struct test *test)
372 {
373         char *output;
374         FILE *outf;
375         int status;
376
377         if (test->done)
378                 return test->answer;
379
380         if (test->depends) {
381                 size_t len;
382                 const char *deps = test->depends;
383                 char *dep;
384
385                 /* Space-separated dependencies, could be ! for inverse. */
386                 while ((len = strcspn(deps, " "))) {
387                         bool positive = true;
388                         if (deps[len]) {
389                                 dep = strdup(deps);
390                                 dep[len] = '\0';
391                         } else {
392                                 dep = (char *)deps;
393                         }
394
395                         if (dep[0] == '!') {
396                                 dep++;
397                                 positive = false;
398                         }
399                         if (run_test(cmd, find_test(dep)) != positive) {
400                                 test->answer = false;
401                                 test->done = true;
402                                 return test->answer;
403                         }
404                         deps += len;
405                         deps += strspn(deps, " ");
406                 }
407         }
408
409         outf = fopen(INPUT_FILE, "w");
410         if (!outf)
411                 err(1, "creating %s", INPUT_FILE);
412
413         fprintf(outf, "%s", PRE_BOILERPLATE);
414         switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) {
415         case INSIDE_MAIN:
416                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
417                 fprintf(outf, "%s", test->fragment);
418                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
419                 break;
420         case OUTSIDE_MAIN:
421                 fprintf(outf, "%s", test->fragment);
422                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
423                 fprintf(outf, "%s", MAIN_BODY_BOILERPLATE);
424                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
425                 break;
426         case DEFINES_FUNC:
427                 fprintf(outf, "%s", test->fragment);
428                 fprintf(outf, "%s", MAIN_START_BOILERPLATE);
429                 fprintf(outf, "%s", USE_FUNC_BOILERPLATE);
430                 fprintf(outf, "%s", MAIN_BODY_BOILERPLATE);
431                 fprintf(outf, "%s", MAIN_END_BOILERPLATE);
432                 break;
433         case DEFINES_EVERYTHING:
434                 fprintf(outf, "%s", test->fragment);
435                 break;
436         default:
437                 abort();
438
439         }
440         fclose(outf);
441
442         if (verbose > 1)
443                 if (system("cat " INPUT_FILE) == -1);
444
445         if (test->link) {
446                 char *newcmd;
447                 newcmd = malloc(strlen(cmd) + strlen(" ")
448                                 + strlen(test->link) + 1);
449                 sprintf(newcmd, "%s %s", cmd, test->link);
450                 if (verbose > 1)
451                         printf("Extra link line: %s", newcmd);
452                 cmd = newcmd;
453         }
454
455         output = run(cmd, &status);
456         if (status != 0 || strstr(output, "warning")) {
457                 if (verbose)
458                         printf("Compile %s for %s, status %i: %s\n",
459                                status ? "fail" : "warning",
460                                test->name, status, output);
461                 if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE))
462                         errx(1, "Test for %s did not compile:\n%s",
463                              test->name, output);
464                 test->answer = false;
465                 free(output);
466         } else {
467                 /* Compile succeeded. */
468                 free(output);
469                 /* We run INSIDE_MAIN tests for sanity checking. */
470                 if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) {
471                         output = run("./" OUTPUT_FILE, &status);
472                         if (!(test->style & EXECUTE) && status != 0)
473                                 errx(1, "Test for %s failed with %i:\n%s",
474                                      test->name, status, output);
475                         if (verbose && status)
476                                 printf("%s exited %i\n", test->name, status);
477                         free(output);
478                 }
479                 test->answer = (status == 0);
480         }
481         test->done = true;
482         return test->answer;
483 }
484
485 int main(int argc, const char *argv[])
486 {
487         char *cmd;
488         unsigned int i;
489         const char *default_args[]
490                 = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL };
491
492         if (argc > 1) {
493                 if (strcmp(argv[1], "--help") == 0) {
494                         printf("Usage: configurator [-v] [<compiler> <flags>...]\n"
495                                "  <compiler> <flags> will have \"-o <outfile> <infile.c>\" appended\n"
496                                "Default: %s %s\n",
497                                DEFAULT_COMPILER, DEFAULT_FLAGS);
498                         exit(0);
499                 }
500                 if (strcmp(argv[1], "-v") == 0) {
501                         argc--;
502                         argv++;
503                         verbose = 1;
504                 } else if (strcmp(argv[1], "-vv") == 0) {
505                         argc--;
506                         argv++;
507                         verbose = 2;
508                 }
509         }
510
511         if (argc == 1)
512                 argv = default_args;
513
514         cmd = connect_args(argv, " -o " OUTPUT_FILE " " INPUT_FILE);
515         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
516                 run_test(cmd, &tests[i]);
517
518         unlink(OUTPUT_FILE);
519         unlink(INPUT_FILE);
520
521         printf("/* Generated by CCAN configurator */\n"
522                "#ifndef CCAN_CONFIG_H\n"
523                "#define CCAN_CONFIG_H\n");
524         printf("#ifndef _GNU_SOURCE\n");
525         printf("#define _GNU_SOURCE /* Always use GNU extensions. */\n");
526         printf("#endif\n");
527         printf("#define CCAN_COMPILER \"%s\"\n", argv[1]);
528         printf("#define CCAN_CFLAGS \"%s\"\n\n", connect_args(argv+1, ""));
529         /* This one implies "#include <ccan/..." works, eg. for tdb2.h */
530         printf("#define HAVE_CCAN 1\n");
531         for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
532                 printf("#define %s %u\n", tests[i].name, tests[i].answer);
533         printf("#endif /* CCAN_CONFIG_H */\n");
534         return 0;
535 }