From d99d1b90f84bdf5842281267a77cc7c1334cc67b Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 21 Jun 2014 12:34:26 -0700 Subject: [PATCH] Add a get_compiler_info() routine in libwsutil to get compiler information. Change-Id: I8ccb6187f2ee0255460f448aee170768b6fa3f5d Reviewed-on: https://code.wireshark.org/review/2519 Reviewed-by: Guy Harris --- version_info.c | 77 +---------------------------- wsutil/CMakeLists.txt | 1 + wsutil/Makefile.common | 2 + wsutil/compiler_info.c | 110 +++++++++++++++++++++++++++++++++++++++++ wsutil/compiler_info.h | 39 +++++++++++++++ 5 files changed, 154 insertions(+), 75 deletions(-) create mode 100644 wsutil/compiler_info.c create mode 100644 wsutil/compiler_info.h diff --git a/version_info.c b/version_info.c index 6403a87fe7..67d4139b76 100644 --- a/version_info.c +++ b/version_info.c @@ -36,6 +36,7 @@ #include #include #include +#include #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); } diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index e344fd205f..a08787a1c7 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -45,6 +45,7 @@ set(WSUTIL_FILES base64.c bitswap.c cfutils.c + compiler_info.c copyright_info.c crash_info.c crc10.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index ff747ea5cb..f040ea57d3 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -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 index 0000000000..df77e5c425 --- /dev/null +++ b/wsutil/compiler_info.c @@ -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 + * 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 + +#include + +/* + * 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 index 0000000000..e64175d4de --- /dev/null +++ b/wsutil/compiler_info.h @@ -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 + * 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__ */