2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
20 #if defined(__cplusplus) || defined(c_plusplus)
21 # define LDAP_BEGIN_DECL extern "C" {
22 # define LDAP_END_DECL }
24 # define LDAP_BEGIN_DECL /* begin declarations */
25 # define LDAP_END_DECL /* end declarations */
28 #if !defined(LDAP_NO_PROTOTYPES) && ( defined(LDAP_NEEDS_PROTOTYPES) || \
29 defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) )
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 */
39 # define LDAP_CONST const
42 #else /* no prototypes */
45 # define LDAP_P(protos) ()
46 # define LDAP_CONCAT(x,y) x/**/y
47 # define LDAP_STRING(x) "x"
50 # define LDAP_CONST /* no const */
53 #endif /* no prototypes */
55 #if (__GNUC__) * 1000 + (__GNUC_MINOR__) >= 2006
56 # define LDAP_GCCATTR(attrs) __attribute__(attrs)
58 # define LDAP_GCCATTR(attrs)
62 * Support for Windows DLLs.
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.
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.
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.
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.
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.
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
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.
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.
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
136 # define LBER_F(type) extern type
137 # define LBER_V(type) extern type
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
147 # define LDAP_F(type) extern type
148 # define LDAP_V(type) extern type
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
156 # define LDAP_AVL_F(type) extern type
157 # define LDAP_AVL_V(type) extern type
161 /* Not exported/imported any more */
162 # define LDAP_LDBM_F(type) extern type
163 # define LDAP_LDBM_V(type) extern type
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
170 # define LDAP_LDIF_F(type) extern type
171 # define LDAP_LDIF_V(type) extern type
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
179 # define LDAP_LUNICODE_F(type) extern type
180 # define LDAP_LUNICODE_V(type) extern type
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
188 # define LDAP_LUTIL_F(type) extern type
189 # define LDAP_LUTIL_V(type) extern type
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
197 # define LDAP_REWRITE_F(type) extern type
198 # define LDAP_REWRITE_V(type) extern type
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
206 # define LDAP_SLAPD_F(type) extern type
207 # define LDAP_SLAPD_V(type) extern type
211 * C library. Mingw32 links with the dynamic C run-time library by default,
212 * so the explicit definition of CSTATIC will keep dllimport from
213 * being defined, if desired.
215 * MSVC defines the _DLL macro when the compiler is invoked with /MD or /MDd,
216 * which means the resulting object code will be linked with the dynamic
217 * C run-time library.
219 * Technically, it shouldn't be necessary to redefine any functions that
220 * the headers for the C library should already contain. Nevertheless, this
221 * is here as a safe-guard.
223 * TODO: Determine if these macros ever get expanded for Windows. If not,
224 * the declspec expansion can probably be removed.
226 #if (defined(__MINGW32__) && !defined(CSTATIC)) || \
227 (defined(_MSC_VER) && defined(_DLL))
228 # define LDAP_LIBC_F(type) extern __declspec(dllimport) type
229 # define LDAP_LIBC_V(type) extern __declspec(dllimport) type
231 # define LDAP_LIBC_F(type) extern type
232 # define LDAP_LIBC_V(type) extern type
235 #endif /* _LDAP_CDEFS_H */