flext 0.6.2
flprefix.h
Go to the documentation of this file.
1/*
2flext - C++ layer for Max and Pure Data externals
3
4Copyright (c) 2001-2017 Thomas Grill (gr@grrrr.org)
5For information on usage and redistribution, and for a DISCLAIMER OF ALL
6WARRANTIES, see the file, "license.txt," in this distribution.
7*/
8
13#ifndef __FLEXT_PREFIX_H
14#define __FLEXT_PREFIX_H
15
16// --- definitions for FLEXT_SYS ---------------------
17#define FLEXT_SYS_UNKNOWN 0
18
19#ifndef FLEXT_SYS_MAX
20 #define FLEXT_SYS_MAX 1
21#else
22 // already defined
23 #undef FLEXT_SYS_MAX
24 #define FLEXT_SYS_MAX 1
25 #define FLEXT_SYS FLEXT_SYS_MAX
26#endif
27
28#ifndef FLEXT_SYS_PD
29 #define FLEXT_SYS_PD 2
30#else
31 // already defined
32 #undef FLEXT_SYS_PD
33 #define FLEXT_SYS_PD 2
34 #define FLEXT_SYS FLEXT_SYS_PD
35#endif
36
37// --- definitions for FLEXT_OS ----------------------
38#define FLEXT_OS_UNKNOWN 0
39#define FLEXT_OS_WIN 1
40#define FLEXT_OS_MAC 2
41#define FLEXT_OS_LINUX 3
42#define FLEXT_OS_IRIX 4
43
44// --- definitions for FLEXT_OS_API ---------------------
45#define FLEXT_OSAPI_UNKNOWN 0
46
47#define FLEXT_OSAPI_UNIX_POSIX 1
48
49#define FLEXT_OSAPI_MAC_CLASSIC 2
50#define FLEXT_OSAPI_MAC_CARBON 3
51#define FLEXT_OSAPI_MAC_MACH 4
52
53#define FLEXT_OSAPI_WIN_NATIVE 5 // WIN32 Platform
54#define FLEXT_OSAPI_WIN_POSIX 6 // POSIX API (e.g. cygwin)
55
56// --- definitions for FLEXT_CPU ---------------------
57#define FLEXT_CPU_UNKNOWN 0
58#define FLEXT_CPU_IA32 1
59#define FLEXT_CPU_PPC 2
60#define FLEXT_CPU_MIPS 3
61#define FLEXT_CPU_ALPHA 4
62
63#define FLEXT_CPU_IA64 5 // Itanium
64#define FLEXT_CPU_X86_64 6 // AMD-K8, EMT64
65#define FLEXT_CPU_PPC64 7 // G5 in 64 bit mode
66
67// compatibility
68#define FLEXT_CPU_INTEL FLEXT_CPU_IA32
69
70// --- definitions for FLEXT_THREADS -----------------
71#define FLEXT_THR_POSIX 1 // pthreads
72#define FLEXT_THR_WIN32 2 // Win32 native
73#define FLEXT_THR_MP 3 // MacOS MPThreads
74
75// ---------------------------------------------------
76// support old definitions
77
78#ifndef FLEXT_SYS
79 #if defined(MAXMSP)
80 #define FLEXT_SYS FLEXT_SYS_MAX
81 // #undef MAXMSP
82 #elif defined(PD)
83 #define FLEXT_SYS FLEXT_SYS_PD
84 // #undef PD
85 // #undef NT
86 #endif
87#endif
88
89#if defined(_DEBUG) && !defined(FLEXT_DEBUG)
90 #define FLEXT_DEBUG
91#endif
92
93// ---------------------------------------------------
94
95// Definition of supported real-time systems
96#if FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_PD
97#else
98 #error "System must be defined by either FLEXT_SYS_MAX or FLEXT_SYS_PD"
99#endif
100
101// Definition of OS/CPU
102#if defined(_MSC_VER) || (defined(__ICC) && (FLEXT_OS == FLEXT_OS_WIN || defined(_WIN32)))
103 // Microsoft C++
104 // and Intel C++ (as guessed)
105
106 #ifndef FLEXT_CPU
107 #if defined(_M_AMD64)
108 #define FLEXT_CPU FLEXT_CPU_X86_64
109 #elif defined(_M_IA64)
110 #define FLEXT_CPU FLEXT_CPU_IA64
111 #elif defined(_M_IX86)
112 #define FLEXT_CPU FLEXT_CPU_IA32
113 #elif defined(_M_PPC)
114 #define FLEXT_CPU FLEXT_CPU_PPC
115 #elif defined(_M_MRX000)
116 #define FLEXT_CPU FLEXT_CPU_MIPS
117 #elif defined(_M_ALPHA)
118 #define FLEXT_CPU FLEXT_CPU_ALPHA
119 #else
120 #define FLEXT_CPU FLEXT_CPU_UNKNOWN
121 #endif
122 #endif
123
124 #ifndef FLEXT_OS
125 #if defined(_WIN32) || defined(_WIN64)
126 #define FLEXT_OS FLEXT_OS_WIN
127 #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
128 #else
129 #define FLEXT_OS FLEXT_OS_UNKNOWN
130 #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
131 #endif
132 #endif
133
134
135#elif defined(__BORLANDC__)
136 // Borland C++
137
138 #ifndef FLEXT_CPU
139 #define FLEXT_CPU FLEXT_CPU_INTEL
140 #endif
141 #ifndef FLEXT_OS
142 #define FLEXT_OS FLEXT_OS_WIN
143 #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
144 #else
145 #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
146 #endif
147
148
149#elif defined(__MWERKS__)
150 // Metrowerks CodeWarrior
151
152 #ifdef __MACH__
153 // quick fix for OSX Mach-O
154 #ifdef __POWERPC__
155 #ifdef __LP64__
156 #define TARGET_CPU_PPC64 1
157 #else
158 #define TARGET_CPU_PPC 1
159 #endif
160 #else
161 #ifdef __LP64__
162 #define TARGET_CPU_X86_64 1
163 #else
164 #define TARGET_CPU_IA32 1
165 #endif
166 #endif
167 #define TARGET_OS_MAC 1
168 #define TARGET_API_MAC_OSX 1
169 #else
170 #ifndef __CONDITIONALMACROS__
171 #include <ConditionalMacros.h>
172 #endif
173 #endif
174
175 #ifndef FLEXT_CPU
176 #if TARGET_CPU_X86_64
177 #define FLEXT_CPU FLEXT_CPU_X86_64
178 #elif TARGET_CPU_X86
179 #define FLEXT_CPU FLEXT_CPU_IA32
180 #elif TARGET_CPU_PPC64
181 #define FLEXT_CPU FLEXT_CPU_PPC64
182 #elif TARGET_CPU_PPC
183 #define FLEXT_CPU FLEXT_CPU_PPC
184 #elif TARGET_CPU_MIPS
185 #define FLEXT_CPU FLEXT_CPU_MIPS
186 #elif TARGET_CPU_ALPHA
187 #define FLEXT_CPU FLEXT_CPU_ALPHA
188 #else
189 #define FLEXT_CPU FLEXT_CPU_UNKNOWN
190 #endif
191 #endif
192
193 #ifndef FLEXT_OS
194 #if TARGET_OS_MAC
195 #define FLEXT_OS FLEXT_OS_MAC
196 #elif TARGET_OS_WIN32
197 // assume Windows
198 #define FLEXT_OS FLEXT_OS_WIN
199 #else
200 #define FLEXT_OS FLEXT_OS_UNKNOWN
201 #endif
202 #endif
203
204 #ifndef FLEXT_OSAPI
205 #if TARGET_API_MAC_MACH
206 // this is for Mach-O
207 // this has the precedence (MACH also supports Carbon, of course)
208 #define FLEXT_OSAPI FLEXT_OSAPI_MAC_MACH
209 #elif TARGET_API_MAC_CARBON
210 // this is for CFM
211 #define FLEXT_OSAPI FLEXT_OSAPI_MAC_CARBON
212 #else
213 #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
214 #endif
215 #endif
216
217 // This is important for method and attribute callbacks
218 #pragma enumsalwaysint on
219 // This is important for everything
220 #pragma bool on
221
222#elif defined(__GNUG__) || (defined(__ICC) && (FLEXT_OS == FLEXT_OS_LINUX || defined(linux) || defined(__linux__)))
223
224 // GNU C++
225 // and Intel (as suggested by Tim Blechmann)
226
227 #ifndef FLEXT_CPU
228 #if defined(__x86_64__)
229 #define FLEXT_CPU FLEXT_CPU_X86_64
230 #elif defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__)
231 #define FLEXT_CPU FLEXT_CPU_IA32
232 #elif defined(__ppc64__)
233 #define FLEXT_CPU FLEXT_CPU_PPC64
234 #elif defined(__ppc__)
235 #define FLEXT_CPU FLEXT_CPU_PPC
236 #elif defined(__MIPS__)
237 #define FLEXT_CPU FLEXT_CPU_MIPS
238 #else
239 #define FLEXT_CPU FLEXT_CPU_UNKNOWN
240 #endif
241 #endif
242
243 #ifndef FLEXT_OS
244 #if defined(linux) || defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
245 #define FLEXT_OS FLEXT_OS_LINUX
246 #elif defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__MINGW32__)
247 #define FLEXT_OS FLEXT_OS_WIN
248 #elif defined(__APPLE__) && defined(__MACH__)
249 #define FLEXT_OS FLEXT_OS_MAC
250 // how about IRIX??
251 #else
252 #define FLEXT_OS FLEXT_OS_UNKNOWN
253 #endif
254 #endif
255
256 #ifndef FLEXT_OSAPI
257 #if FLEXT_OS == FLEXT_OS_MAC
258 #define FLEXT_OSAPI FLEXT_OSAPI_MAC_MACH
259 #elif FLEXT_OS == FLEXT_OS_WIN
260 #if defined(__MINGW32__)
261 #define FLEXT_OSAPI FLEXT_OSAPI_WIN_NATIVE
262 #else
263 #define FLEXT_OSAPI FLEXT_OSAPI_WIN_POSIX
264 #endif
265 #elif FLEXT_OS == FLEXT_OS_LINUX || FLEXT_OS == FLEXT_OS_IRIX
266 #define FLEXT_OSAPI FLEXT_OSAPI_UNIX_POSIX
267 #else
268 #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
269 #endif
270 #endif
271
272#elif defined(__MRC__) && defined(MPW_CPLUS)
273 // Apple MPW MrCpp
274
275 #if __MRC__ < 0x500
276 #error Apple MPW MrCpp v.5.0.0 or later compiler required
277 #endif
278
279 #ifndef FLEXT_CPU
280 #if defined(__POWERPC__)
281 #define FLEXT_CPU FLEXT_CPU_PPC
282 #else
283 #define FLEXT_CPU FLEXT_CPU_UNKNOWN
284 #endif
285 #endif
286
287 #ifndef FLEXT_OS
288 #if defined(macintosh)
289 #define FLEXT_OS FLEXT_OS_MAC
290 #else
291 #define FLEXT_OS FLEXT_OS_UNKNOWN
292 #endif
293 #endif
294
295 #ifndef FLEXT_OSAPI
296 #if FLEXT_OS == FLEXT_OS_MAC
297 #define FLEXT_OSAPI FLEXT_OSAPI_MAC_CLASSIC
298 #else
299 #define FLEXT_OSAPI FLEXT_OSAPI_UNKNOWN
300 #endif
301 #endif
302#endif
303
304
305
306#if FLEXT_OS == FLEXT_OS_WIN
307// #pragma message("Compiling for Windows")
308
309 #if FLEXT_SYS == FLEXT_SYS_MAX
310// #define WIN_VERSION 1
311 #elif FLEXT_SYS == FLEXT_SYS_PD
312// #define PD
313// #define NT
314 #endif
315#elif FLEXT_OS == FLEXT_OS_LINUX
316// #pragma message("Compiling for Linux")
317
318 #if FLEXT_SYS == FLEXT_SYS_PD
319// #define PD
320 #else
321 #error "Flext SYS/OS combination unknown"
322 #endif
323#elif FLEXT_OS == FLEXT_OS_IRIX
324// #pragma message("Compiling for Irix")
325
326 #if FLEXT_SYS == FLEXT_SYS_PD
327// #define PD
328 #else
329 #error "Flext SYS/OS combination unknown"
330 #endif
331#elif FLEXT_OS == FLEXT_OS_MAC
332// #pragma message("Compiling for MacOS")
333
334 #if FLEXT_SYS == FLEXT_SYS_PD
335// #define PD
336 #endif
337#else
338 #error "Operating system could not be determined"
339#endif
340
341#if FLEXT_SYS == FLEXT_SYS_MAX
342// #pragma message("Compiling for Max/MSP")
343 #ifndef MSP64
344 #if FLEXT_CPU == FLEXT_CPU_X86_64
345 #define MSP64 1
346 #else
347 #define MSP64 0
348 #endif
349 #endif
350#elif FLEXT_SYS == FLEXT_SYS_PD
351// #pragma message("Compiling for PD")
352#endif
353
354// ----- set threading model -----
355// shared builds are always threaded
356#ifdef FLEXT_SHARED
357 #undef FLEXT_THREADS
358 #define FLEXT_THREADS
359#endif
360
361#ifdef FLEXT_THREADS
362 #undef FLEXT_THREADS
363 #if FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_MAC && FLEXT_OSAPI != FLEXT_OSAPI_MAC_MACH
364 // Max for CFM doesn't like posix threads
365 #define FLEXT_THREADS FLEXT_THR_MP
366 #elif FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_WIN
367 // for wmax use native Windows threads
368 #define FLEXT_THREADS FLEXT_THR_WIN32
369 #else
370 #define FLEXT_THREADS FLEXT_THR_POSIX
371 #endif
372#endif
373
374// ----- macros for class names -----
375/*
376 With linux (flat linker namespace) and more than one flext-based external loaded all calls to static
377 exported functions refer to the first instance loaded!
378 Therefore different class names are used so that the correct type of flext function is called.
379*/
380#ifdef __DOXYGEN__
381 #define FLEXT_CLASSDEF(CL) CL
382#elif defined(FLEXT_DEBUG)
383 #if defined(FLEXT_SHARED)
384 #define FLEXT_CLASSDEF(CL) CL##_shared_d
385 #elif defined(FLEXT_THREADS)
386 #define FLEXT_CLASSDEF(CL) CL##_multi_d
387 #else
388 #define FLEXT_CLASSDEF(CL) CL##_single_d
389 #endif
390#else
391 #if defined(FLEXT_SHARED)
392 #define FLEXT_CLASSDEF(CL) CL##_shared
393 #elif defined(FLEXT_THREADS)
394 #define FLEXT_CLASSDEF(CL) CL##_multi
395 #else
396 #define FLEXT_CLASSDEF(CL) CL##_single
397 #endif
398#endif
399
400
401/* Set the right calling convention (and exporting) for the OS */
402
403#if defined(_MSC_VER)
404 #ifdef FLEXT_SHARED
405 // for compiling a shared flext library FLEXT_EXPORTS must be defined
406 #ifdef FLEXT_EXPORTS
407 #define FLEXT_SHARE __declspec(dllexport)
408 #else
409 #define FLEXT_SHARE __declspec(dllimport)
410 #endif
411 #else
412 #define FLEXT_SHARE
413 #endif
414 #define FLEXT_EXT __declspec(dllexport)
415#else // other OS's
416 #define FLEXT_SHARE
417 #define FLEXT_EXT
418#endif
419
420
421// std namespace
422#ifdef __MWERKS__
423# define STD std
424#else
425# define STD
426#endif
427
428// branching hints
429#if __GNUC__ >= 3
430# ifndef LIKELY
431# define LIKELY(expression) (__builtin_expect(!!(expression), 1))
432# endif
433# ifndef UNLIKELY
434# define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
435# endif
436#else
437# ifndef LIKELY
438# define LIKELY(expression) (expression)
439# endif
440# ifndef UNLIKELY
441# define UNLIKELY(expression) (expression)
442# endif
443#endif
444
445// macro definitions for inline flext usage
446#ifdef FLEXT_INLINE
447# define FLEXT_TEMPLATE template<typename flext_T>
448# define FLEXT_TEMPIMPL(fun) template<typename flext_T> fun<flext_T>
449# define FLEXT_TEMPINST(fun) fun<void>
450# define FLEXT_TEMPSUB(fun) typename fun<flext_T>
451# define FLEXT_TEMP_TYPENAME typename
452#else
453# define FLEXT_TEMPLATE
454# define FLEXT_TEMPIMPL(fun) fun
455# define FLEXT_TEMPINST(fun) fun
456# define FLEXT_TEMPSUB(fun) fun
457# define FLEXT_TEMP_TYPENAME
458#endif
459
460#endif // __FLEXT_PREFIX_H