diff options
Diffstat (limited to 'mbglib/common/mbg_tgt.h')
-rw-r--r-- | mbglib/common/mbg_tgt.h | 360 |
1 files changed, 310 insertions, 50 deletions
diff --git a/mbglib/common/mbg_tgt.h b/mbglib/common/mbg_tgt.h index 708d76a..3c18952 100644 --- a/mbglib/common/mbg_tgt.h +++ b/mbglib/common/mbg_tgt.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_tgt.h 1.22 2009/10/01 08:20:50 martin REL_M $ + * $Id: mbg_tgt.h 1.34 2015/03/03 13:32:49 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,9 +11,47 @@ * * ----------------------------------------------------------------------- * $Log: mbg_tgt.h $ + * Revision 1.34 2015/03/03 13:32:49 martin + * Provide __func__ for MS Visual Studio. + * Revision 1.33 2015/03/02 11:27:59Z martin + * Windows only: + * Define _CRT_SECURE_NO_WARNINGS to quiet compiler warnings. + * Define WIN32_LEAN_AND_MEAN only if it hasn't been defined before. + * Revision 1.32 2014/06/24 09:21:44 martin + * Update for newer C++Builder versions. + * Revision 1.31 2014/05/27 10:23:33 martin + * Finer control of which types are required for or already + * available on particular target systems. + * First definitions to support SunOS/Solaris. + * Revision 1.30 2014/04/01 12:55:58 martin + * Define MBG_TGT_WIN32 also for MS resource compiler. + * New target MBG_TGT_POSIX. + * Always include winsock2.h and windows.h for MBG_TGT_WIN32. + * Always include unistd.h for MBG_TGT_POSIX. + * Define empty __attribute__ macro for non-gcc environments. + * Revision 1.29 2013/02/01 14:50:46 martin + * Fixed a typo which caused an error under Borland CBuilder 5. + * Revision 1.28 2012/12/12 10:03:16Z martin + * Fix for Borland C 3.1. + * Revision 1.27 2012/11/29 12:03:14Z martin + * Moved definition of _no_macro_fnc() to words.h. + * Revision 1.26 2012/11/02 09:01:47Z martin + * Merged some stuff depending on the build environment here + * and cleaned up. + * Revision 1.25 2012/04/04 07:17:18 martin + * Treat QNX Neutrino as Unix target. + * Revision 1.24 2011/08/23 10:21:23 martin + * New symbol _NO_MBG_API_ATTR which can be used with functions + * which are going to be exported by a DLL, but actually aren't, yet. + * Revision 1.23 2011/08/19 10:47:00 martin + * Don't include stddef.h. + * Distinguish between different gcc target platforms. + * Initial support for IA64 platform. + * Support wchar_t for BSD. + * Defined _NO_USE_PACK_INTF for Sparc and IA64. + * Fixed typo in comment. * Revision 1.22 2009/10/01 08:20:50 martin * Fixed inline code support with different BC versions. - * Revision 1.1 2009/11/20 12:24:05 philipp * Revision 1.21 2009/09/01 10:34:23Z martin * Don't define __mbg_inline for CVI and undefined targets. * Revision 1.20 2009/08/18 15:14:26 martin @@ -80,8 +118,6 @@ /* Other headers to be included */ -#include <stddef.h> - #ifdef _MBG_TGT #define _ext #else @@ -91,11 +127,16 @@ /* Start of header body */ -#if defined( _CVI ) || defined( _CVI_ ) +#if defined( _CVI_ ) - #define MBG_TGT_WIN32 #define MBG_TGT_CVI + #if defined( _NI_mswin_ ) + #define MBG_TGT_WIN32 + #else + #error Unsupported CVI target platform. + #endif + #elif defined( _WIN32_WINNT ) // MS platform SDK @@ -131,6 +172,11 @@ // MS Visual C++ #define MBG_TGT_WIN32 +#elif defined( RC_INVOKED ) + + //MS resource compiler + #define MBG_TGT_WIN32 + #elif defined( __WINDOWS_386__ ) // Watcom C/C++ for target Win32 @@ -152,6 +198,10 @@ #define MBG_TGT_LINUX #define _GNU_SOURCE 1 + #if defined( __KERNEL__ ) + #define MBG_TGT_KERNEL + #endif + #elif defined( __FreeBSD__ ) // GCC for target FreeBSD @@ -164,9 +214,26 @@ #elif defined( __OpenBSD__ ) - // GCC for target FreeBSD + // GCC for target OpenBSD #define MBG_TGT_OPENBSD +#elif defined( __sun ) // Oracle Solaris or other SunOS derived operating system + + // __SUNPRO_C Oracle Solaris Studio C compiler, __SUNPRO_C value is the version number + // __SUNPRO_CC Oracle Solaris Studio C++ compiler, __SUNPRO_CC value is the version number + // __sparc generate code for SPARC (R) architecture (32-bit or 64-bit) + // __sparcv9 generate code for 64-bit SPARC architecture + // __i386 generate code for 32-bit x86 architecture + // __amd64 generate code for 64-bit x64 architecture + + #define MBG_TGT_SUNOS + + #define __mbg_inline __inline__ + + #include <stdint.h> + #include <stdbool.h> + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #elif defined( __QNX__ ) // any compiler for target QNX @@ -190,39 +257,211 @@ #endif -// Some definitions which depend on the type of compiler ... + + +#if defined( MBG_TGT_FREEBSD ) \ + || defined( MBG_TGT_NETBSD ) \ + || defined( MBG_TGT_OPENBSD ) + #define MBG_TGT_BSD + + #if defined( _KERNEL ) + #define MBG_TGT_KERNEL + #endif + +#endif + +#if defined( MBG_TGT_LINUX ) \ + || defined( MBG_TGT_BSD ) \ + || defined( MBG_TGT_SUNOS ) + #define MBG_TGT_POSIX + #define MBG_TGT_UNIX +#endif + + + +// Some definitions depending on the build environment ... #if defined( __GNUC__ ) - #define __mbg_inline __inline__ + #if defined( __i386__ ) - #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + #define MBG_ARCH_I386 + #define MBG_ARCH_X86 - #if defined( __sparc__ ) + #elif defined( __x86_64__ ) + + #define MBG_ARCH_X86_64 + #define MBG_ARCH_X86 + + #elif defined( __ia64__ ) + + #define MBG_ARCH_IA64 + + #define _NO_USE_PACK_INTF + + #elif defined( __sparc__ ) #define MBG_ARCH_SPARC - #define _MBG_ARCH_DEFINED + #define MBG_USE_MM_IO_FOR_PCI 1 + + #define _NO_USE_PACK_INTF #elif defined( __arm__ ) #define MBG_ARCH_ARM - #define _MBG_ARCH_DEFINED #endif + #if defined( MBG_TGT_LINUX ) + + #if defined( __KERNEL__ ) + + #include <linux/types.h> + #include <linux/version.h> + + #if ( LINUX_VERSION_CODE <= KERNEL_VERSION( 2, 6, 4 ) ) + #define _ULONG_DEFINED 1 + #define _USHORT_DEFINED 1 + #define _UINT_DEFINED 1 + #endif + + #else + + #include <sys/types.h> + #include <stdint.h> + #include <stdbool.h> + + #if defined( __u_char_defined ) + #define _ULONG_DEFINED 1 + #define _USHORT_DEFINED 1 + #define _UINT_DEFINED 1 + #endif + + #endif + + #elif defined( MBG_TGT_BSD ) + + #include <sys/types.h> + + #elif defined( MBG_TGT_QNX_NTO ) // QNX 6.x (Neutrino) + + #include <stdint.h> + #include <stdbool.h> + + #else + + #include <stdint.h> + #include <stdbool.h> + + #endif + + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + + #define MBG_TGT_HAS_WCHAR_T 1 + + #define __mbg_inline __inline__ + #elif defined( _MSC_VER ) + // Known predifined MS compiler version codes: + // 1700: MSVC++ 11.0 (Visual Studio 2012) + // 1600: MSVC++ 10.0 (Visual Studio 2010) + // 1500: MSVC++ 9.0 (Visual Studio 2008) + // 1400: MSVC++ 8.0 (Visual Studio 2005) + // 1310: MSVC++ 7.1 (Visual Studio 2003) + // 1300: MSVC++ 7.0 + // 1200: MSVC++ 6.0 + // 1100: MSVC++ 5.0 + + #if ( _MSC_VER >= 1600 ) + #include <stdint.h> + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #else + #define MBG_TGT_HAS_INT_8_16_32 1 + #endif + + // no bool support anyway + #define MBG_TGT_MISSING_BOOL_TYPE 1 + + #define MBG_TGT_HAS_WCHAR_T 1 + #define __mbg_inline __forceinline - #define MBG_TGT_HAS_WCHAR_T 1 + // At least up to VS2008 the builtin symbol __func__ + // is not supported, but __FUNCTION__ returns the name + // of the current function instead. + #define __func__ __FUNCTION__ -#elif defined( _CVI ) || defined( _CVI_ ) +#elif defined( _CVI_ ) - // Inline code is not supported. + // 1000 for CVI v10.0 (CVI 2010) + // 911 for CVI v9.1.1 (CVI 2009 SP1) + // 910 for CVI v9.1 (CVI 2009) + // 310 for CVI v3.1 + // 301 for CVI v3.0.1 + // 1 for CVI v3.0 - #define MBG_TGT_HAS_WCHAR_T 0 + #if ( _CVI_ >= 910 ) + // LabWindows/CVI 2009 is the first version providing stdint.h. + #include <stdint.h> + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #else + #define USE_LONG_FOR_INT32 1 + #endif -#elif defined( __BORLANDC__ ) + // As of LabWindows/CVI 2010, stdbool.h is still missing. + #define MBG_TGT_MISSING_BOOL_TYPE 1 + + #define MBG_TGT_HAS_WCHAR_T 0 + + // Inline code is not supported, though the inline keyword + // is silently accepted since CVI v9.0 + +#elif defined( __BORLANDC__ ) // or __CODEGEARC__ in newer versions + + // 0x0200 Borland C/C++ 2.0 + // 0x0400 Borland C/C++ 3.0 + // 0x0410 Borland C/C++ 3.1 + // 0x0550 Borland C/C++ 5.5 (C++Builder 5.0) + + // Next codes are in addition defined as __CODEGEARC__ + // See http://docwiki.embarcadero.com + + // 0x0570 for Borland Developer Studio 2006 (BDS 2006) + // 0x0590 for C++Builder 2007 + // 0x0591 for update 1 to C++Builder 2007 + // 0x0592 for RAD Studio 2007 + // 0x0593 for the December update to RAD Studio 2007 + // 0x0610 for C++Builder 2009 and for C++Builder 2009 Update 1 + // 0x0620 for C++Builder 2010 and for C++Builder 2010 Update 1 + // 0x0621 for C++Builder 2010 Update 2 + // 0x0630 for C++Builder XE + // 0x0631 for C++Builder XE Update 1 + // 0x0640 for C++Builder XE2 + // 0x0650 for C++Builder XE3 + + #if ( __BORLANDC__ >= 0x630 ) + // C++Builder XE starts to provide stdbool.h + #include <stdint.h> + #include <stdbool.h> + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #elif ( __BORLANDC__ >= 0x570 ) + // at least BDS 2006 starts to provide stdint.h + #include <stdint.h> + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 + #elif ( __BORLANDC__ >= 0x0550 ) + #define MBG_TGT_HAS_INT_8_16_32 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 + #else // e.g. BC 3.1 or earlier + #if ( __BORLANDC__ <= 0x410 ) + #define MBG_TGT_MISSING_64_BIT_TYPES 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 + #define USE_LONG_FOR_INT32 1 + #endif + #endif + + #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) #if defined( __cplusplus ) #define __mbg_inline inline // standard C++ syntax @@ -232,42 +471,46 @@ #define __mbg_inline // up to BC3.1 not supported for C #endif - #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) - #elif defined( __WATCOMC__ ) - #define __mbg_inline _inline + // 1050 v10.5 + // 1100 v11.0 + // 1200 Open Watcom C++ v1.0 + // 1230 Open Watcom C++ v1.3 + // 1270 Open Watcom C++ v1.7 - #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + #if defined( MBG_TGT_QNX ) // QNX 4.x -#endif + #include <sys/types.h> + #define MBG_TGT_MISSING_64_BIT_TYPES 1 + #elif ( __WATCOMC__ > 1230 ) // Open Watcom C 1.3 and above -// Currently we support only Sparc and i386/x86_64 architectures, -// so unless we have explicitely found sparc we assume i386. + #include <stdint.h> -#if !defined( _MBG_ARCH_DEFINED ) - #define MBG_ARCH_I386 -#endif + #elif !defined( __WATCOM_INT64__ ) // Watcom C 11 + #define MBG_TGT_MISSING_64_BIT_TYPES 1 -#if defined( MBG_TGT_FREEBSD ) \ - || defined( MBG_TGT_NETBSD ) \ - || defined( MBG_TGT_OPENBSD ) - #define MBG_TGT_BSD -#endif + #endif + + #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + + #define __mbg_inline _inline -#if defined( MBG_TGT_LINUX ) \ - || defined( MBG_TGT_BSD ) \ - || defined( MBG_TGT_QNX_NTO ) - #define MBG_TGT_UNIX #endif +#if !defined( __GNUC__ ) && !defined( __attribute__ ) + #define __attribute__( _x ) +#endif + #if defined( MBG_TGT_WIN32 ) + #define _CRT_SECURE_NO_WARNINGS + #if defined( _AMD64_ ) // This is used for AMD64 architecture and for // Intel XEON CPUs with 64 bit extension. @@ -279,10 +522,18 @@ #endif #if defined( _KDD_ ) + #define MBG_TGT_KERNEL #include <ntddk.h> #else // This must not be used for kernel drivers. + #if !defined( WIN32_LEAN_AND_MEAN ) + #define WIN32_LEAN_AND_MEAN 1 + #endif + + #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ + #include <winsock2.h> #include <windows.h> + typedef HANDLE MBG_HANDLE; #define MBG_INVALID_HANDLE INVALID_HANDLE_VALUE @@ -313,7 +564,11 @@ #define _MBG_API_ATTR __declspec( dllimport ) #endif -#elif defined( MBG_TGT_UNIX ) +#elif defined( MBG_TGT_POSIX ) + + #if !defined( MBG_TGT_KERNEL ) + #include <unistd.h> + #endif typedef int MBG_HANDLE; typedef int MBG_PORT_HANDLE; @@ -338,28 +593,33 @@ #define _MBG_API_ATTR #endif +#if !defined( _NO_MBG_API_ATTR ) + #define _NO_MBG_API_ATTR +#endif + #if !defined( MBG_INVALID_PORT_HANDLE ) #define MBG_INVALID_PORT_HANDLE MBG_INVALID_HANDLE #endif #if !defined( MBG_USE_MM_IO_FOR_PCI ) - #if ( 0 || defined( MBG_ARCH_SPARC ) ) - #define MBG_USE_MM_IO_FOR_PCI 1 - #else - #define MBG_USE_MM_IO_FOR_PCI 0 - #endif + #define MBG_USE_MM_IO_FOR_PCI 0 #endif -#if !defined( _nop_macro_fnc ) - #define _nop_macro_fnc() do {} while (0) +// The macros below are defined in order to be able to check if +// certain C language extensions are available on the target system: +#if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199409L ) + #define MBG_TGT_C94 1 +#else + #define MBG_TGT_C94 0 #endif -// The macros below are defined in order to be able to check if -// certain C language extensions are available on the target system: -#define MBG_TGT_C94 ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199409L ) ) -#define MBG_TGT_C99 ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) ) +#if defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) + #define MBG_TGT_C99 1 +#else + #define MBG_TGT_C99 0 +#endif // Check if wchar_t is supported #if !defined( MBG_TGT_HAS_WCHAR_T ) @@ -372,7 +632,7 @@ // However, some functions may be missing (e.g. snwprintf()). #if !defined( _WCHAR_T ) /* BC3.1 */ \ && !defined( _WCHAR_T_DEFINED_ ) /* WC11 */ - //##++ #define _WCHAR_T + #define _WCHAR_T #define wchar_t char #endif #endif |