Readd Cygwin detection Also add a new public function chaz_CC_has_macro.
Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/41d94077 Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/41d94077 Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/41d94077 Branch: refs/heads/master Commit: 41d940779ee7b022251fc422cff7132b80ef54f7 Parents: 76e4dbe Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Tue May 31 13:14:19 2016 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Thu Jun 2 00:04:17 2016 +0200 ---------------------------------------------------------------------- src/Charmonizer/Core/Compiler.c | 50 ++++++++++++++++++++++++++++-------- src/Charmonizer/Core/Compiler.h | 8 ++++++ src/Charmonizer/Core/Library.c | 15 +++++------ 3 files changed, 54 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/41d94077/src/Charmonizer/Core/Compiler.c ---------------------------------------------------------------------- diff --git a/src/Charmonizer/Core/Compiler.c b/src/Charmonizer/Core/Compiler.c index 1136d68..dd4fa6c 100644 --- a/src/Charmonizer/Core/Compiler.c +++ b/src/Charmonizer/Core/Compiler.c @@ -27,6 +27,11 @@ static void chaz_CC_detect_binary_format(const char *filename); +/** Return the numeric value of a macro or 0 if it isn't defined. + */ +static int +chaz_CC_eval_macro(const char *macro); + /* Detect macros which may help to identify some compilers. */ static void @@ -56,12 +61,13 @@ static struct { int intval__MSC_VER; int intval___clang__; int intval___SUNPRO_C; + int is_cygwin; chaz_CFlags *extra_cflags; chaz_CFlags *temp_cflags; } chaz_CC = { NULL, NULL, NULL, "", "", "", "", "", "", - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL }; @@ -167,6 +173,10 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags) { strcpy(chaz_CC.import_lib_ext, ".lib"); strcpy(chaz_CC.obj_ext, ".obj"); } + + if (chaz_CC_has_macro("__CYGWIN__")) { + chaz_CC.is_cygwin = 1; + } } else { chaz_Util_die("Failed to detect binary format"); @@ -224,7 +234,7 @@ chaz_CC_detect_binary_format(const char *filename) { free(output); } -static const char chaz_CC_detect_macro_code[] = +static const char chaz_CC_eval_macro_code[] = CHAZ_QUOTE( #include <stdio.h> ) CHAZ_QUOTE( int main() { ) CHAZ_QUOTE( #ifndef %s ) @@ -235,15 +245,15 @@ static const char chaz_CC_detect_macro_code[] = CHAZ_QUOTE( } ); static int -chaz_CC_detect_macro(const char *macro) { - size_t size = sizeof(chaz_CC_detect_macro_code) +chaz_CC_eval_macro(const char *macro) { + size_t size = sizeof(chaz_CC_eval_macro_code) + (strlen(macro) * 2) + 20; char *code = (char*)malloc(size); int retval = 0; char *output; size_t len; - sprintf(code, chaz_CC_detect_macro_code, macro, macro); + sprintf(code, chaz_CC_eval_macro_code, macro, macro); output = chaz_CC_capture_output(code, &len); if (output) { retval = atoi(output); @@ -253,21 +263,34 @@ chaz_CC_detect_macro(const char *macro) { return retval; } +int +chaz_CC_has_macro(const char *macro) { + size_t size = sizeof(chaz_CC_eval_macro_code) + + (strlen(macro) * 2) + + 20; + char *code = (char*)malloc(size); + int retval = 0; + sprintf(code, chaz_CC_eval_macro_code, macro, macro); + retval = chaz_CC_test_compile(code); + free(code); + return retval; +} + static void chaz_CC_detect_known_compilers(void) { - chaz_CC.intval___GNUC__ = chaz_CC_detect_macro("__GNUC__"); + chaz_CC.intval___GNUC__ = chaz_CC_eval_macro("__GNUC__"); if (chaz_CC.intval___GNUC__) { chaz_CC.intval___GNUC_MINOR__ - = chaz_CC_detect_macro("__GNUC_MINOR__"); + = chaz_CC_eval_macro("__GNUC_MINOR__"); chaz_CC.intval___GNUC_PATCHLEVEL__ - = chaz_CC_detect_macro("__GNUC_PATCHLEVEL__"); + = chaz_CC_eval_macro("__GNUC_PATCHLEVEL__"); sprintf(chaz_CC.gcc_version_str, "%d.%d.%d", chaz_CC.intval___GNUC__, chaz_CC.intval___GNUC_MINOR__, chaz_CC.intval___GNUC_PATCHLEVEL__); } - chaz_CC.intval__MSC_VER = chaz_CC_detect_macro("_MSC_VER"); - chaz_CC.intval___clang__ = chaz_CC_detect_macro("__clang__"); - chaz_CC.intval___SUNPRO_C = chaz_CC_detect_macro("__SUNPRO_C"); + chaz_CC.intval__MSC_VER = chaz_CC_eval_macro("_MSC_VER"); + chaz_CC.intval___clang__ = chaz_CC_eval_macro("__clang__"); + chaz_CC.intval___SUNPRO_C = chaz_CC_eval_macro("__SUNPRO_C"); } void @@ -522,6 +545,11 @@ chaz_CC_sun_c_version_num(void) { return chaz_CC.intval___SUNPRO_C; } +int +chaz_CC_is_cygwin(void) { + return chaz_CC.is_cygwin; +} + const char* chaz_CC_link_command() { if (chaz_CC.intval__MSC_VER) { http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/41d94077/src/Charmonizer/Core/Compiler.h ---------------------------------------------------------------------- diff --git a/src/Charmonizer/Core/Compiler.h b/src/Charmonizer/Core/Compiler.h index f8a8a3a..6361af7 100644 --- a/src/Charmonizer/Core/Compiler.h +++ b/src/Charmonizer/Core/Compiler.h @@ -66,6 +66,11 @@ chaz_CC_test_link(const char *source); char* chaz_CC_capture_output(const char *source, size_t *output_len); +/** Return true if macro is defined. + */ +int +chaz_CC_has_macro(const char *macro); + /** Initialize the compiler environment. */ void @@ -143,6 +148,9 @@ chaz_CC_msvc_version_num(void); int chaz_CC_sun_c_version_num(void); +int +chaz_CC_is_cygwin(void); + const char* chaz_CC_link_command(void); http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/41d94077/src/Charmonizer/Core/Library.c ---------------------------------------------------------------------- diff --git a/src/Charmonizer/Core/Library.c b/src/Charmonizer/Core/Library.c index b07c7a5..d1e0cb6 100644 --- a/src/Charmonizer/Core/Library.c +++ b/src/Charmonizer/Core/Library.c @@ -33,7 +33,7 @@ static char* S_build_filename(chaz_Lib *lib, const char *version, const char *ext); static const char* -S_get_prefix(void); +S_get_prefix(chaz_Lib *lib); chaz_Lib* chaz_Lib_new_shared(const char *name, const char *version, @@ -120,7 +120,7 @@ chaz_Lib_major_version_filename(chaz_Lib *lib) { char* chaz_Lib_no_version_filename(chaz_Lib *lib) { - const char *prefix = S_get_prefix(); + const char *prefix = S_get_prefix(lib); const char *ext = lib->is_shared ? chaz_CC_shared_lib_ext() : chaz_CC_static_lib_ext(); @@ -140,7 +140,7 @@ chaz_Lib_export_filename(chaz_Lib *lib) { static char* S_build_filename(chaz_Lib *lib, const char *version, const char *ext) { - const char *prefix = S_get_prefix(); + const char *prefix = S_get_prefix(lib); int binary_format = chaz_CC_binary_format(); if (binary_format == CHAZ_CC_BINFMT_PE) { @@ -159,14 +159,13 @@ S_build_filename(chaz_Lib *lib, const char *version, const char *ext) { } static const char* -S_get_prefix() { +S_get_prefix(chaz_Lib *lib) { if (chaz_CC_msvc_version_num()) { return ""; } - /* TODO: Readd Cygwin detection. */ - /*else if (chaz_OS_is_cygwin()) { - return "cyg"; - }*/ + else if (chaz_CC_is_cygwin()) { + return lib->is_static ? "lib" : "cyg"; + } else { return "lib"; }