Regenerate charmonizer.c
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/55d99f5e Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/55d99f5e Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/55d99f5e Branch: refs/heads/thread_safe_errors Commit: 55d99f5e2b0ee1b8ec25a7c0d6925eee524f9f65 Parents: f1f316e Author: Nick Wellnhofer <[email protected]> Authored: Thu Dec 4 21:54:58 2014 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Thu Dec 4 21:56:18 2014 +0100 ---------------------------------------------------------------------- compiler/common/charmonizer.c | 18 ++++++++++ runtime/common/charmonizer.c | 69 +++++++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55d99f5e/compiler/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/compiler/common/charmonizer.c b/compiler/common/charmonizer.c index 2a24d21..0d295c2 100644 --- a/compiler/common/charmonizer.c +++ b/compiler/common/charmonizer.c @@ -301,6 +301,12 @@ chaz_CC_compile_obj(const char *source_path, const char *obj_path, int chaz_CC_test_compile(const char *source); +/* Attempt to compile and link the supplied source code and return true if + * the effort succeeds. + */ +int +chaz_CC_test_link(const char *source); + /* Attempt to compile the supplied source code. If successful, capture the * output of the program and return a pointer to a newly allocated buffer. * If the compilation fails, return NULL. The length of the captured @@ -2793,6 +2799,18 @@ chaz_CC_test_compile(const char *source) { return compile_succeeded; } +int +chaz_CC_test_link(const char *source) { + int link_succeeded; + if (!chaz_Util_remove_and_verify(chaz_CC.try_exe_name)) { + chaz_Util_die("Failed to delete file '%s'", chaz_CC.try_exe_name); + } + link_succeeded = chaz_CC_compile_exe(CHAZ_CC_TRY_SOURCE_PATH, + CHAZ_CC_TRY_BASENAME, source); + chaz_Util_remove_and_verify(chaz_CC.try_exe_name); + return link_succeeded; +} + char* chaz_CC_capture_output(const char *source, size_t *output_len) { char *captured_output = NULL; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/55d99f5e/runtime/common/charmonizer.c ---------------------------------------------------------------------- diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c index 133494b..1d0fe07 100644 --- a/runtime/common/charmonizer.c +++ b/runtime/common/charmonizer.c @@ -301,6 +301,12 @@ chaz_CC_compile_obj(const char *source_path, const char *obj_path, int chaz_CC_test_compile(const char *source); +/* Attempt to compile and link the supplied source code and return true if + * the effort succeeds. + */ +int +chaz_CC_test_link(const char *source); + /* Attempt to compile the supplied source code. If successful, capture the * output of the program and return a pointer to a newly allocated buffer. * If the compilation fails, return NULL. The length of the captured @@ -2793,6 +2799,18 @@ chaz_CC_test_compile(const char *source) { return compile_succeeded; } +int +chaz_CC_test_link(const char *source) { + int link_succeeded; + if (!chaz_Util_remove_and_verify(chaz_CC.try_exe_name)) { + chaz_Util_die("Failed to delete file '%s'", chaz_CC.try_exe_name); + } + link_succeeded = chaz_CC_compile_exe(CHAZ_CC_TRY_SOURCE_PATH, + CHAZ_CC_TRY_BASENAME, source); + chaz_Util_remove_and_verify(chaz_CC.try_exe_name); + return link_succeeded; +} + char* chaz_CC_capture_output(const char *source, size_t *output_len) { char *captured_output = NULL; @@ -7773,10 +7791,15 @@ 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 = chaz_CLI_new(argv[0], "charmonizer: Probe C build environment"); + chaz_CLI_register(cli, "host", "specify host binding language", + CHAZ_CLI_ARG_REQUIRED); chaz_CLI_register(cli, "disable-threads", "whether to disable threads", CHAZ_CLI_NO_ARG); chaz_CLI_set_usage(cli, "Usage: charmonizer [OPTIONS] [-- [CFLAGS]]"); @@ -7865,7 +7888,7 @@ S_add_compiler_flags(struct chaz_CLI *cli) { else if (getenv("LUCY_DEBUG")) { chaz_CFlags_append(extra_cflags, "-DLUCY_DEBUG -pedantic -Wall -Wextra -Wno-variadic-macros"); - if (chaz_CLI_defined(cli, "enable-perl")) { + if (strcmp(chaz_CLI_strval(cli, "host"), "perl") == 0) { chaz_CFlags_append(extra_cflags, "-DPERL_GCC_PEDANTIC"); } } @@ -7915,7 +7938,7 @@ cfish_MakeFile_new(chaz_CLI *cli) { self->autogen_target = chaz_Util_join(dir_sep, "autogen", "hierarchy.json", NULL); - if (chaz_CLI_defined(cli, "enable-perl")) { + if (strcmp(chaz_CLI_strval(self->cli, "host"), "perl") == 0) { static const char *perl_autogen_src_files[] = { "boot", "callbacks", @@ -8035,7 +8058,7 @@ cfish_MakeFile_write(cfish_MakeFile *self) { chaz_MakeFile_add_rule(self->makefile, "all", scratch); free(scratch); - if (!chaz_CLI_defined(self->cli, "enable-perl")) { + if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) { cfish_MakeFile_write_c_cfc_rules(self); } @@ -8055,6 +8078,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); } @@ -8064,7 +8090,7 @@ cfish_MakeFile_write(cfish_MakeFile *self) { chaz_MakeFile_add_static_lib(self->makefile, self->static_lib, "$(CLOWNFISH_OBJS)"); - if (!chaz_CLI_defined(self->cli, "enable-perl")) { + if (strcmp(chaz_CLI_strval(self->cli, "host"), "c") == 0) { cfish_MakeFile_write_c_test_rules(self); } @@ -8230,4 +8256,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; +}
