1 /**
2  * WinPR: Windows Portable Runtime
3  * Platform-Specific Definitions
4  *
5  * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef WINPR_PLATFORM_H
21 #define WINPR_PLATFORM_H
22 
23 #include <stdlib.h>
24 
25 #include <winpr/wtypes.h>
26 
27 /*
28  * Processor Architectures:
29  * http://sourceforge.net/p/predef/wiki/Architectures/
30  *
31  * Visual Studio Predefined Macros:
32  * http://msdn.microsoft.com/en-ca/library/vstudio/b0084kay.aspx
33  */
34 
35 /* Intel x86 (_M_IX86) */
36 
37 #if defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) ||   \
38     defined(__i586__) || defined(__i686__) || defined(__X86__) || defined(_X86_) || \
39     defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL__) || defined(__INTEL__)
40 #ifndef _M_IX86
41 #define _M_IX86 1
42 #endif
43 #endif
44 
45 /* AMD64 (_M_AMD64) */
46 
47 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
48     defined(_M_X64)
49 #ifndef _M_AMD64
50 #define _M_AMD64 1
51 #endif
52 #endif
53 
54 /* Intel x86 or AMD64 (_M_IX86_AMD64) */
55 
56 #if defined(_M_IX86) || defined(_M_AMD64)
57 #ifndef _M_IX86_AMD64
58 #define _M_IX86_AMD64 1
59 #endif
60 #endif
61 
62 /* ARM (_M_ARM) */
63 
64 #if defined(__arm__) || defined(__thumb__) || defined(__TARGET_ARCH_ARM) || \
65     defined(__TARGET_ARCH_THUMB)
66 #ifndef _M_ARM
67 #define _M_ARM 1
68 #endif
69 #endif
70 
71 /* ARM64 (_M_ARM64) */
72 
73 #if defined(__aarch64__)
74 #ifndef _M_ARM64
75 #define _M_ARM64 1
76 #endif
77 #endif
78 
79 /* MIPS (_M_MIPS) */
80 
81 #if defined(mips) || defined(__mips) || defined(__mips__) || defined(__MIPS__)
82 #ifndef _M_MIPS
83 #define _M_MIPS 1
84 #endif
85 #endif
86 
87 /* MIPS64 (_M_MIPS64) */
88 
89 #if defined(mips64) || defined(__mips64) || defined(__mips64__) || defined(__MIPS64__)
90 #ifndef _M_MIPS64
91 #define _M_MIPS64 1
92 #endif
93 #endif
94 
95 /* PowerPC (_M_PPC) */
96 
97 #if defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || \
98     defined(_ARCH_PPC)
99 #ifndef _M_PPC
100 #define _M_PPC 1
101 #endif
102 #endif
103 
104 /* Intel Itanium (_M_IA64) */
105 
106 #if defined(__ia64) || defined(__ia64__) || defined(_IA64) || defined(__IA64__)
107 #ifndef _M_IA64
108 #define _M_IA64 1
109 #endif
110 #endif
111 
112 /* Alpha (_M_ALPHA) */
113 
114 #if defined(__alpha) || defined(__alpha__)
115 #ifndef _M_ALPHA
116 #define _M_ALPHA 1
117 #endif
118 #endif
119 
120 /* SPARC (_M_SPARC) */
121 
122 #if defined(__sparc) || defined(__sparc__)
123 #ifndef _M_SPARC
124 #define _M_SPARC 1
125 #endif
126 #endif
127 
128 /**
129  * Operating Systems:
130  * http://sourceforge.net/p/predef/wiki/OperatingSystems/
131  */
132 
133 /* Windows (_WIN32) */
134 
135 /* WinRT (_WINRT) */
136 
137 #if defined(WINAPI_FAMILY)
138 #if (WINAPI_FAMILY == WINAPI_FAMILY_APP)
139 #ifndef _WINRT
140 #define _WINRT 1
141 #endif
142 #endif
143 #endif
144 
145 #if defined(__cplusplus_winrt)
146 #ifndef _WINRT
147 #define _WINRT 1
148 #endif
149 #endif
150 
151 /* Linux (__linux__) */
152 
153 #if defined(linux) || defined(__linux)
154 #ifndef __linux__
155 #define __linux__ 1
156 #endif
157 #endif
158 
159 /* GNU/Linux (__gnu_linux__) */
160 
161 /* Apple Platforms (iOS, Mac OS X) */
162 
163 #if (defined(__APPLE__) && defined(__MACH__))
164 
165 #include <TargetConditionals.h>
166 
167 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
168 
169 /* iOS (__IOS__) */
170 
171 #ifndef __IOS__
172 #define __IOS__ 1
173 #endif
174 
175 #elif (TARGET_OS_MAC == 1)
176 
177 /* Mac OS X (__MACOSX__) */
178 
179 #ifndef __MACOSX__
180 #define __MACOSX__ 1
181 #endif
182 
183 #endif
184 #endif
185 
186 /* Android (__ANDROID__) */
187 
188 /* Cygwin (__CYGWIN__) */
189 
190 /* FreeBSD (__FreeBSD__) */
191 
192 /* NetBSD (__NetBSD__) */
193 
194 /* OpenBSD (__OpenBSD__) */
195 
196 /* DragonFly (__DragonFly__) */
197 
198 /* Solaris (__sun) */
199 
200 #if defined(sun)
201 #ifndef __sun
202 #define __sun 1
203 #endif
204 #endif
205 
206 /* IRIX (__sgi) */
207 
208 #if defined(sgi)
209 #ifndef __sgi
210 #define __sgi 1
211 #endif
212 #endif
213 
214 /* AIX (_AIX) */
215 
216 #if defined(__TOS_AIX__)
217 #ifndef _AIX
218 #define _AIX 1
219 #endif
220 #endif
221 
222 /* HP-UX (__hpux) */
223 
224 #if defined(hpux) || defined(_hpux)
225 #ifndef __hpux
226 #define __hpux 1
227 #endif
228 #endif
229 
230 /* BeOS (__BEOS__) */
231 
232 /* QNX (__QNXNTO__) */
233 
234 /**
235  * Endianness:
236  * http://sourceforge.net/p/predef/wiki/Endianness/
237  */
238 
239 #if defined(__gnu_linux__)
240 #include <endian.h>
241 #endif
242 
243 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
244     defined(__DragonFly__) || defined(__APPLE__)
245 #include <sys/param.h>
246 #endif
247 
248 /* Big-Endian */
249 
250 #ifdef __BYTE_ORDER
251 
252 #if (__BYTE_ORDER == __BIG_ENDIAN)
253 #ifndef __BIG_ENDIAN__
254 #define __BIG_ENDIAN__ 1
255 #endif
256 #endif
257 
258 #else
259 
260 #if defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIPSEB) || \
261     defined(__MIPSEB) || defined(__MIPSEB__)
262 #ifndef __BIG_ENDIAN__
263 #define __BIG_ENDIAN__ 1
264 #endif
265 #endif
266 
267 #endif /* __BYTE_ORDER */
268 
269 /* Little-Endian */
270 
271 #ifdef __BYTE_ORDER
272 
273 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
274 #ifndef __LITTLE_ENDIAN__
275 #define __LITTLE_ENDIAN__ 1
276 #endif
277 #endif
278 
279 #else
280 
281 #if defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || \
282     defined(__MIPSEL) || defined(__MIPSEL__)
283 #ifndef __LITTLE_ENDIAN__
284 #define __LITTLE_ENDIAN__ 1
285 #endif
286 #endif
287 
288 #endif /* __BYTE_ORDER */
289 
290 #endif /* WINPR_PLATFORM_H */
291