Repository: lucy-clownfish Updated Branches: refs/heads/master 0e2700939 -> ca15901d7
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/64c7bc2d Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/64c7bc2d Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/64c7bc2d Branch: refs/heads/master Commit: 64c7bc2d69e67c641bfee00367100c916fa46efa Parents: 0e27009 Author: Nick Wellnhofer <[email protected]> Authored: Thu Dec 4 21:54:03 2014 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sat Dec 27 16:01:02 2014 +0100 ---------------------------------------------------------------------- runtime/common/charmonizer.main | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/64c7bc2d/runtime/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main index 30bdff2..207b607 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,40 @@ 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) { + static const char source[] = + "#include <pthread.h>\n" + "\n" + "int main() {\n" + " pthread_create(0, 0, 0, 0);\n" + " pthread_key_create(0, 0);\n" + " return 0;\n" + "}\n"; + chaz_CFlags *temp_cflags; + + 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."); + } + + if (chaz_CC_test_link(source)) { + return 0; + } + + 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; +}
