Commit 1239aa28 authored by Rusty Russell's avatar Rusty Russell

tools/configurator: support --header-file if we don't want to write to stdout.

Works well with --autotools-style.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 5cd7a0ea
......@@ -703,6 +703,8 @@ int main(int argc, const char *argv[])
const char *configurator_cc = NULL;
const char *orig_cc;
const char *varfile = NULL;
const char *headerfile = NULL;
FILE *outf;
if (argc > 0)
progname = argv[0];
......@@ -746,6 +748,10 @@ int main(int argc, const char *argv[])
like_a_libtool = true;
argc--;
argv++;
} else if (strncmp(argv[1], "--header-file=", 14) == 0) {
headerfile = argv[1] + 14;
argc--;
argv++;
} else {
break;
}
......@@ -791,21 +797,36 @@ int main(int argc, const char *argv[])
}
}
printf("/* Generated by CCAN configurator */\n"
if (headerfile) {
start_test("Writing header to ", headerfile);
outf = fopen(headerfile, "w");
if (!outf)
c12r_err(2, "Could not open %s", headerfile);
} else
outf = stdout;
fprintf(outf, "/* Generated by CCAN configurator */\n"
"#ifndef CCAN_CONFIG_H\n"
"#define CCAN_CONFIG_H\n");
printf("#ifndef _GNU_SOURCE\n");
printf("#define _GNU_SOURCE /* Always use GNU extensions. */\n");
printf("#endif\n");
printf("#define CCAN_COMPILER \"%s\"\n", orig_cc);
fprintf(outf, "#ifndef _GNU_SOURCE\n");
fprintf(outf, "#define _GNU_SOURCE /* Always use GNU extensions. */\n");
fprintf(outf, "#endif\n");
fprintf(outf, "#define CCAN_COMPILER \"%s\"\n", orig_cc);
cmd = connect_args(argv + 1, "", "");
printf("#define CCAN_CFLAGS \"%s\"\n", cmd);
fprintf(outf, "#define CCAN_CFLAGS \"%s\"\n", cmd);
free(cmd);
printf("#define CCAN_OUTPUT_EXE_CFLAG \"%s\"\n\n", outflag);
fprintf(outf, "#define CCAN_OUTPUT_EXE_CFLAG \"%s\"\n\n", outflag);
/* This one implies "#include <ccan/..." works, eg. for tdb2.h */
printf("#define HAVE_CCAN 1\n");
fprintf(outf, "#define HAVE_CCAN 1\n");
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
printf("#define %s %u\n", tests[i].name, tests[i].answer);
printf("#endif /* CCAN_CONFIG_H */\n");
fprintf(outf, "#define %s %u\n", tests[i].name, tests[i].answer);
fprintf(outf, "#endif /* CCAN_CONFIG_H */\n");
if (headerfile) {
if (fclose(outf) != 0)
c12r_err(2, "Closing %s", headerfile);
end_test(1);
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment