1 /***************************************************************************/
5 /* ANSI-specific configuration file (specification only). */
7 /* Copyright 1996-2004, 2006-2008, 2010-2011, 2013, 2014 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 /*************************************************************************/
21 /* This header file contains a number of macro definitions that are used */
22 /* by the rest of the engine. Most of the macros here are automatically */
23 /* determined at compile time, and you should not need to change it to */
24 /* port FreeType, except to compile the library with a non-ANSI */
27 /* Note however that if some specific modifications are needed, we */
28 /* advise you to place a modified copy in your build directory. */
30 /* The build directory is usually `builds/<system>', and contains */
31 /* system-specific files that are always included first when building */
34 /* This ANSI version should stay in `include/config/'. */
36 /*************************************************************************/
38 #ifndef __FTCONFIG_H__
39 #define __FTCONFIG_H__
42 #include FT_CONFIG_OPTIONS_H
43 #include FT_CONFIG_STANDARD_LIBRARY_H
49 /*************************************************************************/
51 /* PLATFORM-SPECIFIC CONFIGURATION MACROS */
53 /* These macros can be toggled to suit a specific system. The current */
54 /* ones are defaults used to compile FreeType in an ANSI C environment */
55 /* (16bit compilers are also supported). Copy this file to your own */
56 /* `builds/<system>' directory, and edit it to port the engine. */
58 /*************************************************************************/
61 /* There are systems (like the Texas Instruments 'C54x) where a `char' */
62 /* has 16 bits. ANSI C says that sizeof(char) is always 1. Since an */
63 /* `int' has 16 bits also for this system, sizeof(int) gives 1 which */
64 /* is probably unexpected. */
66 /* `CHAR_BIT' (defined in limits.h) gives the number of bits in a */
70 #define FT_CHAR_BIT CHAR_BIT
74 /* The size of an `int' type. */
75 #if FT_UINT_MAX == 0xFFFFUL
76 #define FT_SIZEOF_INT (16 / FT_CHAR_BIT)
77 #elif FT_UINT_MAX == 0xFFFFFFFFUL
78 #define FT_SIZEOF_INT (32 / FT_CHAR_BIT)
79 #elif FT_UINT_MAX > 0xFFFFFFFFUL && FT_UINT_MAX == 0xFFFFFFFFFFFFFFFFUL
80 #define FT_SIZEOF_INT (64 / FT_CHAR_BIT)
82 #error "Unsupported size of `int' type!"
85 /* The size of a `long' type. A five-byte `long' (as used e.g. on the */
86 /* DM642) is recognized but avoided. */
87 #if FT_ULONG_MAX == 0xFFFFFFFFUL
88 #define FT_SIZEOF_LONG (32 / FT_CHAR_BIT)
89 #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFUL
90 #define FT_SIZEOF_LONG (32 / FT_CHAR_BIT)
91 #elif FT_ULONG_MAX > 0xFFFFFFFFUL && FT_ULONG_MAX == 0xFFFFFFFFFFFFFFFFUL
92 #define FT_SIZEOF_LONG (64 / FT_CHAR_BIT)
94 #error "Unsupported size of `long' type!"
98 /* FT_UNUSED is a macro used to indicate that a given parameter is not */
99 /* used -- this is only used to get rid of unpleasant compiler warnings */
101 #define FT_UNUSED( arg ) ( (arg) = (arg) )
105 /*************************************************************************/
107 /* AUTOMATIC CONFIGURATION MACROS */
109 /* These macros are computed from the ones defined above. Don't touch */
110 /* their definition, unless you know precisely what you are doing. No */
111 /* porter should need to mess with them. */
113 /*************************************************************************/
116 /*************************************************************************/
120 /* This is the only necessary change, so it is defined here instead */
121 /* providing a new configuration file. */
123 #if defined( __APPLE__ ) || ( defined( __MWERKS__ ) && defined( macintosh ) )
124 /* no Carbon frameworks for 64bit 10.4.x */
125 /* AvailabilityMacros.h is available since Mac OS X 10.2, */
126 /* so guess the system version by maximum errno before inclusion */
128 #ifdef ECANCELED /* defined since 10.2 */
129 #include "AvailabilityMacros.h"
131 #if defined( __LP64__ ) && \
132 ( MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 )
136 #elif defined( __SC__ ) || defined( __MRC__ )
137 /* Classic MacOS compilers */
138 #include "ConditionalMacros.h"
140 #define FT_MACINTOSH 1
146 /*************************************************************************/
151 /*************************************************************************/
154 /*************************************************************************/
160 /* A typedef for a 16bit signed integer type. */
162 typedef signed short FT_Int16
;
165 /*************************************************************************/
171 /* A typedef for a 16bit unsigned integer type. */
173 typedef unsigned short FT_UInt16
;
178 /* this #if 0 ... #endif clause is for documentation purposes */
181 /*************************************************************************/
187 /* A typedef for a 32bit signed integer type. The size depends on */
188 /* the configuration. */
190 typedef signed XXX FT_Int32
;
193 /*************************************************************************/
198 /* A typedef for a 32bit unsigned integer type. The size depends on */
199 /* the configuration. */
201 typedef unsigned XXX FT_UInt32
;
204 /*************************************************************************/
209 /* A typedef for a 64bit signed integer type. The size depends on */
210 /* the configuration. Only defined if there is real 64bit support; */
211 /* otherwise, it gets emulated with a structure (if necessary). */
213 typedef signed XXX FT_Int64
;
216 /*************************************************************************/
221 /* A typedef for a 64bit unsigned integer type. The size depends on */
222 /* the configuration. Only defined if there is real 64bit support; */
223 /* otherwise, it gets emulated with a structure (if necessary). */
225 typedef unsigned XXX FT_UInt64
;
231 #if FT_SIZEOF_INT == (32 / FT_CHAR_BIT)
233 typedef signed int FT_Int32
;
234 typedef unsigned int FT_UInt32
;
236 #elif FT_SIZEOF_LONG == (32 / FT_CHAR_BIT)
238 typedef signed long FT_Int32
;
239 typedef unsigned long FT_UInt32
;
242 #error "no 32bit type found -- please check your configuration files"
246 /* look up an integer type that is at least 32 bits */
247 #if FT_SIZEOF_INT >= (32 / FT_CHAR_BIT)
250 typedef unsigned int FT_UFast
;
252 #elif FT_SIZEOF_LONG >= (32 / FT_CHAR_BIT)
254 typedef long FT_Fast
;
255 typedef unsigned long FT_UFast
;
260 /* determine whether we have a 64-bit int type for platforms without */
262 #if FT_SIZEOF_LONG == (64 / FT_CHAR_BIT)
264 /* FT_LONG64 must be defined if a 64-bit type is available */
266 #define FT_INT64 long
267 #define FT_UINT64 unsigned long
269 #elif defined( _MSC_VER ) && _MSC_VER >= 900 /* Visual C++ (and Intel C++) */
271 /* this compiler provides the __int64 type */
273 #define FT_INT64 __int64
274 #define FT_UINT64 unsigned __int64
276 #elif defined( __BORLANDC__ ) /* Borland C++ */
278 /* XXXX: We should probably check the value of __BORLANDC__ in order */
279 /* to test the compiler version. */
281 /* this compiler provides the __int64 type */
283 #define FT_INT64 __int64
284 #define FT_UINT64 unsigned __int64
286 #elif defined( __WATCOMC__ ) /* Watcom C++ */
288 /* Watcom doesn't provide 64-bit data types */
290 #elif defined( __MWERKS__ ) /* Metrowerks CodeWarrior */
293 #define FT_INT64 long long int
294 #define FT_UINT64 unsigned long long int
296 #elif defined( __GNUC__ )
298 /* GCC provides the `long long' type */
300 #define FT_INT64 long long int
301 #define FT_UINT64 unsigned long long int
303 #endif /* FT_SIZEOF_LONG == (64 / FT_CHAR_BIT) */
306 /*************************************************************************/
308 /* A 64-bit data type will create compilation problems if you compile */
309 /* in strict ANSI mode. To avoid them, we disable its use if __STDC__ */
310 /* is defined. You can however ignore this rule by defining the */
311 /* FT_CONFIG_OPTION_FORCE_INT64 configuration macro. */
313 #if defined( FT_LONG64 ) && !defined( FT_CONFIG_OPTION_FORCE_INT64 )
317 /* undefine the 64-bit macros in strict ANSI compilation mode */
321 #endif /* __STDC__ */
323 #endif /* FT_LONG64 && !FT_CONFIG_OPTION_FORCE_INT64 */
326 typedef FT_INT64 FT_Int64
;
327 typedef FT_UINT64 FT_UInt64
;
331 #define FT_BEGIN_STMNT do {
332 #define FT_END_STMNT } while ( 0 )
333 #define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT
336 #ifndef FT_CONFIG_OPTION_NO_ASSEMBLER
337 /* Provide assembler fragments for performance-critical functions. */
338 /* These must be defined `static __inline__' with GCC. */
340 #if defined( __CC_ARM ) || defined( __ARMCC__ ) /* RVCT */
342 #define FT_MULFIX_ASSEMBLER FT_MulFix_arm
344 /* documentation is in freetype.h */
346 static __inline FT_Int32
347 FT_MulFix_arm( FT_Int32 a
,
350 register FT_Int32 t
, t2
;
355 smull t2
, t
, b
, a
/* (lo=t2,hi=t) = a*b */
356 mov a
, t
, asr
#31 /* a = (hi >> 31) */
357 add a
, a
, #0x8000 /* a += 0x8000 */
358 adds t2
, t2
, a
/* t2 += a */
359 adc t
, t
, #0 /* t += carry */
360 mov a
, t2
, lsr
#16 /* a = t2 >> 16 */
361 orr a
, a
, t
, lsl
#16 /* a |= t << 16 */
366 #endif /* __CC_ARM || __ARMCC__ */
371 #if defined( __arm__ ) && \
372 ( !defined( __thumb__ ) || defined( __thumb2__ ) ) && \
373 !( defined( __CC_ARM ) || defined( __ARMCC__ ) )
375 #define FT_MULFIX_ASSEMBLER FT_MulFix_arm
377 /* documentation is in freetype.h */
379 static __inline__ FT_Int32
380 FT_MulFix_arm( FT_Int32 a
,
383 register FT_Int32 t
, t2
;
386 __asm__
__volatile__ (
387 "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */
388 "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */
389 #if defined( __clang__ ) && defined( __thumb2__ )
390 "add.w %0, %0, #0x8000\n\t" /* %0 += 0x8000 */
392 "add %0, %0, #0x8000\n\t" /* %0 += 0x8000 */
394 "adds %1, %1, %0\n\t" /* %1 += %0 */
395 "adc %2, %2, #0\n\t" /* %2 += carry */
396 "mov %0, %1, lsr #16\n\t" /* %0 = %1 >> 16 */
397 "orr %0, %0, %2, lsl #16\n\t" /* %0 |= %2 << 16 */
398 : "=r"(a
), "=&r"(t2
), "=&r"(t
)
404 #endif /* __arm__ && */
405 /* ( __thumb2__ || !__thumb__ ) && */
406 /* !( __CC_ARM || __ARMCC__ ) */
409 #if defined( __i386__ )
411 #define FT_MULFIX_ASSEMBLER FT_MulFix_i386
413 /* documentation is in freetype.h */
415 static __inline__ FT_Int32
416 FT_MulFix_i386( FT_Int32 a
,
419 register FT_Int32 result
;
422 __asm__
__volatile__ (
424 "movl %%edx, %%ecx\n"
426 "addl $0x8000, %%ecx\n"
427 "addl %%ecx, %%eax\n"
431 "addl %%edx, %%eax\n"
432 : "=a"(result
), "=d"(b
)
440 #endif /* __GNUC__ */
443 #ifdef _MSC_VER /* Visual C++ */
447 #define FT_MULFIX_ASSEMBLER FT_MulFix_i386
449 /* documentation is in freetype.h */
451 static __inline FT_Int32
452 FT_MulFix_i386( FT_Int32 a
,
455 register FT_Int32 result
;
477 #endif /* _MSC_VER */
480 #if defined( __GNUC__ ) && defined( __x86_64__ )
482 #define FT_MULFIX_ASSEMBLER FT_MulFix_x86_64
484 static __inline__ FT_Int32
485 FT_MulFix_x86_64( FT_Int32 a
,
488 /* Temporarily disable the warning that C90 doesn't support */
490 #if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) )
491 #pragma GCC diagnostic push
492 #pragma GCC diagnostic ignored "-Wlong-long"
496 /* Technically not an assembly fragment, but GCC does a really good */
497 /* job at inlining it and generating good machine code for it. */
501 ret
= (long long)a
* b
;
505 return (FT_Int32
)( ret
>> 16 );
508 /* For some reason, GCC 4.6 on Ubuntu 12.04 generates invalid machine */
509 /* code from the lines below. The main issue is that `wide_a' is not */
510 /* properly initialized by sign-extending `a'. Instead, the generated */
511 /* machine code assumes that the register that contains `a' on input */
512 /* can be used directly as a 64-bit value, which is wrong most of the */
514 long long wide_a
= (long long)a
;
515 long long wide_b
= (long long)b
;
519 __asm__
__volatile__ (
523 "lea 0x8000(%1, %0), %0\n"
525 : "=&r"(result
), "=&r"(wide_a
)
529 return (FT_Int32
)result
;
532 #if ( __GNUC__ > 4 ) || ( ( __GNUC__ == 4 ) && ( __GNUC_MINOR__ >= 6 ) )
533 #pragma GCC diagnostic pop
537 #endif /* __GNUC__ && __x86_64__ */
539 #endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
542 #ifdef FT_CONFIG_OPTION_INLINE_MULFIX
543 #ifdef FT_MULFIX_ASSEMBLER
544 #define FT_MULFIX_INLINED FT_MULFIX_ASSEMBLER
549 #ifdef FT_MAKE_OPTION_SINGLE_OBJECT
551 #define FT_LOCAL( x ) static x
552 #define FT_LOCAL_DEF( x ) static x
557 #define FT_LOCAL( x ) extern "C" x
558 #define FT_LOCAL_DEF( x ) extern "C" x
560 #define FT_LOCAL( x ) extern x
561 #define FT_LOCAL_DEF( x ) x
564 #endif /* FT_MAKE_OPTION_SINGLE_OBJECT */
566 #define FT_LOCAL_ARRAY( x ) extern const x
567 #define FT_LOCAL_ARRAY_DEF( x ) const x
573 #define FT_BASE( x ) extern "C" x
575 #define FT_BASE( x ) extern x
578 #endif /* !FT_BASE */
584 #define FT_BASE_DEF( x ) x
586 #define FT_BASE_DEF( x ) x
589 #endif /* !FT_BASE_DEF */
595 #define FT_EXPORT( x ) extern "C" x
597 #define FT_EXPORT( x ) extern x
600 #endif /* !FT_EXPORT */
603 #ifndef FT_EXPORT_DEF
606 #define FT_EXPORT_DEF( x ) extern "C" x
608 #define FT_EXPORT_DEF( x ) extern x
611 #endif /* !FT_EXPORT_DEF */
614 #ifndef FT_EXPORT_VAR
617 #define FT_EXPORT_VAR( x ) extern "C" x
619 #define FT_EXPORT_VAR( x ) extern x
622 #endif /* !FT_EXPORT_VAR */
624 /* The following macros are needed to compile the library with a */
625 /* C++ compiler and with 16bit compilers. */
628 /* This is special. Within C++, you must specify `extern "C"' for */
629 /* functions which are used via function pointers, and you also */
630 /* must do that for structures which contain function pointers to */
631 /* assure C linkage -- it's not possible to have (local) anonymous */
632 /* functions which are accessed by (global) function pointers. */
635 /* FT_CALLBACK_DEF is used to _define_ a callback function. */
637 /* FT_CALLBACK_TABLE is used to _declare_ a constant variable that */
638 /* contains pointers to callback functions. */
640 /* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable */
641 /* that contains pointers to callback functions. */
644 /* Some 16bit compilers have to redefine these macros to insert */
645 /* the infamous `_cdecl' or `__fastcall' declarations. */
647 #ifndef FT_CALLBACK_DEF
649 #define FT_CALLBACK_DEF( x ) extern "C" x
651 #define FT_CALLBACK_DEF( x ) static x
653 #endif /* FT_CALLBACK_DEF */
655 #ifndef FT_CALLBACK_TABLE
657 #define FT_CALLBACK_TABLE extern "C"
658 #define FT_CALLBACK_TABLE_DEF extern "C"
660 #define FT_CALLBACK_TABLE extern
661 #define FT_CALLBACK_TABLE_DEF /* nothing */
663 #endif /* FT_CALLBACK_TABLE */
669 #endif /* __FTCONFIG_H__ */