]> git.ozlabs.org Git - ccan/commitdiff
configurator: Add OpenMP detection
authorAndrew Jeffery <andrew@aj.id.au>
Sat, 5 Sep 2015 14:09:59 +0000 (23:39 +0930)
committerAndrew Jeffery <andrew@aj.id.au>
Wed, 9 Sep 2015 14:17:24 +0000 (23:47 +0930)
tools/configurator/configurator.c

index fe1611e4b525312e8f5dbbccadaaa4eac56eb28d..2139bcb2059267e9ebfe098831ee25d94c85fe8f 100644 (file)
@@ -55,6 +55,7 @@ struct test {
        const char *depends;
        const char *link;
        const char *fragment;
        const char *depends;
        const char *link;
        const char *fragment;
+       const char *flags;
        const char *overrides; /* On success, force this to '1' */
        bool done;
        bool answer;
        const char *overrides; /* On success, force this to '1' */
        bool done;
        bool answer;
@@ -310,6 +311,12 @@ static struct test tests[] = {
          "static __attribute__((warn_unused_result)) int func(int i) {\n"
          "     return i + 1;\n"
          "}" },
          "static __attribute__((warn_unused_result)) int func(int i) {\n"
          "     return i + 1;\n"
          "}" },
+       { "HAVE_OPENMP", INSIDE_MAIN, NULL, NULL,
+         "int i;\n"
+         "#pragma omp parallel for\n"
+         "for(i = 0; i < 0; i++) {};\n"
+         "return 0;\n",
+         "-Werror -fopenmp" },
 };
 
 static char *grab_fd(int fd)
 };
 
 static char *grab_fd(int fd)
@@ -415,7 +422,7 @@ static struct test *find_test(const char *name)
 
 static bool run_test(const char *cmd, struct test *test)
 {
 
 static bool run_test(const char *cmd, struct test *test)
 {
-       char *output;
+       char *output, *newcmd;
        FILE *outf;
        int status;
 
        FILE *outf;
        int status;
 
@@ -490,17 +497,30 @@ static bool run_test(const char *cmd, struct test *test)
        if (verbose > 1)
                if (system("cat " INPUT_FILE) == -1);
 
        if (verbose > 1)
                if (system("cat " INPUT_FILE) == -1);
 
+       newcmd = strdup(cmd);
+
+       if (test->flags) {
+               newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ")
+                               + strlen(test->flags) + 1);
+               strcat(newcmd, " ");
+               strcat(newcmd, test->flags);
+               if (verbose > 1)
+                       printf("Extra flags line: %s", newcmd);
+       }
+
        if (test->link) {
        if (test->link) {
-               char *newcmd;
-               newcmd = malloc(strlen(cmd) + strlen(" ")
+               newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ")
                                + strlen(test->link) + 1);
                                + strlen(test->link) + 1);
-               sprintf(newcmd, "%s %s", cmd, test->link);
+               strcat(newcmd, " ");
+               strcat(newcmd, test->link);
                if (verbose > 1)
                        printf("Extra link line: %s", newcmd);
                if (verbose > 1)
                        printf("Extra link line: %s", newcmd);
-               cmd = newcmd;
        }
 
        }
 
-       output = run(cmd, &status);
+       output = run(newcmd, &status);
+
+       free(newcmd);
+
        if (status != 0 || strstr(output, "warning")) {
                if (verbose)
                        printf("Compile %s for %s, status %i: %s\n",
        if (status != 0 || strstr(output, "warning")) {
                if (verbose)
                        printf("Compile %s for %s, status %i: %s\n",