Add probe for libpthread

Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/f1f316ed
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/f1f316ed
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/f1f316ed

Branch: refs/heads/thread_safe_errors
Commit: f1f316ed6717af8e5847f4b3f2747bd4a8e2517e
Parents: 8b939e5
Author: Nick Wellnhofer <[email protected]>
Authored: Thu Dec 4 21:54:03 2014 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Thu Dec 4 21:56:18 2014 +0100

----------------------------------------------------------------------
 runtime/common/charmonizer.main | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/f1f316ed/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main
index 30bdff2..207599a 100644
--- a/runtime/common/charmonizer.main
+++ b/runtime/common/charmonizer.main
@@ -93,6 +93,9 @@ S_cfh_file_callback(const char *dir, char *file, void 
*context);
 static int
 S_ends_with(const char *string, const char *postfix);
 
+static int
+S_need_libpthread(chaz_CLI *cli);
+
 int main(int argc, const char **argv) {
     /* Initialize. */
     chaz_CLI *cli
@@ -377,6 +380,9 @@ cfish_MakeFile_write(cfish_MakeFile *self) {
     if (math_library) {
         chaz_CFlags_add_external_library(link_flags, math_library);
     }
+    if (S_need_libpthread(self->cli)) {
+        chaz_CFlags_add_external_library(link_flags, "pthread");
+    }
     if (chaz_CLI_defined(self->cli, "enable-coverage")) {
         chaz_CFlags_enable_code_coverage(link_flags);
     }
@@ -552,4 +558,39 @@ S_ends_with(const char *string, const char *postfix) {
            && memcmp(string + len - postfix_len, postfix, postfix_len) == 0;
 }
 
+static int
+S_need_libpthread(chaz_CLI *cli) {
+    if (chaz_CLI_defined(cli, "disable-threads")
+        || strcmp(chaz_CLI_strval(cli, "host"), "c") != 0
+        || chaz_HeadCheck_check_header("windows.h")
+    ) {
+        return 0;
+    }
+
+    if (!chaz_HeadCheck_check_header("pthread.h")) {
+        chaz_Util_die("pthread.h not found. Try --disable-threads.");
+    }
+
+    static const char source[] =
+        "#include <pthread.h>\n"
+        "\n"
+        "int main() {\n"
+        "    pthread_key_t key;\n"
+        "    pthread_key_create(&key, NULL);\n"
+        "    return 0;\n"
+        "}\n";
+
+    if (chaz_CC_test_link(source)) {
+        return 0;
+    }
+
+    chaz_CFlags *temp_cflags = chaz_CC_get_temp_cflags();
+    chaz_CFlags_add_external_library(temp_cflags, "pthread");
+    if (!chaz_CC_test_link(source)) {
+        chaz_Util_die("Can't link with libpthread. Try --disable-threads.");
+    }
+    chaz_CFlags_clear(temp_cflags);
+
+    return 1;
+}
 

Reply via email to