1 /*------------------------------------------------------------------------------
2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3 *
4 * Distributable under the terms of either the Apache License (Version 2.0) or
5 * the GNU Lesser General Public License, as specified in the COPYING file.
6 *
7 * Changes are Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
8 ------------------------------------------------------------------------------*/
9 #if !defined(_lucene_COMPILER_GCC)
10 #define _lucene_COMPILER_GCC
11 
12 // It is internal CLucene header - DO NOT include it directly
13 #if !defined(_SUPPRESS_MAKE_BASED_CONFIG)
14     #if defined(_BUILD_FOR_QT_)
15         #include "fulltextsearch/qclucene-config_p.h"
16     #else
17         #include "CLucene/clucene-config.h" //make clucene-config.h file
18     #endif
19 #endif
20 
21 #if defined(_ASCII)
22  #undef _UCS2
23 #elif defined(_UCS2)
24 //
25 #else
26  #define CL_CHARSET_GUESS
27 #endif
28 
29 //dont allow FS_MMAP if mmap is not available
30 #if defined(LUCENE_FS_MMAP) && !defined(_CL_HAVE_MMAP)
31 	#error "LUCENE_FS_MMAP is defined and MMap doesn't appear to be available"
32 #endif
33 
34 #ifdef _CL_HAVE_NO_FUNCTION_TRY_BLOCKS
35     #undef  _LUCENE_DISABLE_EXCEPTIONS
36     #define _LUCENE_DISABLE_EXCEPTIONS
37 
38     #error "this is bad if you made it here... your compiler seems not to have try/catch blocks."
39     #error "maybe you could implement an alternative solution for us? :)"
40 #endif
41 
42 #ifndef _CL_HAVE_NAMESPACES
43 	#define DISABLE_NAMESPACE
44 #endif
45 
46 #define CL_NS_HASHING(func) __gnu_cxx::func
47 #define LUCENE_DISABLE_HASHING //we could enable this, but so far test show that the hashing is slower :(
48 
49 //define the file functions
50 #define fileSeek lseek
51 #define fileSize _filelength
52 #define fileStat stat
53 #define fileHandleStat fstat
54 #ifdef _CL_HAVE_TELL
55     #define fileTell tell
56 #else
57     //ftell (and probably soon ftell64) are POSIX standard functions, but tell and
58     //tell64 are not, so we define fileTell in terms of fileSeek.
59     #define fileTell(fhandle) fileSeek(fhandle, 0, SEEK_CUR)
60 #endif
61 
62 //this is needed early on so that CL_MAX_PATH can be correctly determined
63 //in the StdHeader.h. This was earlier causing problems with macosx.
64 //:: crash was due to realpath() that expects an output arguments that
65 //has at least the size of PATH_MAX (even if the result has a lower size)
66 #include <limits.h>
67 
68 #ifndef _CL_HAVE_WCHAR_T
69     typedef unsigned short wchar_t;
70 #endif
71 
72 #if defined(__CYGWIN__)
73    //cygwin seems to incorrectly define that it has wprintf???
74    #undef _CL_HAVE_WPRINTF
75 #elif defined(__MINGW32__)
76 	#ifndef _CL_HAVE_WINDOWS_H
77 		#define _CL_HAVE_WINDOWS_H
78 	#endif
79 #endif
80 
81 
82 ///////////////////////////////////////////////////////////////////////////////
83 //end _lucene_COMPILER_GCC1
84 #elif !defined(_lucene_COMPILER_GCC2)
85 #define _lucene_COMPILER_GCC2
86     //second inclusion
87 
88     //types
89     #if defined(_CL_HAVE_SYS_TYPES_H)
90         #include <sys/types.h>
91     #endif
92 	#if defined(_CL_HAVE_INTTYPES_H)
93 		#include <inttypes.h>
94 	#elif defined(_CL_HAVE_STDINT_H)
95 		#include <stdint.h>
96 	#else
97 		#if _CL_SIZEOF_UNSIGNED_LONG_LONG==8
98 			typedef unsigned long long uint64_t;
99 			typedef long long int64_t;
100 		#elif _CL_SIZEOF_UNSIGNED_LONG==8
101 			typedef unsigned long uint64_t;
102 			typedef long int64_t;
103 		#else
104 			#error I do not know what to use for a uint64_t.
105 		#endif
106 
107 		/* Give us an unsigned 32-bit data type. */
108 		#if _CL_SIZEOF_UNSIGNED_LONG==4
109 			typedef unsigned long uint32_t;
110 			typedef long int32_t;
111 		#elif _CL_SIZEOF_UNSIGNED_INT==4
112 			typedef unsigned int uint32_t;
113 			typedef int int32_t;
114 		#else
115 			#error I do not know what to use for a uint32_t.
116 		#endif
117 
118 		/* An unsigned 8-bit data type */
119 		#if _CL_SIZEOF_UNSIGNED_CHAR==1
120 			typedef unsigned char uint8_t;
121 		#else
122 			#error I do not know what to use for a uint8_t.
123 		#endif
124 	#endif
125 
126     //second chance to fix default settings
127 	//this must be defined later, otherwise it messes up
128 	//the standard libraries
129 	#if !defined(__MINGW32__)
130 	    #define _close ::close
131 	    #define _read ::read
132 	#endif
133 
134   	//now that int64_t is defined, we can define this...
135 	#ifndef _CL_HAVE_FILELENGTH
136 	    #undef fileSize
137 	    #define fileSize lucene_filelength
138 	    int64_t lucene_filelength(int handle);
139 	#endif
140 
141 #elif !defined(_lucene_COMPILER_GCC3)
142 #define _lucene_COMPILER_GCC3
143     //third inclusion
144 
145 	#if !defined(__MINGW32__)
146 	    //define replacements
147 	    #define O_RANDOM 0
148 	    #undef O_BINARY
149 	    #define O_BINARY 0
150 	    #define _S_IREAD  0444
151 	    #define _S_IWRITE 0333  // write and execute permissions
152 
153 	    //some functions that are needed - not charset dependent and not tchar type functions
154 	    #define _open open
155 	    #define _write write
156 	    #define _snprintf snprintf
157 
158 	    //clucene uses ascii for filename interactions
159 	    #define _realpath(rel,abs) realpath(rel,abs)
160 	    #define _mkdir(x) mkdir(x,0777)
161 	    #define _unlink unlink
162 	#else
163 	    #define _realpath(rel,abs) _fullpath(abs,rel,CL_MAX_PATH)
164 	#endif
165 	//also required by mingw
166 	#define _rename rename
167 #endif
168 
169 #if defined(__GNUC__) && (defined(__sgi) || (defined(Q_OS_SOLARIS) && Q_SOLARIS_VERSION < 10))
170     #undef _CL_HAVE_FLOAT_T
171 #endif
172 
173 #if defined(__GNUC__) && defined(Q_OS_SOLARIS) && Q_SOLARIS_VERSION < 10
174     #undef _CL_HAVE_WCSTOLL
175 #endif
176