You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2017/02/04 17:37:20 UTC

[1/9] lucy-charmonizer git commit: Remove U64_TO_DOUBLE macro

Repository: lucy-charmonizer
Updated Branches:
  refs/heads/master 508ca633e -> 4e29a77d0


Remove U64_TO_DOUBLE macro

It was only needed for MSVC6.


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

Branch: refs/heads/master
Commit: 2380b6685a17973173ca2c7ba9a1955ee3b195b5
Parents: 508ca63
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 13:27:00 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 15:21:31 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Probe/Integers.c | 33 ---------------------------------
 1 file changed, 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/2380b668/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Integers.c b/src/Charmonizer/Probe/Integers.c
index 8fec02e..7411880 100644
--- a/src/Charmonizer/Probe/Integers.c
+++ b/src/Charmonizer/Probe/Integers.c
@@ -67,17 +67,6 @@ static const char chaz_Integers_literal64_code[] =
     CHAZ_QUOTE(      return 0;                             )
     CHAZ_QUOTE(  }                                         );
 
-static const char chaz_Integers_u64_to_double_code[] =
-    CHAZ_QUOTE(  #include <stdio.h>                        )
-    CHAZ_QUOTE(  int main()                                )
-    CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      unsigned %s int_num = 0;              )
-    CHAZ_QUOTE(      double float_num;                     )
-    CHAZ_QUOTE(      float_num = (double)int_num;          )
-    CHAZ_QUOTE(      printf("%%f\n", float_num);           )
-    CHAZ_QUOTE(      return 0;                             )
-    CHAZ_QUOTE(  }                                         );
-
 void
 chaz_Integers_run(void) {
     char *output;
@@ -347,28 +336,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Create macro for converting uint64_t to double. */
-    if (has_64) {
-        /*
-         * Determine whether unsigned 64-bit integers can be converted to
-         * double. Older MSVC versions don't support this conversion.
-         */
-        sprintf(code_buf, chaz_Integers_u64_to_double_code, i64_t_type);
-        output = chaz_CC_capture_output(code_buf, &output_len);
-        if (output != NULL) {
-            chaz_ConfWriter_add_def("U64_TO_DOUBLE(num)", "((double)(num))");
-            free(output);
-        }
-        else {
-            chaz_ConfWriter_add_def(
-                "U64_TO_DOUBLE(num)",
-                "((num) & UINT64_C(0x8000000000000000) ? "
-                "(double)(int64_t)((num) & UINT64_C(0x7FFFFFFFFFFFFFFF)) + "
-                "9223372036854775808.0 : "
-                "(double)(int64_t)(num))");
-        }
-    }
-
     chaz_ConfWriter_end_module();
 
     /* Integer typedefs. */


[2/9] lucy-charmonizer git commit: Rework compiler version detection

Posted by nw...@apache.org.
Rework compiler version detection

Don't evaluate version macros. Only check for presence and add
functions that check version numbers against a predicate. Required to
support cross compilation.


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

Branch: refs/heads/master
Commit: d8e3d9377948cc9490a55519dfbcd67c2bc58162
Parents: cb8761f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 19:32:59 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/CFlags.c            |  12 ++-
 src/Charmonizer/Core/Compiler.c          | 147 +++++++++++++-------------
 src/Charmonizer/Core/Compiler.h          |  24 +++--
 src/Charmonizer/Core/Make.c              |   6 +-
 src/Charmonizer/Probe.c                  |  15 ---
 src/Charmonizer/Probe.h                  |  17 ---
 src/Charmonizer/Probe/Memory.c           |   2 +-
 src/Charmonizer/Probe/SymbolVisibility.c |   2 +-
 8 files changed, 105 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Core/CFlags.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/CFlags.c b/src/Charmonizer/Core/CFlags.c
index ea07dc1..ab57fcc 100644
--- a/src/Charmonizer/Core/CFlags.c
+++ b/src/Charmonizer/Core/CFlags.c
@@ -235,8 +235,16 @@ chaz_CFlags_hide_symbols(chaz_CFlags *flags) {
         }
     }
     else if (flags->style == CHAZ_CFLAGS_STYLE_SUN_C) {
-        if (chaz_CC_sun_c_version_num() >= 0x550) {
-            /* Sun Studio 8. */
+        static int checked = 0;
+        static int version_ge_550;
+
+        if (!checked) {
+            /* Requires Sun Studio 8. */
+            version_ge_550 = chaz_CC_test_sun_c_version(">= 0x550");
+            checked = 1;
+        }
+
+        if (version_ge_550) {
             chaz_CFlags_append(flags, "-xldscope=hidden");
         }
     }

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Core/Compiler.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Compiler.c b/src/Charmonizer/Core/Compiler.c
index f864a5d..49fed58 100644
--- a/src/Charmonizer/Core/Compiler.c
+++ b/src/Charmonizer/Core/Compiler.c
@@ -27,11 +27,6 @@
 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
@@ -62,12 +57,10 @@ static struct {
     char      gcc_version_str[30];
     int       binary_format;
     int       cflags_style;
-    int       intval___GNUC__;
-    int       intval___GNUC_MINOR__;
-    int       intval___GNUC_PATCHLEVEL__;
-    int       intval__MSC_VER;
-    int       intval___clang__;
-    int       intval___SUNPRO_C;
+    int       is_gcc;
+    int       is_msvc;
+    int       is_clang;
+    int       is_sun_c;
     int       is_cygwin;
     int       is_mingw;
     chaz_CFlags *extra_cflags;
@@ -75,7 +68,7 @@ static struct {
 } chaz_CC = {
     NULL, NULL, NULL,
     "", "", "", "", "", "",
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0,
     NULL, NULL
 };
 
@@ -110,6 +103,9 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags) {
         }
         compile_succeeded = chaz_CC_compile_exe(CHAZ_CC_TRY_SOURCE_PATH,
                                                 CHAZ_CC_TRY_BASENAME, code);
+        if (compile_succeeded) {
+            strcpy(chaz_CC.obj_ext, ".obj");
+        }
     }
 
     /* Try POSIX argument style. */
@@ -120,6 +116,9 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags) {
         }
         compile_succeeded = chaz_CC_compile_exe(CHAZ_CC_TRY_SOURCE_PATH,
                                                 CHAZ_CC_TRY_BASENAME, code);
+        if (compile_succeeded) {
+            strcpy(chaz_CC.obj_ext, ".o");
+        }
     }
 
     if (!compile_succeeded) {
@@ -130,13 +129,13 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags) {
 
     chaz_CC_detect_known_compilers();
 
-    if (chaz_CC.intval___GNUC__) {
+    if (chaz_CC_is_gcc()) {
         chaz_CC.cflags_style = CHAZ_CFLAGS_STYLE_GNU;
     }
-    else if (chaz_CC.intval__MSC_VER) {
+    else if (chaz_CC_is_msvc()) {
         chaz_CC.cflags_style = CHAZ_CFLAGS_STYLE_MSVC;
     }
-    else if (chaz_CC.intval___SUNPRO_C) {
+    else if (chaz_CC_is_sun_c()) {
         chaz_CC.cflags_style = CHAZ_CFLAGS_STYLE_SUN_C;
     }
     else {
@@ -170,7 +169,7 @@ chaz_CC_init(const char *compiler_command, const char *compiler_flags) {
         }
         strcpy(chaz_CC.exe_ext, ".exe");
         strcpy(chaz_CC.shared_lib_ext, ".dll");
-        if (chaz_CC.intval___GNUC__) {
+        if (chaz_CC_is_gcc()) {
             strcpy(chaz_CC.static_lib_ext, ".a");
             strcpy(chaz_CC.import_lib_ext, ".dll.a");
             strcpy(chaz_CC.obj_ext, ".o");
@@ -244,43 +243,40 @@ chaz_CC_detect_binary_format(const char *filename) {
     free(output);
 }
 
-static const char chaz_CC_eval_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_eval_macro(const char *macro) {
-    size_t size = sizeof(chaz_CC_eval_macro_code)
-                  + (strlen(macro) * 2)
+int
+chaz_CC_has_macro(const char *macro) {
+    static const char template[] =
+        CHAZ_QUOTE(  #ifdef %s             )
+        CHAZ_QUOTE(  int i;                )
+        CHAZ_QUOTE(  #else                 )
+        CHAZ_QUOTE(  #error "nope"         )
+        CHAZ_QUOTE(  #endif                );
+    size_t size = sizeof(template)
+                  + strlen(macro)
                   + 20;
     char *code = (char*)malloc(size);
     int retval = 0;
-    char *output;
-    size_t len;
-    sprintf(code, chaz_CC_eval_macro_code, macro, macro);
-    output = chaz_CC_capture_output(code, &len);
-    if (output) {
-        retval = atoi(output);
-        free(output);
-    }
+    sprintf(code, template, macro);
+    retval = chaz_CC_test_compile(code);
     free(code);
     return retval;
 }
 
 int
-chaz_CC_has_macro(const char *macro) {
-    size_t size = sizeof(chaz_CC_eval_macro_code)
-                  + (strlen(macro) * 2)
+chaz_CC_test_macro(const char *expression, const char *predicate) {
+    static const char template[] =
+        CHAZ_QUOTE(  #if (%s) %s           )
+        CHAZ_QUOTE(  int i;                )
+        CHAZ_QUOTE(  #else                 )
+        CHAZ_QUOTE(  #error "nope"         )
+        CHAZ_QUOTE(  #endif                );
+    size_t size = sizeof(template)
+                  + strlen(expression)
+                  + strlen(predicate)
                   + 20;
     char *code = (char*)malloc(size);
     int retval = 0;
-    sprintf(code, chaz_CC_eval_macro_code, macro, macro);
+    sprintf(code, template, expression, predicate);
     retval = chaz_CC_test_compile(code);
     free(code);
     return retval;
@@ -288,19 +284,10 @@ chaz_CC_has_macro(const char *macro) {
 
 static void
 chaz_CC_detect_known_compilers(void) {
-    chaz_CC.intval___GNUC__  = chaz_CC_eval_macro("__GNUC__");
-    if (chaz_CC.intval___GNUC__) {
-        chaz_CC.intval___GNUC_MINOR__
-            = chaz_CC_eval_macro("__GNUC_MINOR__");
-        chaz_CC.intval___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_eval_macro("_MSC_VER");
-    chaz_CC.intval___clang__  = chaz_CC_eval_macro("__clang__");
-    chaz_CC.intval___SUNPRO_C = chaz_CC_eval_macro("__SUNPRO_C");
+    chaz_CC.is_gcc   = chaz_CC_has_macro("__GNUC__");
+    chaz_CC.is_msvc  = chaz_CC_has_macro("_MSC_VER");
+    chaz_CC.is_clang = chaz_CC_has_macro("__clang__");
+    chaz_CC.is_sun_c = chaz_CC_has_macro("__SUNPRO_C");
 }
 
 void
@@ -346,7 +333,7 @@ chaz_CC_compile_exe(const char *source_path, const char *exe_name,
         system(command);
     }
 
-    if (chaz_CC.intval__MSC_VER) {
+    if (chaz_CC_is_msvc()) {
         /* Zap MSVC junk. */
         size_t  junk_buf_size = strlen(exe_file) + 4;
         char   *junk          = (char*)malloc(junk_buf_size);
@@ -534,25 +521,18 @@ chaz_CC_obj_ext(void) {
 }
 
 int
-chaz_CC_gcc_version_num(void) {
-    return 10000 * chaz_CC.intval___GNUC__
-           + 100 * chaz_CC.intval___GNUC_MINOR__
-           + chaz_CC.intval___GNUC_PATCHLEVEL__;
-}
-
-const char*
-chaz_CC_gcc_version(void) {
-    return chaz_CC.intval___GNUC__ ? chaz_CC.gcc_version_str : NULL;
+chaz_CC_is_gcc(void) {
+    return chaz_CC.is_gcc;
 }
 
 int
-chaz_CC_msvc_version_num(void) {
-    return chaz_CC.intval__MSC_VER;
+chaz_CC_is_msvc(void) {
+    return chaz_CC.is_msvc;
 }
 
 int
-chaz_CC_sun_c_version_num(void) {
-    return chaz_CC.intval___SUNPRO_C;
+chaz_CC_is_sun_c(void) {
+    return chaz_CC.is_sun_c;
 }
 
 int
@@ -565,9 +545,26 @@ chaz_CC_is_mingw(void) {
     return chaz_CC.is_mingw;
 }
 
+int
+chaz_CC_test_gcc_version(const char *predicate) {
+    static const char version[] =
+        "10000 * __GNUC__ + 100 * __GNUC_MINOR__ + __GNUC_PATCHLEVEL__";
+    return chaz_CC_test_macro(version, predicate);
+}
+
+int
+chaz_CC_test_msvc_version(const char *predicate) {
+    return chaz_CC_test_macro("_MSC_VER", predicate);
+}
+
+int
+chaz_CC_test_sun_c_version(const char *predicate) {
+    return chaz_CC_test_macro("__SUNPRO_C", predicate);
+}
+
 const char*
 chaz_CC_link_command() {
-    if (chaz_CC.intval__MSC_VER) {
+    if (chaz_CC_is_msvc()) {
         return "link";
     }
     else {
@@ -577,7 +574,7 @@ chaz_CC_link_command() {
 
 char*
 chaz_CC_format_archiver_command(const char *target, const char *objects) {
-    if (chaz_CC.intval__MSC_VER) {
+    if (chaz_CC_is_msvc()) {
         /* TODO: Write `objects` to a temporary file in order to avoid
          * exceeding line length limits. */
         char *out = chaz_Util_join("", "/OUT:", target, NULL);
@@ -593,7 +590,7 @@ chaz_CC_format_archiver_command(const char *target, const char *objects) {
 
 char*
 chaz_CC_format_ranlib_command(const char *target) {
-    if (chaz_CC.intval__MSC_VER) {
+    if (chaz_CC_is_msvc()) {
         return NULL;
     }
     return chaz_Util_join(" ", "ranlib", target, NULL);
@@ -603,7 +600,7 @@ char*
 chaz_CC_shared_lib_filename(const char *dir, const char *basename,
                             const char *version) {
     /* Cygwin uses a "cyg" prefix for shared libraries. */
-    const char *prefix = chaz_CC_msvc_version_num()
+    const char *prefix = chaz_CC_is_msvc()
                          ? ""
                          : chaz_CC_is_cygwin() ? "cyg" : "lib";
     return chaz_CC_build_lib_filename(dir, prefix, basename, version,
@@ -613,7 +610,7 @@ chaz_CC_shared_lib_filename(const char *dir, const char *basename,
 char*
 chaz_CC_import_lib_filename(const char *dir, const char *basename,
                             const char *version) {
-    const char *prefix = chaz_CC_msvc_version_num() ? "" : "lib";
+    const char *prefix = chaz_CC_is_msvc() ? "" : "lib";
     return chaz_CC_build_lib_filename(dir, prefix, basename, version,
                                       chaz_CC.import_lib_ext);
 }
@@ -668,7 +665,7 @@ chaz_CC_build_lib_filename(const char *dir, const char *prefix,
 
 char*
 chaz_CC_static_lib_filename(const char *dir, const char *basename) {
-    const char *prefix = chaz_CC_msvc_version_num() ? "" : "lib";
+    const char *prefix = chaz_CC_is_msvc() ? "" : "lib";
 
     if (dir == NULL || strcmp(dir, ".") == 0) {
         return chaz_Util_join("", prefix, basename, chaz_CC.static_lib_ext,

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Core/Compiler.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Compiler.h b/src/Charmonizer/Core/Compiler.h
index 02e2925..da506f6 100644
--- a/src/Charmonizer/Core/Compiler.h
+++ b/src/Charmonizer/Core/Compiler.h
@@ -71,6 +71,12 @@ chaz_CC_capture_output(const char *source, size_t *output_len);
 int
 chaz_CC_has_macro(const char *macro);
 
+/** Return true if preprocessor expression matches predicate. Predicate has
+ * the form "<op> value", e.g. ">= 0x1500".
+ */
+int
+chaz_CC_test_macro(const char *expression, const char *predicate);
+
 /** Initialize the compiler environment.
  */
 void
@@ -137,16 +143,13 @@ const char*
 chaz_CC_obj_ext(void);
 
 int
-chaz_CC_gcc_version_num(void);
-
-const char*
-chaz_CC_gcc_version(void);
+chaz_CC_is_gcc(void);
 
 int
-chaz_CC_msvc_version_num(void);
+chaz_CC_is_msvc(void);
 
 int
-chaz_CC_sun_c_version_num(void);
+chaz_CC_is_sun_c(void);
 
 int
 chaz_CC_is_cygwin(void);
@@ -154,6 +157,15 @@ chaz_CC_is_cygwin(void);
 int
 chaz_CC_is_mingw(void);
 
+int
+chaz_CC_test_gcc_version(const char *predicate);
+
+int
+chaz_CC_test_msvc_version(const char *predicate);
+
+int
+chaz_CC_test_sun_c_version(const char *predicate);
+
 const char*
 chaz_CC_link_command(void);
 

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index 9c4722b..cebacd5 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -507,7 +507,7 @@ S_chaz_MakeFile_finish_shared_lib(chaz_MakeFile *self,
         free(filename);
     }
 
-    if (chaz_CC_msvc_version_num()) {
+    if (chaz_CC_is_msvc()) {
         /* Remove export file. */
         char *filename
             = chaz_CC_export_filename(binary->target_dir, binary->basename,
@@ -674,7 +674,7 @@ chaz_MakeFile_write(chaz_MakeFile *self) {
     S_chaz_MakeRule_write(self->distclean, out);
 
     /* Suffix rule for .c files. */
-    if (chaz_CC_msvc_version_num()) {
+    if (chaz_CC_is_msvc()) {
         fprintf(out, ".c.obj :\n");
         fprintf(out, "\t$(CC) /nologo $(CFLAGS) /c $< /Fo$@\n\n");
     }
@@ -691,7 +691,7 @@ S_chaz_MakeFile_write_binary_rules(chaz_MakeFile *self,
                                    chaz_MakeBinary *binary, FILE *out) {
     const char *cflags;
 
-    if (chaz_CC_msvc_version_num()) {
+    if (chaz_CC_is_msvc()) {
         chaz_CFlags_append(binary->compile_flags, "/nologo");
         chaz_CFlags_append(binary->link_flags, "/nologo");
     }

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Probe.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.c b/src/Charmonizer/Probe.c
index 5aaa988..3cc4228 100644
--- a/src/Charmonizer/Probe.c
+++ b/src/Charmonizer/Probe.c
@@ -171,18 +171,3 @@ chaz_Probe_clean_up(void) {
 
     if (chaz_Util_verbosity) { printf("Cleanup complete.\n"); }
 }
-
-int
-chaz_Probe_gcc_version_num(void) {
-    return chaz_CC_gcc_version_num();
-}
-
-const char*
-chaz_Probe_gcc_version(void) {
-    return chaz_CC_gcc_version_num() ? chaz_CC_gcc_version() : NULL;
-}
-
-int
-chaz_Probe_msvc_version_num(void) {
-    return chaz_CC_msvc_version_num();
-}

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Probe.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.h b/src/Charmonizer/Probe.h
index 3ce92d0..cd1f03c 100644
--- a/src/Charmonizer/Probe.h
+++ b/src/Charmonizer/Probe.h
@@ -66,23 +66,6 @@ chaz_Probe_init(struct chaz_CLI *cli);
 void
 chaz_Probe_clean_up(void);
 
-/* Return an integer version of the GCC version number which is
- * (10000 * __GNU_C__ + 100 * __GNUC_MINOR__ + __GNUC_PATCHLEVEL__).
- */
-int
-chaz_Probe_gcc_version_num(void);
-
-/* If the compiler is GCC (or claims compatibility), return an X.Y.Z string
- * version of the GCC version; otherwise, return NULL.
- */
-const char*
-chaz_Probe_gcc_version(void);
-
-/* Return the integer version of MSVC defined by _MSC_VER
- */
-int
-chaz_Probe_msvc_version_num(void);
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Probe/Memory.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Memory.c b/src/Charmonizer/Probe/Memory.c
index 07bde87..a853a53 100644
--- a/src/Charmonizer/Probe/Memory.c
+++ b/src/Charmonizer/Probe/Memory.c
@@ -65,7 +65,7 @@ chaz_Memory_probe_alloca(void) {
     /* Under GCC, alloca is a builtin that works without including the
      * correct header, generating only a warning. To avoid misdetection,
      * disable the alloca builtin temporarily. */
-    if (chaz_CC_gcc_version_num()) {
+    if (chaz_CC_is_gcc()) {
         chaz_CFlags_append(temp_cflags, "-fno-builtin-alloca");
     }
 

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/d8e3d937/src/Charmonizer/Probe/SymbolVisibility.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/SymbolVisibility.c b/src/Charmonizer/Probe/SymbolVisibility.c
index 73fdaf4..34e9ac4 100644
--- a/src/Charmonizer/Probe/SymbolVisibility.c
+++ b/src/Charmonizer/Probe/SymbolVisibility.c
@@ -59,7 +59,7 @@ chaz_SymbolVisibility_run(void) {
         if (chaz_CC_test_compile(code_buf)) {
             can_control_visibility = true;
             chaz_ConfWriter_add_def("EXPORT", export_win);
-            if (chaz_CC_gcc_version_num()) {
+            if (chaz_CC_is_gcc()) {
                 /*
                  * Under MinGW, symbols with dllimport storage class aren't
                  * constant. If a global variable is initialized to such a


[8/9] lucy-charmonizer git commit: Add chaz_OS_exe_ext() function

Posted by nw...@apache.org.
Add chaz_OS_exe_ext() function

The executable extension can differ on host and target OS when
cross-compiling.


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

Branch: refs/heads/master
Commit: 4e29a77d0b25255ad4b807eda608bf7e4a65e758
Parents: 34d27fa
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Feb 4 16:07:29 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/Make.c            | 7 +++----
 src/Charmonizer/Core/OperatingSystem.c | 9 +++++++++
 src/Charmonizer/Core/OperatingSystem.h | 7 +++++++
 3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/4e29a77d/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index 2ea2c7c..2bd286c 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -273,8 +273,6 @@ S_chaz_Make_audition(const char *make) {
 chaz_MakeFile*
 chaz_MakeFile_new() {
     chaz_MakeFile *self = (chaz_MakeFile*)calloc(1, sizeof(chaz_MakeFile));
-    const char    *exe_ext  = chaz_CC_exe_ext();
-    const char    *obj_ext  = chaz_CC_obj_ext();
     char *generated;
 
     self->vars     = (chaz_MakeVar**)calloc(1, sizeof(chaz_MakeVar*));
@@ -284,8 +282,9 @@ chaz_MakeFile_new() {
     self->clean     = S_chaz_MakeRule_new("clean", NULL);
     self->distclean = S_chaz_MakeRule_new("distclean", "clean");
 
-    generated = chaz_Util_join("", "charmonizer", exe_ext, " charmonizer",
-                               obj_ext, " charmony.h Makefile", NULL);
+    /* MSVC leaves .obj files around when creating executables. */
+    generated = chaz_Util_join("", "charmonizer", chaz_OS_exe_ext(),
+                               " charmonizer.obj charmony.h Makefile", NULL);
     chaz_MakeRule_add_rm_command(self->distclean, generated);
 
     free(generated);

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/4e29a77d/src/Charmonizer/Core/OperatingSystem.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/OperatingSystem.c b/src/Charmonizer/Core/OperatingSystem.c
index 446872b..9721b82 100644
--- a/src/Charmonizer/Core/OperatingSystem.c
+++ b/src/Charmonizer/Core/OperatingSystem.c
@@ -127,6 +127,15 @@ chaz_OS_shell_type(void) {
     return chaz_OS.shell_type;
 }
 
+const char*
+chaz_OS_exe_ext(void) {
+#ifdef _WIN32
+    return ".exe";
+#else
+    return "";
+#endif
+}
+
 int
 chaz_OS_remove(const char *name) {
     /*

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/4e29a77d/src/Charmonizer/Core/OperatingSystem.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/OperatingSystem.h b/src/Charmonizer/Core/OperatingSystem.h
index eda3890..cf13068 100644
--- a/src/Charmonizer/Core/OperatingSystem.h
+++ b/src/Charmonizer/Core/OperatingSystem.h
@@ -83,6 +83,13 @@ chaz_OS_dir_sep(void);
 int
 chaz_OS_shell_type(void);
 
+/* Return the file extension for executables on this system. This can be
+ * a different value than returned by chaz_CC_exe_ext() when
+ * cross-compiling.
+ */
+const char*
+chaz_OS_exe_ext(void);
+
 /* Initialize the Charmonizer/Core/OperatingSystem module.
  */
 void


[7/9] lucy-charmonizer git commit: Move format string code block

Posted by nw...@apache.org.
Move format string code block


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

Branch: refs/heads/master
Commit: 7576ef3b71f47c9fa3566b4ed77c85bf2c8b96ef
Parents: bf01644
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 18:02:47 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Probe/Integers.c | 82 +++++++++++++++++------------------
 1 file changed, 41 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/7576ef3b/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Integers.c b/src/Charmonizer/Probe/Integers.c
index 885dd59..ab2862d 100644
--- a/src/Charmonizer/Probe/Integers.c
+++ b/src/Charmonizer/Probe/Integers.c
@@ -173,47 +173,6 @@ chaz_Integers_run(void) {
         }
     }
 
-    /* Probe for 64-bit printf format string modifier. */
-    if (!has_inttypes && has_64) {
-        int i;
-        const char *options[] = {
-            "ll",
-            "l",
-            "L",
-            "q",   /* Some *BSDs */
-            "I64", /* Microsoft */
-            NULL,
-        };
-
-        /* Buffer to hold the code, and its start and end. */
-        static const char format_64_code[] =
-            CHAZ_QUOTE(  #include <stdio.h>                            )
-            CHAZ_QUOTE(  int main() {                                  )
-            CHAZ_QUOTE(      printf("%%%su", 18446744073709551615%s);  )
-            CHAZ_QUOTE(      return 0;                                 )
-            CHAZ_QUOTE( }                                              );
-
-        for (i = 0; options[i] != NULL; i++) {
-            /* Try to print 2**64-1, and see if we get it back intact. */
-            int success;
-            sprintf(code_buf, format_64_code, options[i], u64_t_postfix);
-            output = chaz_CC_capture_output(code_buf, &output_len);
-            success = output != NULL
-                      && strcmp(output, "18446744073709551615") == 0;
-            free(output);
-
-            if (success) {
-                break;
-            }
-        }
-
-        if (options[i] == NULL) {
-            chaz_Util_die("64-bit types, but no printf modifier found");
-        }
-
-        strcpy(printf_modifier_64, options[i]);
-    }
-
     /* Write out some conditional defines. */
     if (has_inttypes) {
         chaz_ConfWriter_add_def("HAS_INTTYPES_H", NULL);
@@ -503,6 +462,47 @@ chaz_Integers_run(void) {
         chaz_ConfWriter_add_sys_include("inttypes.h");
     }
 
+    /* Probe for 64-bit printf format string modifier. */
+    if (!has_inttypes && has_64) {
+        int i;
+        const char *options[] = {
+            "ll",
+            "l",
+            "L",
+            "q",   /* Some *BSDs */
+            "I64", /* Microsoft */
+            NULL,
+        };
+
+        /* Buffer to hold the code, and its start and end. */
+        static const char format_64_code[] =
+            CHAZ_QUOTE(  #include <stdio.h>                            )
+            CHAZ_QUOTE(  int main() {                                  )
+            CHAZ_QUOTE(      printf("%%%su", 18446744073709551615%s);  )
+            CHAZ_QUOTE(      return 0;                                 )
+            CHAZ_QUOTE( }                                              );
+
+        for (i = 0; options[i] != NULL; i++) {
+            /* Try to print 2**64-1, and see if we get it back intact. */
+            int success;
+            sprintf(code_buf, format_64_code, options[i], u64_t_postfix);
+            output = chaz_CC_capture_output(code_buf, &output_len);
+            success = output != NULL
+                      && strcmp(output, "18446744073709551615") == 0;
+            free(output);
+
+            if (success) {
+                break;
+            }
+        }
+
+        if (options[i] == NULL) {
+            chaz_Util_die("64-bit types, but no printf modifier found");
+        }
+
+        strcpy(printf_modifier_64, options[i]);
+    }
+
     if (!has_inttypes || !has_intptr_t) {
         /* We support only the following subset of inttypes.h
          *   PRId32


[6/9] lucy-charmonizer git commit: Execute probes only when necessary

Posted by nw...@apache.org.
Execute probes only when necessary

In many cases, it's enough to check whether a test program compiles.
This allows to simplify the probe code and speeds up the configuration
process.


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

Branch: refs/heads/master
Commit: b978797e57c734850952f9c3268f1ccc7ae97216
Parents: 2380b66
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 16:42:30 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/HeaderChecker.c   |  7 +--
 src/Charmonizer/Probe/Floats.c         | 22 ++++------
 src/Charmonizer/Probe/FuncMacro.c      | 67 +++--------------------------
 src/Charmonizer/Probe/Integers.c       | 36 +++-------------
 src/Charmonizer/Probe/LargeFiles.c     | 49 +++------------------
 src/Charmonizer/Probe/Strings.c        | 26 ++---------
 src/Charmonizer/Probe/VariadicMacros.c | 23 +++-------
 7 files changed, 39 insertions(+), 191 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Core/HeaderChecker.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/HeaderChecker.c b/src/Charmonizer/Core/HeaderChecker.c
index 5b1c90b..a2b46db 100644
--- a/src/Charmonizer/Core/HeaderChecker.c
+++ b/src/Charmonizer/Core/HeaderChecker.c
@@ -132,18 +132,13 @@ chaz_HeadCheck_check_many_headers(const char **header_names) {
 
 int
 chaz_HeadCheck_defines_symbol(const char *symbol, const char *includes) {
-    /*
-     * Casting function pointers to object pointers like 'char*' is a C
-     * extension, so for a bullet-proof check, a separate test for functions
-     * might be necessary.
-     */
     static const char defines_code[] =
         CHAZ_QUOTE(  %s                                            )
         CHAZ_QUOTE(  int main() {                                  )
         CHAZ_QUOTE(  #ifdef %s                                     )
         CHAZ_QUOTE(      return 0;                                 )
         CHAZ_QUOTE(  #else                                         )
-        CHAZ_QUOTE(      return *(char*)&%s;                       )
+        CHAZ_QUOTE(      return (int)&%s;                          )
         CHAZ_QUOTE(  #endif                                        )
         CHAZ_QUOTE(  }                                             );
     long needed = sizeof(defines_code)

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/Floats.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Floats.c b/src/Charmonizer/Probe/Floats.c
index e2f8d41..229a9d4 100644
--- a/src/Charmonizer/Probe/Floats.c
+++ b/src/Charmonizer/Probe/Floats.c
@@ -71,34 +71,30 @@ chaz_Floats_run(void) {
 
 const char*
 chaz_Floats_math_library(void) {
+    /*
+     * The cast to a specific function pointer type is required because
+     * C++ overloads sqrt.
+     */
     static const char sqrt_code[] =
         CHAZ_QUOTE(  #include <math.h>                              )
-        CHAZ_QUOTE(  #include <stdio.h>                             )
         CHAZ_QUOTE(  typedef double (*sqrt_t)(double);              )
-        CHAZ_QUOTE(  int main(void) {                               )
-        CHAZ_QUOTE(      printf("%p\n", (sqrt_t)sqrt);              )
-        CHAZ_QUOTE(      return 0;                                  )
-        CHAZ_QUOTE(  }                                              );
+        CHAZ_QUOTE(  int main() { return (int)(sqrt_t)sqrt; }       );
     chaz_CFlags *temp_cflags = chaz_CC_get_temp_cflags();
-    char        *output = NULL;
-    size_t       output_len;
+    int success;
 
-    output = chaz_CC_capture_output(sqrt_code, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_link(sqrt_code)) {
         /* Linking against libm not needed. */
-        free(output);
         return NULL;
     }
 
     chaz_CFlags_add_external_lib(temp_cflags, "m");
-    output = chaz_CC_capture_output(sqrt_code, &output_len);
+    success = chaz_CC_test_link(sqrt_code);
     chaz_CFlags_clear(temp_cflags);
 
-    if (output == NULL) {
+    if (!success) {
         chaz_Util_die("Don't know how to use math library.");
     }
 
-    free(output);
     return "m";
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/FuncMacro.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/FuncMacro.c b/src/Charmonizer/Probe/FuncMacro.c
index 762602c..ff4f4dd 100644
--- a/src/Charmonizer/Probe/FuncMacro.c
+++ b/src/Charmonizer/Probe/FuncMacro.c
@@ -22,63 +22,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-/* Probe for ISO func macro. */
-static int
-chaz_FuncMacro_probe_iso() {
-    static const char iso_func_code[] =
-        CHAZ_QUOTE(  #include <stdio.h>                )
-        CHAZ_QUOTE(  int main() {                      )
-        CHAZ_QUOTE(      printf("%s", __func__);       )
-        CHAZ_QUOTE(      return 0;                     )
-        CHAZ_QUOTE(  }                                 );
-    size_t output_len;
-    char *output;
-    int success = false;
-
-    output = chaz_CC_capture_output(iso_func_code, &output_len);
-    if (output != NULL && strncmp(output, "main", 4) == 0) {
-        success = true;
-    }
-    free(output);
-
-    return success;
-}
-
-static int
-chaz_FuncMacro_probe_gnu() {
-    /* Code for verifying GNU func macro. */
-    static const char gnu_func_code[] =
-        CHAZ_QUOTE(  #include <stdio.h>                )
-        CHAZ_QUOTE(  int main() {                      )
-        CHAZ_QUOTE(      printf("%s", __FUNCTION__);   )
-        CHAZ_QUOTE(      return 0;                     )
-        CHAZ_QUOTE(  }                                 );
-    size_t output_len;
-    char *output;
-    int success = false;
-
-    output = chaz_CC_capture_output(gnu_func_code, &output_len);
-    if (output != NULL && strncmp(output, "main", 4) == 0) {
-        success = true;
-    }
-    free(output);
-
-    return success;
-}
-
 /* Attempt to verify inline keyword. */
-static char*
-chaz_FuncMacro_try_inline(const char *keyword, size_t *output_len) {
-    static const char inline_code[] =
-        CHAZ_QUOTE(  #include <stdio.h>                )
-        CHAZ_QUOTE(  static %s int foo() { return 1; } )
-        CHAZ_QUOTE(  int main() {                      )
-        CHAZ_QUOTE(      printf("%%d", foo());         )
-        CHAZ_QUOTE(      return 0;                     )
-        CHAZ_QUOTE(  }                                 );
+static int
+chaz_FuncMacro_try_inline(const char *keyword) {
+    static const char inline_code[] = "static %s int f() { return 1; }";
     char code[sizeof(inline_code) + 30];
     sprintf(code, inline_code, keyword);
-    return chaz_CC_capture_output(code, output_len);
+    return chaz_CC_test_compile(code);
 }
 
 static void
@@ -94,12 +44,9 @@ chaz_FuncMacro_probe_inline(void) {
 
     for (i = 0; i < num_inline_options; i++) {
         const char *inline_option = inline_options[i];
-        size_t output_len;
-        char *output = chaz_FuncMacro_try_inline(inline_option, &output_len);
-        if (output != NULL) {
+        if (chaz_FuncMacro_try_inline(inline_option)) {
             has_inline = true;
             chaz_ConfWriter_add_def("INLINE", inline_option);
-            free(output);
             break;
         }
     }
@@ -117,11 +64,11 @@ chaz_FuncMacro_run(void) {
     chaz_ConfWriter_start_module("FuncMacro");
 
     /* Check for func macros. */
-    if (chaz_FuncMacro_probe_iso()) {
+    if (chaz_CC_test_compile("const char *f() { return __func__; }")) {
         has_funcmac     = true;
         has_iso_funcmac = true;
     }
-    if (chaz_FuncMacro_probe_gnu()) {
+    if (chaz_CC_test_compile("const char *f() { return __FUNCTION__; }")) {
         has_funcmac      = true;
         has_gnuc_funcmac = true;
     }

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Integers.c b/src/Charmonizer/Probe/Integers.c
index 7411880..c680141 100644
--- a/src/Charmonizer/Probe/Integers.c
+++ b/src/Charmonizer/Probe/Integers.c
@@ -42,12 +42,7 @@ static const char chaz_Integers_sizes_code[] =
 
 static const char chaz_Integers_stdint_type_code[] =
     CHAZ_QUOTE(  #include <stdint.h>                       )
-    CHAZ_QUOTE(  #include <stdio.h>                        )
-    CHAZ_QUOTE(  int main()                                )
-    CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      printf("%%d", (int)sizeof(%s));       )
-    CHAZ_QUOTE(      return 0;                             )
-    CHAZ_QUOTE(  }                                         );
+    CHAZ_QUOTE(  %s i;                                     );
 
 static const char chaz_Integers_type64_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                        )
@@ -58,14 +53,7 @@ static const char chaz_Integers_type64_code[] =
     CHAZ_QUOTE(  }                                         );
 
 static const char chaz_Integers_literal64_code[] =
-    CHAZ_QUOTE(  #include <stdio.h>                        )
-    CHAZ_QUOTE(  #define big 9000000000000000000%s         )
-    CHAZ_QUOTE(  int main()                                )
-    CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      int truncated = (int)big;             )
-    CHAZ_QUOTE(      printf("%%d\n", truncated);           )
-    CHAZ_QUOTE(      return 0;                             )
-    CHAZ_QUOTE(  }                                         );
+    CHAZ_QUOTE(  int f() { return (int)9000000000000000000%s; }  );
 
 void
 chaz_Integers_run(void) {
@@ -151,10 +139,8 @@ chaz_Integers_run(void) {
     /* Determine whether the intptr_t type is available (it's optional in
      * C99). */
     sprintf(code_buf, chaz_Integers_stdint_type_code, "intptr_t");
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_compile(code_buf)) {
         has_intptr_t = true;
-        free(output);
     }
 
     /* Figure out which integer types are available. */
@@ -198,34 +184,26 @@ chaz_Integers_run(void) {
     }
     else if (has_64) {
         sprintf(code_buf, chaz_Integers_literal64_code, "LL");
-        output = chaz_CC_capture_output(code_buf, &output_len);
-        if (output != NULL) {
+        if (chaz_CC_test_compile(code_buf)) {
             strcpy(i64_t_postfix, "LL");
-            free(output);
         }
         else {
             sprintf(code_buf, chaz_Integers_literal64_code, "i64");
-            output = chaz_CC_capture_output(code_buf, &output_len);
-            if (output != NULL) {
+            if (chaz_CC_test_compile(code_buf)) {
                 strcpy(i64_t_postfix, "i64");
-                free(output);
             }
             else {
                 chaz_Util_die("64-bit types, but no literal syntax found");
             }
         }
         sprintf(code_buf, chaz_Integers_literal64_code, "ULL");
-        output = chaz_CC_capture_output(code_buf, &output_len);
-        if (output != NULL) {
+        if (chaz_CC_test_compile(code_buf)) {
             strcpy(u64_t_postfix, "ULL");
-            free(output);
         }
         else {
             sprintf(code_buf, chaz_Integers_literal64_code, "Ui64");
-            output = chaz_CC_capture_output(code_buf, &output_len);
-            if (output != NULL) {
+            if (chaz_CC_test_compile(code_buf)) {
                 strcpy(u64_t_postfix, "Ui64");
-                free(output);
             }
             else {
                 chaz_Util_die("64-bit types, but no literal syntax found");

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/LargeFiles.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/LargeFiles.c b/src/Charmonizer/Probe/LargeFiles.c
index e1541c9..fe5e1fa 100644
--- a/src/Charmonizer/Probe/LargeFiles.c
+++ b/src/Charmonizer/Probe/LargeFiles.c
@@ -231,35 +231,13 @@ chaz_LargeFiles_probe_stdio64(void) {
 static int
 chaz_LargeFiles_probe_lseek(chaz_LargeFiles_unbuff_combo *combo) {
     static const char lseek_code[] =
-        CHAZ_QUOTE( %s                                                       )
-        CHAZ_QUOTE( #include <stdio.h>                                       )
-        CHAZ_QUOTE( int main() {                                             )
-        CHAZ_QUOTE(     int fd;                                              )
-        CHAZ_QUOTE(     fd = open("_charm_lseek", O_WRONLY | O_CREAT, 0666); )
-        CHAZ_QUOTE(     if (fd == -1) { return -1; }                         )
-        CHAZ_QUOTE(     %s(fd, 0, SEEK_SET);                                 )
-        CHAZ_QUOTE(     printf("%%d", 1);                                    )
-        CHAZ_QUOTE(     if (close(fd)) { return -1; }                        )
-        CHAZ_QUOTE(     return 0;                                            )
-        CHAZ_QUOTE( }                                                        );
+        CHAZ_QUOTE( %s                                      )
+        CHAZ_QUOTE( void f() { %s(0, 0, SEEK_SET); }        );
     char code_buf[sizeof(lseek_code) + 100];
-    char *output = NULL;
-    size_t output_len;
-    int success = false;
 
     /* Verify compilation. */
     sprintf(code_buf, lseek_code, combo->includes, combo->lseek_command);
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
-        success = true;
-        free(output);
-    }
-
-    if (!chaz_Util_remove_and_verify("_charm_lseek")) {
-        chaz_Util_die("Failed to remove '_charm_lseek'");
-    }
-
-    return success;
+    return chaz_CC_test_compile(code_buf);
 }
 
 static int
@@ -268,28 +246,15 @@ chaz_LargeFiles_probe_pread64(chaz_LargeFiles_unbuff_combo *combo) {
      * fine as long as it compiles. */
     static const char pread64_code[] =
         CHAZ_QUOTE(  %s                                     )
-        CHAZ_QUOTE(  #include <stdio.h>                     )
-        CHAZ_QUOTE(  int main() {                           )
-        CHAZ_QUOTE(      int fd = 20;                       )
+        CHAZ_QUOTE(  void f() {                             )
         CHAZ_QUOTE(      char buf[1];                       )
-        CHAZ_QUOTE(      printf("1");                       )
-        CHAZ_QUOTE(      %s(fd, buf, 1, 1);                 )
-        CHAZ_QUOTE(      return 0;                          )
+        CHAZ_QUOTE(      %s(0, buf, 1, 1);                  )
         CHAZ_QUOTE(  }                                      );
     char code_buf[sizeof(pread64_code) + 100];
-    char *output = NULL;
-    size_t output_len;
-    int success = false;
 
     /* Verify compilation. */
     sprintf(code_buf, pread64_code, combo->includes, combo->pread64_command);
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
-        success = true;
-        free(output);
-    }
-
-    return success;
+    return chaz_CC_test_compile(code_buf);
 }
 
 static void
@@ -297,7 +262,7 @@ chaz_LargeFiles_probe_unbuff(void) {
     static chaz_LargeFiles_unbuff_combo unbuff_combos[] = {
         { "#include <unistd.h>\n#include <fcntl.h>\n", "lseek64",   "pread64" },
         { "#include <unistd.h>\n#include <fcntl.h>\n", "lseek",     "pread"      },
-        { "#include <io.h>\n#include <fcntl.h>\n",     "_lseeki64", "NO_PREAD64" },
+        { "#include <io.h>\n#include <stdio.h>\n",     "_lseeki64", "NO_PREAD64" },
         { NULL, NULL, NULL }
     };
     int i;

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/Strings.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Strings.c b/src/Charmonizer/Probe/Strings.c
index aed53b6..fdb9a13 100644
--- a/src/Charmonizer/Probe/Strings.c
+++ b/src/Charmonizer/Probe/Strings.c
@@ -16,6 +16,7 @@
 
 #include "Charmonizer/Core/Compiler.h"
 #include "Charmonizer/Core/ConfWriter.h"
+#include "Charmonizer/Core/HeaderChecker.h"
 #include "Charmonizer/Probe/Strings.h"
 
 #include <stdlib.h>
@@ -46,23 +47,6 @@ chaz_Strings_probe_c99_snprintf(void) {
         CHAZ_QUOTE(      printf("%d", result);                      )
         CHAZ_QUOTE(      return 0;                                  )
         CHAZ_QUOTE(  }                                              );
-    static const char detect__scprintf_code[] =
-        CHAZ_QUOTE(  #include <stdio.h>                             )
-        CHAZ_QUOTE(  int main() {                                   )
-        CHAZ_QUOTE(      int  result;                               )
-        CHAZ_QUOTE(      result = _scprintf("%s", "12345");         )
-        CHAZ_QUOTE(      printf("%d", result);                      )
-        CHAZ_QUOTE(      return 0;                                  )
-        CHAZ_QUOTE(  }                                              );
-    static const char detect__snprintf_code[] =
-        CHAZ_QUOTE(  #include <stdio.h>                             )
-        CHAZ_QUOTE(  int main() {                                   )
-        CHAZ_QUOTE(      char buf[6];                               )
-        CHAZ_QUOTE(      int  result;                               )
-        CHAZ_QUOTE(      result = _snprintf(buf, 6, "%s", "12345"); )
-        CHAZ_QUOTE(      printf("%d", result);                      )
-        CHAZ_QUOTE(      return 0;                                  )
-        CHAZ_QUOTE(  }                                              );
     char   *output = NULL;
     size_t  output_len;
 
@@ -81,15 +65,11 @@ chaz_Strings_probe_c99_snprintf(void) {
 
     /* Test for _scprintf and _snprintf found in the MSVCRT.
      */
-    output = chaz_CC_capture_output(detect__scprintf_code, &output_len);
-    if (output != NULL) {
+    if (chaz_HeadCheck_defines_symbol("_scprintf", "#include <stdio.h>")) {
         chaz_ConfWriter_add_def("HAS__SCPRINTF", NULL);
-        free(output);
     }
-    output = chaz_CC_capture_output(detect__snprintf_code, &output_len);
-    if (output != NULL) {
+    if (chaz_HeadCheck_defines_symbol("_snprintf", "#include <stdio.h>")) {
         chaz_ConfWriter_add_def("HAS__SNPRINTF", NULL);
-        free(output);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/b978797e/src/Charmonizer/Probe/VariadicMacros.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/VariadicMacros.c b/src/Charmonizer/Probe/VariadicMacros.c
index d6f2d9f..0fd7bdd 100644
--- a/src/Charmonizer/Probe/VariadicMacros.c
+++ b/src/Charmonizer/Probe/VariadicMacros.c
@@ -26,48 +26,35 @@
 /* Code for verifying ISO-style variadic macros. */
 static const char chaz_VariadicMacros_iso_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                                    )
-    CHAZ_QUOTE(  #define ISO_TEST(fmt, ...) \\                         )
-    "                printf(fmt, __VA_ARGS__)                        \n"
-    CHAZ_QUOTE(  int main() {                                          )
-    CHAZ_QUOTE(      ISO_TEST("%d %d", 1, 1);                          )
-    CHAZ_QUOTE(      return 0;                                         )
-    CHAZ_QUOTE(  }                                                     );
+                "#define ISO_TEST(fmt, ...) printf(fmt, __VA_ARGS__)\n"
+    CHAZ_QUOTE(  void f() { ISO_TEST("%d %d", 1, 1); }                 );
 
 /* Code for verifying GNU-style variadic macros. */
 static const char chaz_VariadicMacros_gnuc_code[] =
     CHAZ_QUOTE(  #include <stdio.h>                                    )
     CHAZ_QUOTE(  #define GNU_TEST(fmt, args...) printf(fmt, ##args)    )
-    CHAZ_QUOTE(  int main() {                                          )
-    CHAZ_QUOTE(      GNU_TEST("%d %d", 1, 1);                          )
-    CHAZ_QUOTE(      return 0;                                         )
-    CHAZ_QUOTE(  }                                                     );
+    CHAZ_QUOTE(  void f() { GNU_TEST("%d %d", 1, 1); }                 );
 
 void
 chaz_VariadicMacros_run(void) {
-    char *output;
-    size_t output_len;
     int has_varmacros = false;
 
     chaz_ConfWriter_start_module("VariadicMacros");
 
     /* Test for ISO-style variadic macros. */
-    output = chaz_CC_capture_output(chaz_VariadicMacros_iso_code, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_compile(chaz_VariadicMacros_iso_code)) {
         has_varmacros = true;
         chaz_ConfWriter_add_def("HAS_VARIADIC_MACROS", NULL);
         chaz_ConfWriter_add_def("HAS_ISO_VARIADIC_MACROS", NULL);
-        free(output);
     }
 
     /* Test for GNU-style variadic macros. */
-    output = chaz_CC_capture_output(chaz_VariadicMacros_gnuc_code, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_compile(chaz_VariadicMacros_gnuc_code)) {
         if (has_varmacros == false) {
             has_varmacros = true;
             chaz_ConfWriter_add_def("HAS_VARIADIC_MACROS", NULL);
         }
         chaz_ConfWriter_add_def("HAS_GNUC_VARIADIC_MACROS", NULL);
-        free(output);
     }
 
     chaz_ConfWriter_end_module();


[9/9] lucy-charmonizer git commit: Set CC and LINK variables in Makefile

Posted by nw...@apache.org.
Set CC and LINK variables in Makefile

Before, CC was set by Clownfish's and Lucy's charmonizer.main.

The LINK variable makes is easier to change the link command manually.


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

Branch: refs/heads/master
Commit: 34d27faa4aa332bdf06fa36fbf4e4136f8facba0
Parents: d8e3d93
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 23:28:50 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/Make.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/34d27faa/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index cebacd5..2ea2c7c 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -394,7 +394,6 @@ chaz_MakeFile_add_exe(chaz_MakeFile *self, const char *dir,
 
 void
 S_chaz_MakeFile_finish_exe(chaz_MakeFile *self, chaz_MakeBinary *binary) {
-    const char *link = chaz_CC_link_command();
     const char *link_flags_string;
     char *command;
 
@@ -409,8 +408,8 @@ S_chaz_MakeFile_finish_exe(chaz_MakeFile *self, chaz_MakeBinary *binary) {
     /* Objects in dollar var must come before flags since flags may
      * contain libraries.
      */
-    command = chaz_Util_join(" ", link, binary->dollar_var, link_flags_string,
-                             NULL);
+    command = chaz_Util_join(" ", "$(LINK)", binary->dollar_var,
+                             link_flags_string, NULL);
     chaz_MakeRule_add_command(binary->rule, command);
     free(command);
 }
@@ -446,7 +445,6 @@ chaz_MakeFile_add_shared_lib(chaz_MakeFile *self, const char *dir,
 void
 S_chaz_MakeFile_finish_shared_lib(chaz_MakeFile *self,
                                   chaz_MakeBinary *binary) {
-    const char *link = chaz_CC_link_command();
     const char *link_flags_string;
     int binfmt = chaz_CC_binary_format();
     char *no_v_name
@@ -471,8 +469,8 @@ S_chaz_MakeFile_finish_shared_lib(chaz_MakeFile *self,
     chaz_CFlags_set_link_output(binary->link_flags, "$@");
     link_flags_string = chaz_CFlags_get_string(binary->link_flags);
 
-    command = chaz_Util_join(" ", link, binary->dollar_var, link_flags_string,
-                             NULL);
+    command = chaz_Util_join(" ", "$(LINK)", binary->dollar_var,
+                             link_flags_string, NULL);
     chaz_MakeRule_add_command(binary->rule, command);
     free(command);
 
@@ -656,6 +654,9 @@ chaz_MakeFile_write(chaz_MakeFile *self) {
         fprintf(out, "SHELL = cmd\n");
     }
 
+    fprintf(out, "CC = %s\n", chaz_CC_get_cc());
+    fprintf(out, "LINK = %s\n", chaz_CC_link_command());
+
     for (i = 0; self->vars[i]; i++) {
         chaz_MakeVar *var = self->vars[i];
         fprintf(out, "%s = %s\n", var->name, var->value);


[4/9] lucy-charmonizer git commit: Compile-only LargeFiles probes

Posted by nw...@apache.org.
Compile-only LargeFiles probes


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

Branch: refs/heads/master
Commit: cb8761f227706edcf2e3243658c932d4afd76edd
Parents: 7576ef3
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 18:17:22 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Probe/LargeFiles.c | 54 +++++++--------------------------
 1 file changed, 11 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/cb8761f2/src/Charmonizer/Probe/LargeFiles.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/LargeFiles.c b/src/Charmonizer/Probe/LargeFiles.c
index fe5e1fa..5179bb3 100644
--- a/src/Charmonizer/Probe/LargeFiles.c
+++ b/src/Charmonizer/Probe/LargeFiles.c
@@ -118,12 +118,7 @@ static int
 chaz_LargeFiles_probe_off64(void) {
     static const char off64_code[] =
         CHAZ_QUOTE(  %s                                        )
-        CHAZ_QUOTE(  #include <stdio.h>                        )
-        CHAZ_QUOTE(  int main()                                )
-        CHAZ_QUOTE(  {                                         )
-        CHAZ_QUOTE(      printf("%%d", (int)sizeof(%s));       )
-        CHAZ_QUOTE(      return 0;                             )
-        CHAZ_QUOTE(  }                                         );
+        CHAZ_QUOTE(  int a[sizeof(%s)==8?1:-1];                );
     char code_buf[sizeof(off64_code) + 100];
     int i;
     int success = false;
@@ -137,8 +132,6 @@ chaz_LargeFiles_probe_off64(void) {
 
     for (i = 0; i < num_off64_options; i++) {
         const char *candidate = off64_options[i];
-        char *output;
-        size_t output_len;
         int has_sys_types_h = chaz_HeadCheck_check_header("sys/types.h");
         const char *sys_types_include = has_sys_types_h
                                         ? "#include <sys/types.h>"
@@ -146,15 +139,10 @@ chaz_LargeFiles_probe_off64(void) {
 
         /* Execute the probe. */
         sprintf(code_buf, off64_code, sys_types_include, candidate);
-        output = chaz_CC_capture_output(code_buf, &output_len);
-        if (output != NULL) {
-            long sizeof_candidate = strtol(output, NULL, 10);
-            free(output);
-            if (sizeof_candidate == 8) {
-                strcpy(chaz_LargeFiles.off64_type, candidate);
-                success = true;
-                break;
-            }
+        if (chaz_CC_test_compile(code_buf)) {
+            strcpy(chaz_LargeFiles.off64_type, candidate);
+            success = true;
+            break;
         }
     }
     return success;
@@ -165,20 +153,13 @@ chaz_LargeFiles_try_stdio64(chaz_LargeFiles_stdio64_combo *combo) {
     static const char stdio64_code[] =
         CHAZ_QUOTE(  %s                                         )
         CHAZ_QUOTE(  #include <stdio.h>                         )
-        CHAZ_QUOTE(  int main() {                               )
-        CHAZ_QUOTE(      %s pos;                                )
-        CHAZ_QUOTE(      FILE *f;                               )
-        CHAZ_QUOTE(      f = %s("_charm_stdio64", "w");         )
-        CHAZ_QUOTE(      if (f == NULL) return -1;              )
-        CHAZ_QUOTE(      printf("%%d", (int)sizeof(%s));        )
-        CHAZ_QUOTE(      pos = %s(stdout);                      )
-        CHAZ_QUOTE(      %s(stdout, 0, SEEK_SET);               )
-        CHAZ_QUOTE(      return 0;                              )
+        CHAZ_QUOTE(  int a[sizeof(%s)==8?1:-1];                 )
+        CHAZ_QUOTE(  void f() {                                 )
+        CHAZ_QUOTE(      FILE *f = %s("_charm_stdio64", "w");   )
+        CHAZ_QUOTE(      %s pos = %s(f);                        )
+        CHAZ_QUOTE(      %s(f, 0, SEEK_SET);                    )
         CHAZ_QUOTE(  }                                          );
-    char *output = NULL;
-    size_t output_len;
     char code_buf[sizeof(stdio64_code) + 200];
-    int success = false;
 
     /* Prepare the source code. */
     sprintf(code_buf, stdio64_code, combo->includes,
@@ -187,20 +168,7 @@ chaz_LargeFiles_try_stdio64(chaz_LargeFiles_stdio64_combo *combo) {
             combo->fseek_command);
 
     /* Verify compilation and that the offset type has 8 bytes. */
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
-        long size = strtol(output, NULL, 10);
-        if (size == 8) {
-            success = true;
-        }
-        free(output);
-    }
-
-    if (!chaz_Util_remove_and_verify("_charm_stdio64")) {
-        chaz_Util_die("Failed to remove '_charm_stdio64'");
-    }
-
-    return success;
+    return chaz_CC_test_compile(code_buf);
 }
 
 static void


[3/9] lucy-charmonizer git commit: Detect integer sizes without running executables

Posted by nw...@apache.org.
Detect integer sizes without running executables

Try to compile test code for sizes 1, 2, 4, 8 that only succeeds if a
type has a certain size. The test code contains an array declaration
of the form:

    int a[sizeof(type) == size ? 1 : -1];

The array size is a valid constant expression but produces a
compilation error unless the the size of the type matches. This makes
it possible to determine the size of types without executing any test
programs when cross-compiling.

Inspired by Autoconf's AC_CHECK_SIZEOF.


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

Branch: refs/heads/master
Commit: 7740918976c0ba5b5ffee73fa11c7dfd54e8a91b
Parents: b978797
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 17:47:32 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/HeaderChecker.c | 38 ++++++++++++++++++++
 src/Charmonizer/Core/HeaderChecker.h |  8 +++++
 src/Charmonizer/Probe/Integers.c     | 60 ++++++-------------------------
 3 files changed, 57 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/77409189/src/Charmonizer/Core/HeaderChecker.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/HeaderChecker.c b/src/Charmonizer/Core/HeaderChecker.c
index a2b46db..eaf9663 100644
--- a/src/Charmonizer/Core/HeaderChecker.c
+++ b/src/Charmonizer/Core/HeaderChecker.c
@@ -173,6 +173,44 @@ chaz_HeadCheck_contains_member(const char *struct_name, const char *member,
     return retval;
 }
 
+int
+chaz_HeadCheck_size_of_type(const char *type, const char *includes, int hint) {
+    static const char sizeof_code[] =
+        CHAZ_QUOTE(  #include <stddef.h>                           )
+        CHAZ_QUOTE(  %s                                            )
+        CHAZ_QUOTE(  int a[sizeof(%s)==%d?1:-1];                   );
+    size_t needed = sizeof(sizeof_code)
+                    + strlen(type)
+                    + strlen(includes)
+                    + 10;
+    char *buf = (char*)malloc(needed);
+    static const int sizes[] = { 4, 8, 2, 1 };
+    int retval = 0;
+    int i;
+
+    for (i = -1; i < (int)(sizeof(sizes) / sizeof(sizes[0])); i++) {
+        int size;
+
+        if (i < 0) {
+            if (hint != 0) { size = hint; }
+            else           { continue; }
+        }
+        else {
+            if (sizes[i] != hint) { size = sizes[i]; }
+            else                  { continue; }
+        }
+
+        sprintf(buf, sizeof_code, includes, type, size);
+        if (chaz_CC_test_compile(buf)) {
+            retval = size;
+            break;
+        }
+    }
+
+    free(buf);
+    return retval;
+}
+
 static int
 chaz_HeadCheck_compare_headers(const void *vptr_a, const void *vptr_b) {
     chaz_CHeader *const *const a = (chaz_CHeader*const*)vptr_a;

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/77409189/src/Charmonizer/Core/HeaderChecker.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/HeaderChecker.h b/src/Charmonizer/Core/HeaderChecker.h
index e7c14cb..1f8110d 100644
--- a/src/Charmonizer/Core/HeaderChecker.h
+++ b/src/Charmonizer/Core/HeaderChecker.h
@@ -53,6 +53,14 @@ int
 chaz_HeadCheck_contains_member(const char *struct_name, const char *member,
                                const char *includes);
 
+/*
+ * Return the size of the type or 0 if can't be determined. Only checks for
+ * sizes 1, 2, 4, 8. If hint != 0, try this size first to speed up the
+ * detection.
+ */
+int
+chaz_HeadCheck_size_of_type(const char *type, const char *includes, int hint);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/77409189/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Integers.c b/src/Charmonizer/Probe/Integers.c
index c680141..6ae12a0 100644
--- a/src/Charmonizer/Probe/Integers.c
+++ b/src/Charmonizer/Probe/Integers.c
@@ -28,30 +28,10 @@
 static int
 chaz_Integers_machine_is_big_endian(void);
 
-static const char chaz_Integers_sizes_code[] =
-    CHAZ_QUOTE(  #include <stdio.h>                        )
-    CHAZ_QUOTE(  int main () {                             )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(char));     )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(short));    )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(int));      )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(long));     )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(void*));    )
-    CHAZ_QUOTE(      printf("%d ", (int)sizeof(size_t));   )
-    CHAZ_QUOTE(      return 0;                             )
-    CHAZ_QUOTE(  }                                         );
-
 static const char chaz_Integers_stdint_type_code[] =
     CHAZ_QUOTE(  #include <stdint.h>                       )
     CHAZ_QUOTE(  %s i;                                     );
 
-static const char chaz_Integers_type64_code[] =
-    CHAZ_QUOTE(  #include <stdio.h>                        )
-    CHAZ_QUOTE(  int main()                                )
-    CHAZ_QUOTE(  {                                         )
-    CHAZ_QUOTE(      printf("%%d", (int)sizeof(%s));       )
-    CHAZ_QUOTE(      return 0;                             )
-    CHAZ_QUOTE(  }                                         );
-
 static const char chaz_Integers_literal64_code[] =
     CHAZ_QUOTE(  int f() { return (int)9000000000000000000%s; }  );
 
@@ -98,42 +78,24 @@ chaz_Integers_run(void) {
     }
 
     /* Record sizeof() for several common integer types. */
-    output = chaz_CC_capture_output(chaz_Integers_sizes_code, &output_len);
-    if (output != NULL) {
-        char *ptr     = output;
-        char *end_ptr = output;
-
-        sizeof_char   = strtol(ptr, &end_ptr, 10);
-        ptr           = end_ptr;
-        sizeof_short  = strtol(ptr, &end_ptr, 10);
-        ptr           = end_ptr;
-        sizeof_int    = strtol(ptr, &end_ptr, 10);
-        ptr           = end_ptr;
-        sizeof_long   = strtol(ptr, &end_ptr, 10);
-        ptr           = end_ptr;
-        sizeof_ptr    = strtol(ptr, &end_ptr, 10);
-        ptr           = end_ptr;
-        sizeof_size_t = strtol(ptr, &end_ptr, 10);
-
-        free(output);
-    }
+    sizeof_char   = chaz_HeadCheck_size_of_type("char",  "", 1);
+    sizeof_short  = chaz_HeadCheck_size_of_type("short", "", 2);
+    sizeof_int    = chaz_HeadCheck_size_of_type("int",   "", 4);
+    sizeof_long   = chaz_HeadCheck_size_of_type("long",  "", 4);
+    sizeof_ptr    = chaz_HeadCheck_size_of_type("void*", "", 4);
+    sizeof_size_t = chaz_HeadCheck_size_of_type("size_t",
+                                                "#include <stddef.h>", 4);
 
     /* Determine whether long longs are available. */
-    sprintf(code_buf, chaz_Integers_type64_code, "long long");
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_compile("long long l;")) {
         has_long_long    = true;
-        sizeof_long_long = strtol(output, NULL, 10);
-        free(output);
+        sizeof_long_long = chaz_HeadCheck_size_of_type("long long", "", 8);
     }
 
     /* Determine whether the __int64 type is available. */
-    sprintf(code_buf, chaz_Integers_type64_code, "__int64");
-    output = chaz_CC_capture_output(code_buf, &output_len);
-    if (output != NULL) {
+    if (chaz_CC_test_compile("__int64 i;")) {
         has___int64 = true;
-        sizeof___int64 = strtol(output, NULL, 10);
-        free(output);
+        sizeof___int64 = chaz_HeadCheck_size_of_type("__int64", "", 8);
     }
 
     /* Determine whether the intptr_t type is available (it's optional in


[5/9] lucy-charmonizer git commit: Don't run 64-bit format string probe under C99

Posted by nw...@apache.org.
Don't run 64-bit format string probe under C99

Feature tests for format strings can't be compile-only but require
execution of a test program which breaks when cross-compiling. But if
C99's inttypes.h is available, there's no need for a probe at all.


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

Branch: refs/heads/master
Commit: bf0164464849fa7872d0805fba617e78299dc6d3
Parents: 7740918
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Feb 3 17:56:07 2017 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Feb 4 18:10:18 2017 +0100

----------------------------------------------------------------------
 src/Charmonizer/Probe/Integers.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/bf016446/src/Charmonizer/Probe/Integers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Integers.c b/src/Charmonizer/Probe/Integers.c
index 6ae12a0..885dd59 100644
--- a/src/Charmonizer/Probe/Integers.c
+++ b/src/Charmonizer/Probe/Integers.c
@@ -174,7 +174,7 @@ chaz_Integers_run(void) {
     }
 
     /* Probe for 64-bit printf format string modifier. */
-    if (has_64) {
+    if (!has_inttypes && has_64) {
         int i;
         const char *options[] = {
             "ll",
@@ -503,7 +503,7 @@ chaz_Integers_run(void) {
         chaz_ConfWriter_add_sys_include("inttypes.h");
     }
 
-    {
+    if (!has_inttypes || !has_intptr_t) {
         /* We support only the following subset of inttypes.h
          *   PRId32
          *   PRIi32
@@ -540,10 +540,9 @@ chaz_Integers_run(void) {
             int c = ptr[0];
 
             if (has_32) {
-                sprintf(scratch, "\"%s%c\"", printf_modifier_32, c);
-
+                macro_name_32[3] = c;
                 if (!has_inttypes) {
-                    macro_name_32[3] = c;
+                    sprintf(scratch, "\"%s%c\"", printf_modifier_32, c);
                     chaz_ConfWriter_add_global_def(macro_name_32, scratch);
                     if (!has_64) {
                         macro_name_max[3] = c;
@@ -553,21 +552,22 @@ chaz_Integers_run(void) {
                 }
                 if (!has_intptr_t && sizeof_ptr == 4) {
                     macro_name_ptr[3] = c;
-                    chaz_ConfWriter_add_global_def(macro_name_ptr, scratch);
+                    chaz_ConfWriter_add_global_def(macro_name_ptr,
+                                                   macro_name_32);
                 }
             }
             if (has_64) {
-                sprintf(scratch, "\"%s%c\"", printf_modifier_64, c);
-
+                macro_name_64[3] = c;
                 if (!has_inttypes) {
-                    macro_name_64[3] = c;
+                    sprintf(scratch, "\"%s%c\"", printf_modifier_64, c);
                     chaz_ConfWriter_add_global_def(macro_name_64, scratch);
                     macro_name_max[3] = c;
                     chaz_ConfWriter_add_global_def(macro_name_max, scratch);
                 }
                 if (!has_intptr_t && sizeof_ptr == 8) {
                     macro_name_ptr[3] = c;
-                    chaz_ConfWriter_add_global_def(macro_name_ptr, scratch);
+                    chaz_ConfWriter_add_global_def(macro_name_ptr,
+                                                   macro_name_64);
                 }
             }
         }