1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 /*
4  * This file has to be C90 compatible, as it is not only used by the engine,
5  * but also by AIs, which might be compiled with compilers (for example VS)
6  * that do not support C99.
7  */
8 
9 #ifndef MAIN_DEFINES_H
10 #define MAIN_DEFINES_H
11 
12 #include <stdio.h>
13 
14 #if       !defined __cplusplus && !defined bool
15 /* include the bool type (defines: bool, true, false) */
16 #if defined _MSC_VER
17 #include "System/booldefines.h"
18 #else
19 #include <stdbool.h>
20 #endif
21 #endif /* !defined __cplusplus && !defined bool */
22 
23 /* define if we have a X11 enviroment (:= linux/freebsd) */
24 #if !defined(__APPLE__) && !defined(_WIN32)
25 	//FIXME move this check to cmake, which has FindX11.cmake?
26 	#define _X11
27 #endif
28 
29 /* define a common indicator for 32bit or 64bit-ness */
30 #if defined _WIN64 || defined __LP64__ || defined __ppc64__ || defined __ILP64__ || defined __SILP64__ || defined __LLP64__ || defined(__sparcv9)
31 #define __arch64__
32 #define __archBits__ 64
33 #else
34 #define __arch32__
35 #define __archBits__ 32
36 #endif
37 
38 /*
39   define a cross-platform/-compiler compatible "%z" format replacement for
40   printf() style functions.
41   "%z" being the propper way for size_t typed values,
42   but support for it has not yet spread wide enough.
43 */
44 #if defined __arch64__
45 #define __SIZE_T_PRINTF_FORMAT__ "%lu"
46 #else
47 #define __SIZE_T_PRINTF_FORMAT__ "%u"
48 #endif
49 /* a shorter form */
50 #define _STPF_ __SIZE_T_PRINTF_FORMAT__
51 
52 #ifdef _MSC_VER
53 	/* Microsoft Visual C++ 7.0: MSC_VER = 1300
54 	   Microsoft Visual C++ 7.1: MSC_VER = 1310 */
55 	#if _MSC_VER > 1310 // >= Visual Studio 2005
56 		#define PRINTF    printf_s
57 		#define FPRINTF   fprintf_s
58 		#define SNPRINTF  _snprintf /* sprintf_s misbehaves in debug mode, triggering breakpoints */
59 		#define VSNPRINTF _vsnprintf /* vsprintf_s misbehaves in debug mode, triggering breakpoints */
60 		#define STRCPY    strcpy
61 		#define STRCPYS   strcpy_s
62 		#define STRNCPY   strncpy
63 		#define STRCAT    strcat
64 		#define STRCATS   strcat_s
65 		#define STRNCAT   strncat
66 		#define FOPEN     fopen_s
67 	#else              /* Visual Studio 2003 */
68 		#define PRINTF    _printf
69 		#define FPRINTF   _fprintf
70 		#define SNPRINTF  _snprintf
71 		#define VSNPRINTF _vsnprintf
72 		#define STRCPY    _strcpy
73 		#define STRCPYS(dst, dstSize, src) _strcpy(dst, src)
74 		#define STRNCPY   _strncpy
75 		#define STRCAT    _strcat
76 		#define STRCATS(dst, dstSize, src) _strcat(dst, src)
77 		#define STRNCAT   _strncat
78 		#define FOPEN     _fopen
79 	#endif
80 	#define STRCASECMP    stricmp
81 #else /* _MSC_VER */
82 	/* assuming GCC */
83 	#define PRINTF     printf
84 	#define FPRINTF    fprintf
85 	#define SNPRINTF   snprintf
86 	#define VSNPRINTF  vsnprintf
87 	#define STRCPY     strcpy
88 	#define STRCPYS(dst, dstSize, src) strcpy(dst, src)
89 	#define STRNCPY    strncpy
90 	#define STRCAT     strcat
91 	#define STRCATS(dst, dstSize, src) strcat(dst, src)
92 	#define STRNCAT    strncat
93 	#define FOPEN      fopen
94 	#define STRCASECMP strcasecmp
95 #endif /* _MSC_VER */
96 
97 #define FREE(x) free(x); x = NULL;
98 
99 /* define a platform independent path separator C-string and char */
100 #ifndef sPS
101 	#define sPS_WIN32 "\\"
102 	#define sPS_POSIX "/"
103 
104 	#ifdef    _WIN32
105 	#define sPS sPS_WIN32
106 	#else  // _WIN32
107 	#define sPS sPS_POSIX
108 	#endif // _WIN32
109 #endif /* sPS */
110 #ifndef cPS
111 	#define cPS_WIN32 '\\'
112 	#define cPS_POSIX '/'
113 
114 	#ifdef    _WIN32
115 	#define cPS cPS_WIN32
116 	#else  /* _WIN32 */
117 	#define cPS cPS_POSIX
118 	#endif /* _WIN32 */
119 #endif /* cPS */
120 
121 /* define a platform independent path delimitter C-string and char */
122 #ifndef sPD
123 	#define sPD_WIN32 ";"
124 	#define sPD_POSIX ":"
125 
126 	#ifdef    _WIN32
127 	#define sPD sPD_WIN32
128 	#else  /* _WIN32 */
129 	#define sPD sPD_POSIX
130 	#endif /* _WIN32 */
131 #endif /* sPD */
132 #ifndef cPD
133 	#define cPD_WIN32 ';'
134 	#define cPD_POSIX ':'
135 
136 	#ifdef    _WIN32
137 	#define cPD cPD_WIN32
138 	#else  /* _WIN32 */
139 	#define cPD cPD_POSIX
140 	#endif /* _WIN32 */
141 #endif /* cPD */
142 
143 /* WORKAROUND (2013) a pthread stack alignment problem, else SSE code would crash
144    more info: http://www.peterstock.co.uk/games/mingw_sse/ (TLDR: mingw-32 aligns
145    thread stacks to 4 bytes but we want 16-byte alignment)
146 */
147 #if (defined(__MINGW32__) && defined(__GNUC__) && (__GNUC__ == 4))
148 #define __FORCE_ALIGN_STACK__ __attribute__ ((force_align_arg_pointer))
149 #else
150 #define __FORCE_ALIGN_STACK__
151 #endif
152 
153 #endif /* MAIN_DEFINES_H */
154 
155