comparison dyncall/dyncall_macros.h @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children 6e7b1b7ad9d3
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 /*
2
3 Package: dyncall
4 Library: dyncall
5 File: dyncall/dyncall_macros.h
6 Description: Platform detection macros
7 License:
8
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>,
10 Tassilo Philipp <tphilipp@potion-studios.com>
11
12 Permission to use, copy, modify, and distribute this software for any
13 purpose with or without fee is hereby granted, provided that the above
14 copyright notice and this permission notice appear in all copies.
15
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
24 */
25
26
27
28 /*
29
30 dyncall macros
31
32 Platform detection, specific defines and configuration.
33 The purpose of this file is to provide coherent platform and compiler
34 specific defines. So instead of defines like WIN32, _OpenBSD_ or
35 __GNUC__, one should use DC__OS_Win32, DC__OS_OpenBSD or DC__C_GNU,
36 respectively.
37
38 REVISION
39 2007/12/11 initial
40
41 */
42
43
44 #ifndef DYNCALL_MACROS_H
45 #define DYNCALL_MACROS_H
46
47
48 /* Platform specific defines. */
49
50 /* MS Windows XP x64/Vista64 or later. */
51 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
52 #define DC__OS_Win64
53
54 /* MS Windows NT/95/98/ME/2000/XP/Vista32. */
55 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WINDOWS__) || defined(_WINDOWS)
56 #define DC__OS_Win32
57
58 /* All the OS' based on Darwin OS (MacOS X, OpenDarwin). Note that '__APPLE__' may be defined for classic MacOS, too. */
59 /* __MACOSX__ is not defined in gcc assembler mode (switch: -S) */
60 /* @@@ TODO: Check for Classic OS */
61
62 #elif defined(__APPLE__) || defined(__Darwin__)
63 # define DC__OS_Darwin
64 # if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
65 # define DC__OS_IPhone
66 # else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */
67 # define DC__OS_MacOSX
68 # endif
69
70 /* The most popular open source Unix-like OS - Linux. */
71 #elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
72 #define DC__OS_Linux
73
74 /* The most powerful open source Unix-like OS - FreeBSD. */
75 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
76 #define DC__OS_FreeBSD
77
78 /* The most secure open source Unix-like OS - OpenBSD. */
79 #elif defined(__OpenBSD__)
80 #define DC__OS_OpenBSD
81
82 /* The most portable open source Unix-like OS - NetBSD. */
83 #elif defined(__NetBSD__)
84 #define DC__OS_NetBSD
85
86 /* The FreeBSD fork having heavy clusterization in mind - DragonFlyBSD. */
87 #elif defined(__DragonFly__)
88 #define DC__OS_DragonFlyBSD
89
90 /* Sun's Unix-like OS - SunOS / Solaris. */
91 #elif defined(__sun__) || defined(__sun) || defined(sun)
92 #define DC__OS_SunOS
93
94 /* The "Linux-like environment for Windows" - Cygwin. */
95 #elif defined(__CYGWIN__)
96 #define DC__OS_Cygwin
97
98 /* The "Minimalist GNU for Windows" - MinGW. */
99 #elif defined(__MINGW__)/*@@@*/
100 #define DC__OS_MinGW
101
102 /* The Nintendo DS (homebrew) using devkitpro. */
103 #elif defined(__nds__)
104 #define DC__OS_NDS
105
106 /* The PlayStation Portable (homebrew) SDK. */
107 #elif defined(__psp__) || defined(PSP)
108 #define DC__OS_PSP
109
110 /* Haiku (BeOS alike). */
111 #elif defined(__HAIKU__)
112 #define DC__OS_BeOS
113
114 /* The Unix successor - Plan9 from Bell Labs */
115 #elif defined(Plan9) || defined(__Plan9__)
116 #define DC__OS_Plan9
117
118 /* Digital's Unix-like OS - VMS */
119 #elif defined(__vms)
120 #define DC__OS_VMS
121
122 #elif defined(__minix)
123 #define DC__OS_Minix
124
125 #else
126 #error Unsupported OS.
127 #endif
128
129
130
131 /* Compiler specific defines. Do not change the order, because */
132 /* some of the compilers define flags for compatible ones, too. */
133
134 /* Intel's C/C++ compiler. */
135 #if defined(__INTEL_COMPILER)
136 #define DC__C_Intel
137
138 /* MS C/C++ compiler. */
139 #elif defined(_MSC_VER)
140 #define DC__C_MSVC
141
142 /* LLVM clang. */
143 #elif defined(__clang__)
144 #define DC__C_CLANG
145
146 /* The GNU Compiler Collection - GCC. */
147 #elif defined(__GNUC__)
148 #define DC__C_GNU
149
150 /* Watcom compiler. */
151 #elif defined(__WATCOMC__)
152 #define DC__C_WATCOM
153
154 /* Portable C Compiler. */
155 #elif defined(__PCC__)
156 #define DC__C_PCC
157
158 /* Sun Pro C. */
159 #elif defined(__SUNPRO_C)
160 #define DC__C_SUNPRO
161
162 /* Undetected C Compiler. */
163 #else
164 #define DC__C_UNKNOWN
165 #endif
166
167
168
169 /* Architecture. */
170
171 /* Check architecture. */
172 #if defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__386__) || defined(__i386)
173 # define DC__Arch_Intel_x86
174 #elif defined(_M_X64_) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
175 # define DC__Arch_AMD64
176 #elif defined(_M_IA64) || defined(__ia64__)
177 # define DC__Arch_Itanium
178 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__)
179 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__)
180 # define DC__Arch_PPC64
181 # else
182 # define DC__Arch_PPC32
183 # endif
184 #elif defined(__mips64__) || defined(__mips64)
185 # define DC__Arch_MIPS64
186 #elif defined(_M_MRX000) || defined(__mips__) || defined(__mips) || defined(_mips)
187 # define DC__Arch_MIPS
188 #elif defined(__arm__)
189 # define DC__Arch_ARM
190 #elif defined(__aarch64__)
191 # define DC__Arch_ARM64
192 #elif defined(__sh__)
193 # define DC__Arch_SuperH
194 #elif defined(__sparcv9) || defined(__sparc64__) || ( defined(__sparc) && defined(__arch64__) )
195 /* this could be needed on Linux/GNU sparc64 in the future: || ( defined(__sparc) && defined(__arch64__) ) */
196 # define DC__Arch_Sparcv9
197 #elif defined(__sparc)
198 # define DC__Arch_Sparc
199 #endif
200
201
202
203 /* Rough OS classification. */
204
205 #if defined(DC__OS_Win32) || defined(DC__OS_Win64)
206 # define DC_WINDOWS
207 #elif defined(DC__OS_Plan9)
208 # define DC_PLAN9
209 #elif defined(DC__OS_NDS) || defined(DC__OS_PSP)
210 # define DC_OTHER
211 #else
212 # define DC_UNIX
213 #endif
214
215
216
217 /* Misc machine-dependent modes, ABIs, etc.. */
218
219 #if defined(__arm__) && !defined(__thumb__)
220 # define DC__Arch_ARM_ARM
221 #elif defined(__arm__) && defined(__thumb__)
222 # define DC__Arch_ARM_THUMB
223 #endif
224
225 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB)
226 # if defined(__ARM_EABI__) || defined(DC__OS_NDS)
227 # if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1)
228 # define DC__ABI_ARM_HF
229 # else
230 # define DC__ABI_ARM_EABI
231 # endif
232 # elif defined(__APCS_32__)
233 # define DC__ABI_ARM_OABI
234 # endif
235 #endif /* ARM */
236
237 #if defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64)
238 # if defined(_ABIO32) || defined(_MIPS_ARCH_MIPS1) || defined(_MIPS_ARCH_MIPS2)
239 # define DC__ABI_MIPS_O32
240 # elif defined(_ABIN32)
241 # define DC__ABI_MIPS_N32
242 # elif defined(_ABI64)
243 # define DC__ABI_MIPS_N64
244 # else
245 # define DC__ABI_MIPS_EABI
246 # endif
247 #endif /* MIPS */
248
249 #if defined(DC__Arch_PPC64)
250 # if defined(_CALL_ELF)
251 # define DC__ABI_PPC64_ELF_V _CALL_ELF
252 # else
253 # define DC__ABI_PPC64_ELF_V 0 /* 0 means not explicitly set, otherwise this is 1 (big endian) and 2 (little endian) */
254 # endif
255 #endif /* MIPS */
256
257
258 /* Endian detection. */
259 #if defined(DC__Arch_Intel_x86) || defined(DC__Arch_AMD64) /* always little */
260 # define DC__Endian_LITTLE
261 #elif defined(DC__Arch_Sparc) /*always big until v9*/
262 # define DC__Endian_BIG
263 #else /* all others are bi-endian */
264 /* @@@check flags used on following bi-endianness archs:
265 DC__Arch_ARM
266 DC__Arch_ARM64
267 DC__Arch_Itanium
268 DC__Arch_MIPS
269 DC__Arch_MIPS64
270 DC__Arch_PPC32
271 DC__Arch_PPC64
272 DC__Arch_Sparcv9
273 DC__Arch_SuperH
274 */
275 # if (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 1)) || defined(_BIG_ENDIAN) || defined(MIPSEB)
276 # define DC__Endian_BIG
277 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(_LITTLE_ENDIAN) || defined(MIPSEL)
278 # define DC__Endian_LITTLE
279 # endif /* no else, leave unset if not sure */
280 #endif
281
282
283 /* Internal macro/tag. */
284 #if !defined(DC_API)
285 #define DC_API
286 #endif
287
288 #endif /* DYNCALL_MACROS_H */
289