]> git.sur5r.net Git - openldap/blob - include/ldap_cdefs.h
large X (for version.sh)
[openldap] / include / ldap_cdefs.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  * 
4  * Copyright 1998-2008 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* LDAP C Defines */
16
17 #ifndef _LDAP_CDEFS_H
18 #define _LDAP_CDEFS_H
19
20 #if defined(__cplusplus) || defined(c_plusplus)
21 #       define LDAP_BEGIN_DECL  extern "C" {
22 #       define LDAP_END_DECL    }
23 #else
24 #       define LDAP_BEGIN_DECL  /* begin declarations */
25 #       define LDAP_END_DECL    /* end declarations */
26 #endif
27
28 #if !defined(LDAP_NO_PROTOTYPES) && ( defined(LDAP_NEEDS_PROTOTYPES) || \
29         defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) )
30
31         /* ANSI C or C++ */
32 #       define LDAP_P(protos)   protos
33 #       define LDAP_CONCAT1(x,y)        x ## y
34 #       define LDAP_CONCAT(x,y) LDAP_CONCAT1(x,y)
35 #       define LDAP_STRING(x)   #x /* stringify without expanding x */
36 #       define LDAP_XSTRING(x)  LDAP_STRING(x) /* expand x, then stringify */
37
38 #ifndef LDAP_CONST
39 #       define LDAP_CONST       const
40 #endif
41
42 #else /* no prototypes */
43
44         /* traditional C */
45 #       define LDAP_P(protos)   ()
46 #       define LDAP_CONCAT(x,y) x/**/y
47 #       define LDAP_STRING(x)   "x"
48
49 #ifndef LDAP_CONST
50 #       define LDAP_CONST       /* no const */
51 #endif
52
53 #endif /* no prototypes */
54
55 #if (__GNUC__) * 1000 + (__GNUC_MINOR__) >= 2006
56 #       define LDAP_GCCATTR(attrs)      __attribute__(attrs)
57 #else
58 #       define LDAP_GCCATTR(attrs)
59 #endif
60
61 /*
62  * Support for Windows DLLs.
63  *
64  * When external source code includes header files for dynamic libraries,
65  * the external source code is "importing" DLL symbols into its resulting
66  * object code. On Windows, symbols imported from DLLs must be explicitly
67  * indicated in header files with the __declspec(dllimport) directive.
68  * This is not totally necessary for functions because the compiler
69  * (gcc or MSVC) will generate stubs when this directive is absent.
70  * However, this is required for imported variables.
71  *
72  * The LDAP libraries, i.e. liblber and libldap, can be built as
73  * static or shared, based on configuration. Just about all other source
74  * code in OpenLDAP use these libraries. If the LDAP libraries
75  * are configured as shared, 'configure' defines the LDAP_LIBS_DYNAMIC
76  * macro. When other source files include LDAP library headers, the
77  * LDAP library symbols will automatically be marked as imported. When
78  * the actual LDAP libraries are being built, the symbols will not
79  * be marked as imported because the LBER_LIBRARY or LDAP_LIBRARY macros
80  * will be respectively defined.
81  *
82  * Any project outside of OpenLDAP with source code wanting to use
83  * LDAP dynamic libraries should explicitly define LDAP_LIBS_DYNAMIC.
84  * This will ensure that external source code appropriately marks symbols
85  * that will be imported.
86  *
87  * The slapd executable, itself, can be used as a dynamic library.
88  * For example, if a backend module is compiled as shared, it will
89  * import symbols from slapd. When this happens, the slapd symbols
90  * must be marked as imported in header files that the backend module
91  * includes. Remember that slapd links with various static libraries.
92  * If the LDAP libraries were configured as static, their object
93  * code is also part of the monolithic slapd executable. Thus, when
94  * a backend module imports symbols from slapd, it imports symbols from
95  * all of the static libraries in slapd as well. Thus, the SLAP_IMPORT
96  * macro, when defined, will appropriately mark symbols as imported.
97  * This macro should be used by shared backend modules as well as any
98  * other external source code that imports symbols from the slapd
99  * executable as if it were a DLL.
100  *
101  * Note that we don't actually have to worry about using the
102  * __declspec(dllexport) directive anywhere. This is because both
103  * MSVC and Mingw provide alternate (more effective) methods for exporting
104  * symbols out of binaries, i.e. the use of a DEF file.
105  *
106  * NOTE ABOUT BACKENDS: Backends can be configured as static or dynamic.
107  * When a backend is configured as dynamic, slapd will load the backend
108  * explicitly and populate function pointer structures by calling
109  * the backend's well-known initialization function. Because of this
110  * procedure, slapd never implicitly imports symbols from dynamic backends.
111  * This makes it unnecessary to tag various backend functions with the
112  * __declspec(dllimport) directive. This is because neither slapd nor
113  * any other external binary should ever be implicitly loading a backend
114  * dynamic module.
115  *
116  * Backends are supposed to be self-contained. However, it appears that
117  * back-meta DOES implicitly import symbols from back-ldap. This means
118  * that the __declspec(dllimport) directive should be marked on back-ldap
119  * functions (in its header files) if and only if we're compiling for
120  * windows AND back-ldap has been configured as dynamic AND back-meta
121  * is the client of back-ldap. When client is slapd, there is no effect
122  * since slapd does not implicitly import symbols.
123  *
124  * TODO(?): Currently, back-meta nor back-ldap is supported for Mingw32.
125  * Thus, there's no need to worry about this right now. This is something that
126  * may or may not have to be addressed in the future.
127  */
128
129 /* LBER library */
130 #if defined(_WIN32) && \
131     ((defined(LDAP_LIBS_DYNAMIC) && !defined(LBER_LIBRARY)) || \
132      (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
133 #       define LBER_F(type)             extern __declspec(dllimport) type
134 #       define LBER_V(type)             extern __declspec(dllimport) type
135 #else
136 #       define LBER_F(type)             extern type
137 #       define LBER_V(type)             extern type
138 #endif
139
140 /* LDAP library */
141 #if defined(_WIN32) && \
142     ((defined(LDAP_LIBS_DYNAMIC) && !defined(LDAP_LIBRARY)) || \
143      (!defined(LDAP_LIBS_DYNAMIC) && defined(SLAPD_IMPORT)))
144 #       define LDAP_F(type)             extern __declspec(dllimport) type
145 #       define LDAP_V(type)             extern __declspec(dllimport) type
146 #else
147 #       define LDAP_F(type)             extern type
148 #       define LDAP_V(type)             extern type
149 #endif
150
151 /* AVL library */
152 #if defined(_WIN32) && defined(SLAPD_IMPORT)
153 #       define LDAP_AVL_F(type)         extern __declspec(dllimport) type
154 #       define LDAP_AVL_V(type)         extern __declspec(dllimport) type
155 #else
156 #       define LDAP_AVL_F(type)         extern type
157 #       define LDAP_AVL_V(type)         extern type
158 #endif
159
160 /* LDBM library */
161 /* Not exported/imported any more */
162 #       define LDAP_LDBM_F(type)        extern type
163 #       define LDAP_LDBM_V(type)        extern type
164
165 /* LDIF library */
166 #if defined(_WIN32) && defined(SLAPD_IMPORT)
167 #       define LDAP_LDIF_F(type)        extern __declspec(dllimport) type
168 #       define LDAP_LDIF_V(type)        extern __declspec(dllimport) type
169 #else
170 #       define LDAP_LDIF_F(type)        extern type
171 #       define LDAP_LDIF_V(type)        extern type
172 #endif
173
174 /* LUNICODE library */
175 #if defined(_WIN32) && defined(SLAPD_IMPORT)
176 #       define LDAP_LUNICODE_F(type)    extern __declspec(dllimport) type
177 #       define LDAP_LUNICODE_V(type)    extern __declspec(dllimport) type
178 #else
179 #       define LDAP_LUNICODE_F(type)    extern type
180 #       define LDAP_LUNICODE_V(type)    extern type
181 #endif
182
183 /* LUTIL library */
184 #if defined(_WIN32) && defined(SLAPD_IMPORT)
185 #       define LDAP_LUTIL_F(type)       extern __declspec(dllimport) type
186 #       define LDAP_LUTIL_V(type)       extern __declspec(dllimport) type
187 #else
188 #       define LDAP_LUTIL_F(type)       extern type
189 #       define LDAP_LUTIL_V(type)       extern type
190 #endif
191
192 /* REWRITE library */
193 #if defined(_WIN32) && defined(SLAPD_IMPORT)
194 #       define LDAP_REWRITE_F(type)     extern __declspec(dllimport) type
195 #       define LDAP_REWRITE_V(type)     extern __declspec(dllimport) type
196 #else
197 #       define LDAP_REWRITE_F(type)     extern type
198 #       define LDAP_REWRITE_V(type)     extern type
199 #endif
200
201 /* SLAPD (as a dynamic library exporting symbols) */
202 #if defined(_WIN32) && defined(SLAPD_IMPORT)
203 #       define LDAP_SLAPD_F(type)       extern __declspec(dllimport) type
204 #       define LDAP_SLAPD_V(type)       extern __declspec(dllimport) type
205 #else
206 #       define LDAP_SLAPD_F(type)       extern type
207 #       define LDAP_SLAPD_V(type)       extern type
208 #endif
209
210 /* SLAPD (as a dynamic library exporting symbols) */
211 #if defined(_WIN32) && defined(SLAPD_IMPORT)
212 #       define LDAP_SLAPI_F(type)       extern __declspec(dllimport) type
213 #       define LDAP_SLAPI_V(type)       extern __declspec(dllimport) type
214 #else
215 #       define LDAP_SLAPI_F(type)       extern type
216 #       define LDAP_SLAPI_V(type)       extern type
217 #endif
218
219 /* SLAPD (as a dynamic library exporting symbols) */
220 #if defined(_WIN32) && defined(SLAPD_IMPORT)
221 #       define SLAPI_F(type)            extern __declspec(dllimport) type
222 #       define SLAPI_V(type)            extern __declspec(dllimport) type
223 #else
224 #       define SLAPI_F(type)            extern type
225 #       define SLAPI_V(type)            extern type
226 #endif
227
228 /*
229  * C library. Mingw32 links with the dynamic C run-time library by default,
230  * so the explicit definition of CSTATIC will keep dllimport from
231  * being defined, if desired.
232  *
233  * MSVC defines the _DLL macro when the compiler is invoked with /MD or /MDd,
234  * which means the resulting object code will be linked with the dynamic
235  * C run-time library.
236  *
237  * Technically, it shouldn't be necessary to redefine any functions that
238  * the headers for the C library should already contain. Nevertheless, this
239  * is here as a safe-guard.
240  *
241  * TODO: Determine if these macros ever get expanded for Windows. If not,
242  * the declspec expansion can probably be removed.
243  */
244 #if (defined(__MINGW32__) && !defined(CSTATIC)) || \
245     (defined(_MSC_VER) && defined(_DLL))
246 #       define LDAP_LIBC_F(type)        extern __declspec(dllimport) type
247 #       define LDAP_LIBC_V(type)        extern __declspec(dllimport) type
248 #else
249 #       define LDAP_LIBC_F(type)        extern type
250 #       define LDAP_LIBC_V(type)        extern type
251 #endif
252
253 #endif /* _LDAP_CDEFS_H */