From d4ff9ce39fe434ccc52a7ae5ba695a646eb659a4 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Fri, 30 Aug 2013 12:09:50 +0000 Subject: [PATCH] Improve feature detection. Add V8_GLIBC_PREREQ() macro to test the version of the GNU C library. Make V8_GNUC_PREREQ() work for compilers that masquerade as GCC (you can always use V8_CC_* to test for a specific one if you need to). Add V8_LIBC_* to detect the C library in use. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/23717009 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16450 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8config.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/include/v8config.h b/include/v8config.h index 2bf3b9d..b2e659a 100644 --- a/include/v8config.h +++ b/include/v8config.h @@ -28,6 +28,52 @@ #ifndef V8CONFIG_H_ #define V8CONFIG_H_ +// Platform headers for feature detection below. +#if defined(__ANDROID__) +# include +#elif defined(__APPLE__) +# include +#elif defined(__linux__) +# include +#endif + + +// This macro allows to test for the version of the GNU C library (or +// a compatible C library that masquerades as glibc). It evaluates to +// 0 if libc is not GNU libc or compatible. +// Use like: +// #if V8_GLIBC_PREREQ(2, 3) +// ... +// #endif +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define V8_GLIBC_PREREQ(major, minor) \ + ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor))) +#else +# define V8_GLIBC_PREREQ(major, minor) 0 +#endif + + +// This macro allows to test for the version of the GNU C++ compiler. +// Note that this also applies to compilers that masquerade as GCC, +// for example clang and the Intel C++ compiler for Linux. +// Use like: +// #if V8_GNUC_PREREQ(4, 3, 1) +// ... +// #endif +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define V8_GNUC_PREREQ(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ + ((major) * 10000 + (minor) * 100 + (patchlevel))) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) +# define V8_GNUC_PREREQ(major, minor, patchlevel) \ + ((__GNUC__ * 10000 + __GNUC_MINOR__) >= \ + ((major) * 10000 + (minor) * 100 + (patchlevel))) +#else +# define V8_GNUC_PREREQ(major, minor, patchlevel) 0 +#endif + + + // ----------------------------------------------------------------------------- // Operating system detection // @@ -87,6 +133,32 @@ // ----------------------------------------------------------------------------- +// C library detection +// +// V8_LIBC_BIONIC - Bionic libc +// V8_LIBC_BSD - BSD libc derivate +// V8_LIBC_GLIBC - GNU C library +// V8_LIBC_UCLIBC - uClibc +// +// Note that testing for libc must be done using #if not #ifdef. For example, +// to test for the GNU C library, use: +// #if V8_LIBC_GLIBC +// ... +// #endif + +#if defined(__BIONIC__) +# define V8_LIBC_BIONIC 1 +# define V8_LIBC_BSD 1 +#elif defined(__UCLIBC__) +# define V8_LIBC_UCLIBC 1 +#elif defined(__GLIBC__) || defined(__GNU_LIBRARY__) +# define V8_LIBC_GLIBC 1 +#else +# define V8_LIBC_BSD V8_OS_BSD +#endif + + +// ----------------------------------------------------------------------------- // Compiler detection // // V8_CC_CLANG - Clang @@ -134,9 +206,6 @@ #if defined(__clang__) -// Don't treat clang as GCC. -# define V8_GNUC_PREREQ(major, minor, patchlevel) 0 - # define V8_CC_CLANG 1 // Clang defines __alignof__ as alias for __alignof @@ -161,10 +230,6 @@ #elif defined(__GNUC__) -# define V8_GNUC_PREREQ(major, minor, patchlevel) \ - ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ - ((major) * 10000 + (minor) * 100 + (patchlevel))) - # define V8_CC_GNU 1 // Intel C++ also masquerades as GCC 3.2.0 # define V8_CC_INTEL (defined(__INTEL_COMPILER)) @@ -207,8 +272,6 @@ #elif defined(_MSC_VER) -# define V8_GNUC_PREREQ(major, minor, patchlevel) 0 - # define V8_CC_MSVC 1 # define V8_HAS___ALIGNOF 1 -- 2.7.4