]> git.ozlabs.org Git - ccan/commitdiff
tools/configurator: support --var-file for outputting VAR=VAL format.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 12 Jun 2018 02:30:51 +0000 (12:00 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 12 Jun 2018 02:30:51 +0000 (12:00 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/configurator/configurator.c

index b8cb6f7a7cd4c42f2fd9701bd1d84a71ceba2ee0..bc55de5992e10cf2ea749a30be500b27ca3f749d 100644 (file)
@@ -684,13 +684,14 @@ int main(int argc, const char *argv[])
        const char *outflag = DEFAULT_OUTPUT_EXE_FLAG;
        const char *configurator_cc = NULL;
        const char *orig_cc;
+       const char *varfile = NULL;
 
        if (argc > 0)
                progname = argv[0];
 
        while (argc > 1) {
                if (strcmp(argv[1], "--help") == 0) {
-                       printf("Usage: configurator [-v] [-O<outflag>] [--configurator-cc=<compiler-for-tests>] [<compiler> <flags>...]\n"
+                       printf("Usage: configurator [-v] [--var-file=<filename>] [-O<outflag>] [--configurator-cc=<compiler-for-tests>] [<compiler> <flags>...]\n"
                               "  <compiler> <flags> will have \"<outflag> <outfile> <infile.c>\" appended\n"
                               "Default: %s %s %s\n",
                               DEFAULT_COMPILER, DEFAULT_FLAGS,
@@ -719,6 +720,10 @@ int main(int argc, const char *argv[])
                        configurator_cc = argv[1] + 18;
                        argc--;
                        argv++;
+               } else if (strncmp(argv[1], "--var-file=", 11) == 0) {
+                       varfile = argv[1] + 11;
+                       argc--;
+                       argv++;
                } else {
                        break;
                }
@@ -739,6 +744,24 @@ int main(int argc, const char *argv[])
        remove(OUTPUT_FILE);
        remove(INPUT_FILE);
 
+       if (varfile) {
+               FILE *vars;
+
+               if (strcmp(varfile, "-") == 0)
+                       vars = stdout;
+               else {
+                       vars = fopen(varfile, "a");
+                       if (!vars)
+                               c12r_err(2, "Could not open %s", varfile);
+               }
+               for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+                       fprintf(vars, "%s=%u\n", tests[i].name, tests[i].answer);
+               if (vars != stdout) {
+                       if (fclose(vars) != 0)
+                               c12r_err(2, "Closing %s", varfile);
+               }
+       }
+
        printf("/* Generated by CCAN configurator */\n"
               "#ifndef CCAN_CONFIG_H\n"
               "#define CCAN_CONFIG_H\n");