Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall_macros.h @ 254:9d70178c1ded
- better cpp checking whether dlinfo() is available, to also cover GLIBC based systems that don't identify as Linux (e.g. debian/k*BSD)
author | Tassilo Philipp |
---|---|
date | Mon, 15 May 2017 13:06:04 +0200 |
parents | a74e2cd93348 |
children | b625f2e11911 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: dyncall | |
5 File: dyncall/dyncall_macros.h | |
6 Description: Platform detection macros | |
7 License: | |
8 | |
188 | 9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 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. */ | |
254
9d70178c1ded
- better cpp checking whether dlinfo() is available, to also cover GLIBC based systems that don't identify as Linux (e.g. debian/k*BSD)
Tassilo Philipp
parents:
204
diff
changeset
|
75 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* latter is (also) used by systems using FreeBSD kernel, e.g. Debian/kFreeBSD, which could be detected specifically by also checking for __GLIBC__ */ |
0 | 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 | |
174
a8052efbde18
- loosened OS detection macros a bit to not bail out and thus make it easier to use dyncall on baremetal
cslag
parents:
141
diff
changeset
|
126 |
a8052efbde18
- loosened OS detection macros a bit to not bail out and thus make it easier to use dyncall on baremetal
cslag
parents:
141
diff
changeset
|
127 /* Unable to determine OS, which is probably ok (e.g. baremetal stuff, etc.). */ |
a8052efbde18
- loosened OS detection macros a bit to not bail out and thus make it easier to use dyncall on baremetal
cslag
parents:
141
diff
changeset
|
128 #define DC__OS_UNKNOWN |
0 | 129 #endif |
130 | |
131 | |
132 | |
133 /* Compiler specific defines. Do not change the order, because */ | |
134 /* some of the compilers define flags for compatible ones, too. */ | |
135 | |
136 /* Intel's C/C++ compiler. */ | |
137 #if defined(__INTEL_COMPILER) | |
138 #define DC__C_Intel | |
139 | |
140 /* MS C/C++ compiler. */ | |
141 #elif defined(_MSC_VER) | |
142 #define DC__C_MSVC | |
143 | |
144 /* LLVM clang. */ | |
145 #elif defined(__clang__) | |
146 #define DC__C_CLANG | |
147 | |
148 /* The GNU Compiler Collection - GCC. */ | |
149 #elif defined(__GNUC__) | |
150 #define DC__C_GNU | |
151 | |
152 /* Watcom compiler. */ | |
153 #elif defined(__WATCOMC__) | |
154 #define DC__C_WATCOM | |
155 | |
156 /* Portable C Compiler. */ | |
157 #elif defined(__PCC__) | |
158 #define DC__C_PCC | |
159 | |
160 /* Sun Pro C. */ | |
161 #elif defined(__SUNPRO_C) | |
162 #define DC__C_SUNPRO | |
163 | |
164 /* Undetected C Compiler. */ | |
165 #else | |
166 #define DC__C_UNKNOWN | |
167 #endif | |
168 | |
169 | |
170 | |
171 /* Architecture. */ | |
172 | |
173 /* Check architecture. */ | |
31
6e7b1b7ad9d3
Fixed failing builds when the compiler is ICC/ICPC
Snaipe <franklinmathieu@gmail.com>
parents:
0
diff
changeset
|
174 #if defined(_M_X64_) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) |
6e7b1b7ad9d3
Fixed failing builds when the compiler is ICC/ICPC
Snaipe <franklinmathieu@gmail.com>
parents:
0
diff
changeset
|
175 # define DC__Arch_AMD64 |
6e7b1b7ad9d3
Fixed failing builds when the compiler is ICC/ICPC
Snaipe <franklinmathieu@gmail.com>
parents:
0
diff
changeset
|
176 #elif defined(_M_IX86) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__386__) || defined(__i386) |
0 | 177 # define DC__Arch_Intel_x86 |
178 #elif defined(_M_IA64) || defined(__ia64__) | |
179 # define DC__Arch_Itanium | |
180 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__) | |
181 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__) | |
182 # define DC__Arch_PPC64 | |
183 # else | |
184 # define DC__Arch_PPC32 | |
185 # endif | |
186 #elif defined(__mips64__) || defined(__mips64) | |
187 # define DC__Arch_MIPS64 | |
188 #elif defined(_M_MRX000) || defined(__mips__) || defined(__mips) || defined(_mips) | |
189 # define DC__Arch_MIPS | |
190 #elif defined(__arm__) | |
191 # define DC__Arch_ARM | |
192 #elif defined(__aarch64__) | |
193 # define DC__Arch_ARM64 | |
194 #elif defined(__sh__) | |
195 # define DC__Arch_SuperH | |
180 | 196 #elif defined(__sparc) || defined(__sparc__) |
197 # if defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || defined(__arch64__) | |
198 # define DC__Arch_Sparc64 | |
199 # else | |
200 # define DC__Arch_Sparc | |
201 # endif | |
0 | 202 #endif |
203 | |
204 | |
205 | |
206 /* Rough OS classification. */ | |
207 | |
208 #if defined(DC__OS_Win32) || defined(DC__OS_Win64) | |
209 # define DC_WINDOWS | |
210 #elif defined(DC__OS_Plan9) | |
211 # define DC_PLAN9 | |
212 #elif defined(DC__OS_NDS) || defined(DC__OS_PSP) | |
213 # define DC_OTHER | |
214 #else | |
215 # define DC_UNIX | |
216 #endif | |
217 | |
218 | |
219 | |
220 /* Misc machine-dependent modes, ABIs, etc.. */ | |
221 | |
222 #if defined(__arm__) && !defined(__thumb__) | |
223 # define DC__Arch_ARM_ARM | |
224 #elif defined(__arm__) && defined(__thumb__) | |
225 # define DC__Arch_ARM_THUMB | |
226 #endif | |
227 | |
228 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB) | |
229 # if defined(__ARM_EABI__) || defined(DC__OS_NDS) | |
230 # if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1) | |
231 # define DC__ABI_ARM_HF | |
232 # else | |
233 # define DC__ABI_ARM_EABI | |
234 # endif | |
235 # elif defined(__APCS_32__) | |
236 # define DC__ABI_ARM_OABI | |
237 # endif | |
238 #endif /* ARM */ | |
239 | |
240 #if defined(DC__Arch_MIPS) || defined(DC__Arch_MIPS64) | |
241 # if defined(_ABIO32) || defined(_MIPS_ARCH_MIPS1) || defined(_MIPS_ARCH_MIPS2) | |
242 # define DC__ABI_MIPS_O32 | |
112 | 243 # elif defined(_ABI64) || defined(_mips_n64) |
244 # define DC__ABI_MIPS_N64 | |
0 | 245 # elif defined(_ABIN32) |
246 # define DC__ABI_MIPS_N32 | |
247 # else | |
248 # define DC__ABI_MIPS_EABI | |
249 # endif | |
141 | 250 /*@@@implement/support: __mips_hard_float*/ |
0 | 251 #endif /* MIPS */ |
252 | |
253 #if defined(DC__Arch_PPC64) | |
254 # if defined(_CALL_ELF) | |
255 # define DC__ABI_PPC64_ELF_V _CALL_ELF | |
256 # else | |
257 # define DC__ABI_PPC64_ELF_V 0 /* 0 means not explicitly set, otherwise this is 1 (big endian) and 2 (little endian) */ | |
258 # endif | |
112 | 259 #endif /* PPC64 */ |
0 | 260 |
261 | |
262 /* Endian detection. */ | |
263 #if defined(DC__Arch_Intel_x86) || defined(DC__Arch_AMD64) /* always little */ | |
264 # define DC__Endian_LITTLE | |
179 | 265 #elif defined(DC__Arch_Sparc) /* always purely big until v9 */ |
0 | 266 # define DC__Endian_BIG |
267 #else /* all others are bi-endian */ | |
268 /* @@@check flags used on following bi-endianness archs: | |
269 DC__Arch_ARM | |
270 DC__Arch_ARM64 | |
271 DC__Arch_Itanium | |
272 DC__Arch_PPC32 | |
273 DC__Arch_PPC64 | |
274 DC__Arch_SuperH | |
275 */ | |
115 | 276 # if (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 1)) || defined(_BIG_ENDIAN) || defined(MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) |
0 | 277 # define DC__Endian_BIG |
115 | 278 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(_LITTLE_ENDIAN) || defined(MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) |
0 | 279 # define DC__Endian_LITTLE |
204
a74e2cd93348
- sparc64 endian detection on non-explicit platforms
Tassilo Philipp
parents:
188
diff
changeset
|
280 # elif defined(DC__Arch_Sparc64) && !defined(__BYTE_ORDER__) /* Sparc64 default is big-endian, except if explicitly defined */ |
a74e2cd93348
- sparc64 endian detection on non-explicit platforms
Tassilo Philipp
parents:
188
diff
changeset
|
281 # define DC__Endian_BIG |
188 | 282 # elif defined(__BYTE_ORDER__) /* explicitly set */ |
283 # if defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) | |
284 # define DC__Endian_BIG | |
285 # elif defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) | |
286 # define DC__Endian_LITTLE | |
287 # endif | |
0 | 288 # endif /* no else, leave unset if not sure */ |
289 #endif | |
290 | |
291 | |
292 /* Internal macro/tag. */ | |
293 #if !defined(DC_API) | |
188 | 294 # define DC_API |
0 | 295 #endif |
296 | |
297 #endif /* DYNCALL_MACROS_H */ | |
298 |