lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [2/14] git commit: refs/heads/master - Capture numeric values for compiler version macros.
Date Wed, 02 Jan 2013 20:38:08 GMT
Capture numeric values for compiler version macros.


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

Branch: refs/heads/master
Commit: 95e43517a5f8748c637df47e61c5d297e27e924f
Parents: 8dafae6
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Wed Nov 28 18:22:29 2012 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Wed Jan 2 12:10:11 2013 -0800

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Core/Compiler.c |   36 ++++++++++++++--------
 1 files changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/95e43517/charmonizer/src/Charmonizer/Core/Compiler.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Core/Compiler.c b/charmonizer/src/Charmonizer/Core/Compiler.c
index a2a7e19..0364686 100644
--- a/charmonizer/src/Charmonizer/Core/Compiler.c
+++ b/charmonizer/src/Charmonizer/Core/Compiler.c
@@ -42,9 +42,9 @@ static struct {
     char      exe_flag[10];
     char      no_link_flag[10];
     char      error_flag[10];
-    int       defines___GNUC__;
-    int       defines__MSC_VER;
-    int       defines___clang__;
+    int       intval___GNUC__;
+    int       intval__MSC_VER;
+    int       intval___clang__;
     int       warnings_as_errors;
 } chaz_CC = {
     NULL, NULL, NULL, NULL,
@@ -56,7 +56,7 @@ void
 chaz_CC_set_warnings_as_errors(const int flag) {
     chaz_CC.warnings_as_errors = flag;
     if (chaz_CC.warnings_as_errors) {
-        if (chaz_CC.defines__MSC_VER)  {
+        if (chaz_CC.intval__MSC_VER)  {
             strcpy(chaz_CC.error_flag, "/WX");
         } else {
             strcpy(chaz_CC.error_flag, "-Werror");
@@ -115,30 +115,40 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags)
{
     chaz_CC_detect_known_compilers();
 }
 
-static const char detect_macro_code[] =
+static const char chaz_CC_detect_macro_code[] =
+    CHAZ_QUOTE(  #include <stdio.h>             )
     CHAZ_QUOTE(  int main() {                   )
     CHAZ_QUOTE(  #ifndef %s                     )
     CHAZ_QUOTE(  #error "nope"                  )
     CHAZ_QUOTE(  #endif                         )
+    CHAZ_QUOTE(      printf("%%d", %s);         )
     CHAZ_QUOTE(      return 0;                  )
     CHAZ_QUOTE(  }                              );
 
 static int
 chaz_CC_detect_macro(const char *macro) {
-    size_t size = sizeof(detect_macro_code) + strlen(macro) + 20;
+    size_t size = sizeof(chaz_CC_detect_macro_code)
+                  + (strlen(macro) * 2)
+                  + 20;
     char *code = (char*)malloc(size);
-    int retval;
-    sprintf(code, detect_macro_code, macro);
-    retval = chaz_CC_test_compile(code);
+    int retval = 0;
+    char *output;
+    size_t len;
+    sprintf(code, chaz_CC_detect_macro_code, macro, macro);
+    output = chaz_CC_capture_output(code, &len);
+    if (output) {
+        retval = atoi(output);
+        free(output);
+    }
     free(code);
     return retval;
 }
 
 static void
 chaz_CC_detect_known_compilers(void) {
-    chaz_CC.defines___GNUC__  = chaz_CC_detect_macro("__GNUC__");
-    chaz_CC.defines__MSC_VER  = chaz_CC_detect_macro("_MSC_VER");
-    chaz_CC.defines___clang__ = chaz_CC_detect_macro("__clang__");
+    chaz_CC.intval___GNUC__  = chaz_CC_detect_macro("__GNUC__");
+    chaz_CC.intval__MSC_VER  = chaz_CC_detect_macro("_MSC_VER");
+    chaz_CC.intval___clang__ = chaz_CC_detect_macro("__clang__");
 }
 
 void
@@ -184,7 +194,7 @@ chaz_CC_compile_exe(const char *source_path, const char *exe_name,
         system(command);
     }
 
-    if (chaz_CC.defines__MSC_VER) {
+    if (chaz_CC.intval__MSC_VER) {
         /* Zap MSVC junk. */
         sprintf(junk, "%s.obj", exe_name);
         chaz_Util_remove_and_verify(junk);


Mime
View raw message