Add a get_compiler_info() routine in libwsutil to get compiler information.
authorGuy Harris <guy@alum.mit.edu>
Sat, 21 Jun 2014 19:34:26 +0000 (12:34 -0700)
committerGuy Harris <guy@alum.mit.edu>
Sat, 21 Jun 2014 19:35:06 +0000 (19:35 +0000)
Change-Id: I8ccb6187f2ee0255460f448aee170768b6fa3f5d
Reviewed-on: https://code.wireshark.org/review/2519
Reviewed-by: Guy Harris <guy@alum.mit.edu>
version_info.c
wsutil/CMakeLists.txt
wsutil/Makefile.common
wsutil/compiler_info.c [new file with mode: 0644]
wsutil/compiler_info.h [new file with mode: 0644]

index 6403a87fe7581cd4440c9405ba55b6f0f74769be..67d4139b76cb0292762caff06ccb1e780a36d9f9 100644 (file)
@@ -36,6 +36,7 @@
 #include <wsutil/unicode-utils.h>
 #include <wsutil/ws_cpuid.h>
 #include <wsutil/os_version_info.h>
+#include <wsutil/compiler_info.h>
 
 #include "version.h"
 
@@ -262,81 +263,7 @@ get_runtime_version_info(GString *str, void (*additional_info)(GString *))
        get_mem_info(str);
 
        /* Compiler info */
-
-       /*
-        * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
-        * information on various defined strings.
-        *
-        * GCC's __VERSION__ is a nice text string for humans to
-        * read.  The page at sourceforge.net largely describes
-        * numeric #defines that encode the version; if the compiler
-        * doesn't also offer a nice printable string, we try prettifying
-        * the number somehow.
-        */
-#if defined(__GNUC__) && defined(__VERSION__)
-       /*
-        * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
-        * distinguish between them.
-        */
-#if defined(__clang__)
-       g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
-#elif defined(__llvm__)
-       g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
-#else /* boring old GCC */
-       g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
-#endif /* llvm */
-#elif defined(__HP_aCC)
-       g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
-#elif defined(__xlC__)
-       g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
-           (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
-#ifdef __IBMC__
-       if ((__IBMC__ % 10) != 0)
-               g_string_append_printf(str, " patch %d", __IBMC__ % 10);
-#endif /* __IBMC__ */
-       g_string_append_printf(str, "\n");
-#elif defined(__INTEL_COMPILER)
-       g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
-           __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
-       if ((__INTEL_COMPILER % 10) != 0)
-               g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
-#ifdef __INTEL_COMPILER_BUILD_DATE
-       g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
-           __INTEL_COMPILER_BUILD_DATE / 10000,
-           (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
-           __INTEL_COMPILER_BUILD_DATE % 100);
-#endif /* __INTEL_COMPILER_BUILD_DATE */
-       g_string_append_printf(str, "\n");
-#elif defined(_MSC_FULL_VER)
-# if _MSC_FULL_VER > 99999999
-       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
-                              (_MSC_FULL_VER / 10000000) - 6,
-                              (_MSC_FULL_VER / 100000) % 100);
-#  if (_MSC_FULL_VER % 100000) != 0
-       g_string_append_printf(str, " build %d",
-                              _MSC_FULL_VER % 100000);
-#  endif
-# else
-       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
-                              (_MSC_FULL_VER / 1000000) - 6,
-                              (_MSC_FULL_VER / 10000) % 100);
-#  if (_MSC_FULL_VER % 10000) != 0
-       g_string_append_printf(str, " build %d",
-                              _MSC_FULL_VER % 10000);
-#  endif
-# endif
-       g_string_append_printf(str, "\n");
-#elif defined(_MSC_VER)
-       /* _MSC_FULL_VER not defined, but _MSC_VER defined */
-       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
-           (_MSC_VER / 100) - 6, _MSC_VER % 100);
-#elif defined(__SUNPRO_C)
-       g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
-           (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
-       if ((__SUNPRO_C & 0xF) != 0)
-               g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
-       g_string_append_printf(str, "\n");
-#endif
+       get_compiler_info(str);
 
        end_string(str);
 }
index e344fd205f99213d70b987dbb377d8b19742fbfc..a08787a1c7e6389ddad9e65cc20a26e60a492d43 100644 (file)
@@ -45,6 +45,7 @@ set(WSUTIL_FILES
        base64.c
        bitswap.c
        cfutils.c
+       compiler_info.c
        copyright_info.c
        crash_info.c
        crc10.c
index ff747ea5cb51d7d1bc8b1db60be262d5df596535..f040ea57d31ba5ec3033549d0b3bb286ae37d676 100644 (file)
@@ -33,6 +33,7 @@ LIBWSUTIL_SRC =       \
        base64.c        \
        bitswap.c       \
        cfutils.c       \
+       compiler_info.c \
        copyright_info.c \
        crash_info.c    \
        crc6.c          \
@@ -77,6 +78,7 @@ LIBWSUTIL_INCLUDES =  \
        bits_count_ones.h       \
        bitswap.h               \
        cfutils.h       \
+       compiler_info.h \
        copyright_info.h \
        crash_info.h    \
        crc6.h          \
diff --git a/wsutil/compiler_info.c b/wsutil/compiler_info.c
new file mode 100644 (file)
index 0000000..df77e5c
--- /dev/null
@@ -0,0 +1,110 @@
+/* compiler_info.c
+ * Routines to report information about the compiler used to compile
+ * Wireshark
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include <wsutil/compiler_info.h>
+
+/*
+ * Get compiler information, and append it to the GString.
+ */
+void
+get_compiler_info(GString *str)
+{
+       /*
+        * See https://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
+        * information on various defined strings.
+        *
+        * GCC's __VERSION__ is a nice text string for humans to
+        * read.  The page at sourceforge.net largely describes
+        * numeric #defines that encode the version; if the compiler
+        * doesn't also offer a nice printable string, we try prettifying
+        * the number somehow.
+        */
+#if defined(__GNUC__) && defined(__VERSION__)
+       /*
+        * Clang and llvm-gcc also define __GNUC__ and __VERSION__;
+        * distinguish between them.
+        */
+#if defined(__clang__)
+       g_string_append_printf(str, "\n\nBuilt using clang %s.\n", __VERSION__);
+#elif defined(__llvm__)
+       g_string_append_printf(str, "\n\nBuilt using llvm-gcc %s.\n", __VERSION__);
+#else /* boring old GCC */
+       g_string_append_printf(str, "\n\nBuilt using gcc %s.\n", __VERSION__);
+#endif /* llvm */
+#elif defined(__HP_aCC)
+       g_string_append_printf(str, "\n\nBuilt using HP aCC %d.\n", __HP_aCC);
+#elif defined(__xlC__)
+       g_string_append_printf(str, "\n\nBuilt using IBM XL C %d.%d\n",
+           (__xlC__ >> 8) & 0xFF, __xlC__ & 0xFF);
+#ifdef __IBMC__
+       if ((__IBMC__ % 10) != 0)
+               g_string_append_printf(str, " patch %d", __IBMC__ % 10);
+#endif /* __IBMC__ */
+       g_string_append_printf(str, "\n");
+#elif defined(__INTEL_COMPILER)
+       g_string_append_printf(str, "\n\nBuilt using Intel C %d.%d",
+           __INTEL_COMPILER / 100, (__INTEL_COMPILER / 10) % 10);
+       if ((__INTEL_COMPILER % 10) != 0)
+               g_string_append_printf(str, " patch %d", __INTEL_COMPILER % 10);
+#ifdef __INTEL_COMPILER_BUILD_DATE
+       g_string_sprinta(str, ", compiler built %04d-%02d-%02d",
+           __INTEL_COMPILER_BUILD_DATE / 10000,
+           (__INTEL_COMPILER_BUILD_DATE / 100) % 100,
+           __INTEL_COMPILER_BUILD_DATE % 100);
+#endif /* __INTEL_COMPILER_BUILD_DATE */
+       g_string_append_printf(str, "\n");
+#elif defined(_MSC_FULL_VER)
+# if _MSC_FULL_VER > 99999999
+       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
+                              (_MSC_FULL_VER / 10000000) - 6,
+                              (_MSC_FULL_VER / 100000) % 100);
+#  if (_MSC_FULL_VER % 100000) != 0
+       g_string_append_printf(str, " build %d",
+                              _MSC_FULL_VER % 100000);
+#  endif
+# else
+       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d",
+                              (_MSC_FULL_VER / 1000000) - 6,
+                              (_MSC_FULL_VER / 10000) % 100);
+#  if (_MSC_FULL_VER % 10000) != 0
+       g_string_append_printf(str, " build %d",
+                              _MSC_FULL_VER % 10000);
+#  endif
+# endif
+       g_string_append_printf(str, "\n");
+#elif defined(_MSC_VER)
+       /* _MSC_FULL_VER not defined, but _MSC_VER defined */
+       g_string_append_printf(str, "\n\nBuilt using Microsoft Visual C++ %d.%d\n",
+           (_MSC_VER / 100) - 6, _MSC_VER % 100);
+#elif defined(__SUNPRO_C)
+       g_string_append_printf(str, "\n\nBuilt using Sun C %d.%d",
+           (__SUNPRO_C >> 8) & 0xF, (__SUNPRO_C >> 4) & 0xF);
+       if ((__SUNPRO_C & 0xF) != 0)
+               g_string_append_printf(str, " patch %d", __SUNPRO_C & 0xF);
+       g_string_append_printf(str, "\n");
+#endif
+}
diff --git a/wsutil/compiler_info.h b/wsutil/compiler_info.h
new file mode 100644 (file)
index 0000000..e64175d
--- /dev/null
@@ -0,0 +1,39 @@
+/* compiler_info.h
+ * Declarations of outines to report information about the compiler used
+ * to compile Wireshark
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __WSUTIL_COMPILER_INFO_H__
+#define __WSUTIL_COMPILER_INFO_H__
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+WS_DLL_PUBLIC void get_compiler_info(GString *str);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __WSUTIL_COMPILER_INFO_H__ */