smbd: ignore POSIX and stale opens in have_file_open_below()
[samba4-gss.git] / lib / ldb / wscript
blobf234fa79c10c90cb8c90e3e152b1d2f63b5732ed
1 #!/usr/bin/env python
3 # For Samba 4.22.x
4 LDB_VERSION = '2.11.0'
6 import sys, os
8 from wafsamba import samba_dist, samba_utils, samba_bundled
9 from waflib import Errors, Options, Logs, Context
10 import shutil
12 def options(opt):
14 opt.add_option('--without-ldb-lmdb',
15 help='disable new LMDB backend for LDB',
16 action='store_true', dest='without_ldb_lmdb', default=False)
18 def configure(conf):
19 # where does the default LIBDIR end up? in conf.env somewhere?
21 conf.env.ldb_modules_install_dir = conf.SUBST_ENV_VAR('LDBMODULESDIR')
22 conf.CONFIG_PATH('LDB_MODULESDIR', conf.env.ldb_modules_install_dir)
24 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
25 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
26 execute=True,
27 msg='Checking for a 64-bit host to '
28 'support lmdb'):
29 Logs.warn("--without-ldb-lmdb implied as this "
30 "host is not 64-bit")
32 if not Options.options.without_ad_dc and \
33 conf.CONFIG_GET('ENABLE_SELFTEST'):
34 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
36 conf.env.REQUIRE_LMDB = False
37 elif Options.options.without_ldb_lmdb:
38 if not Options.options.without_ad_dc and \
39 conf.CONFIG_GET('ENABLE_SELFTEST'):
40 raise Errors.WafError('--without-ldb-lmdb conflicts '
41 'with --enable-selftest while '
42 'building the AD DC')
44 conf.env.REQUIRE_LMDB = False
45 else:
46 conf.env.REQUIRE_LMDB = True
48 # if lmdb support is enabled then we require lmdb
49 # is present, build the mdb back end and enable lmdb support in
50 # the tools.
51 if conf.env.REQUIRE_LMDB:
52 if not conf.CHECK_CFG(package='lmdb',
53 args='"lmdb >= 0.9.16" --cflags --libs',
54 msg='Checking for lmdb >= 0.9.16',
55 mandatory=False):
56 if not conf.CHECK_CODE('''
57 #if MDB_VERSION_MAJOR == 0 \
58 && MDB_VERSION_MINOR <= 9 \
59 && MDB_VERSION_PATCH < 16
60 #error LMDB too old
61 #endif
62 ''',
63 'HAVE_GOOD_LMDB_VERSION',
64 headers='lmdb.h',
65 msg='Checking for lmdb >= 0.9.16 via header check'):
67 if not Options.options.without_ad_dc:
68 raise Errors.WafError('Samba AD DC and --enable-selftest '
69 'requires '
70 'lmdb 0.9.16 or later')
71 else:
72 raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
73 'requires '
74 'lmdb 0.9.16 or later')
76 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
77 conf.DEFINE('HAVE_LMDB', '1')
78 conf.env.HAVE_LMDB = True
80 conf.env.ldb_is_public_library \
81 = not samba_bundled.LIB_MUST_BE_PRIVATE(conf, 'ldb')
83 def build(bld):
84 bld.env.LDB_PACKAGE_VERSION = LDB_VERSION
86 # we're not currently linking against the ldap libs, but ldb.pc.in
87 # has @LDAP_LIBS@
88 bld.env.LDAP_LIBS = ''
90 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
91 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
93 COMMON_SRC = bld.SUBDIR('common',
94 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
95 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
96 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
98 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
99 init_function='ldb_ldap_init',
100 module_init_name='ldb_init_module',
101 deps='talloc lber ldap ldb',
102 enabled=bld.env.ENABLE_LDAP_BACKEND,
103 internal_module=False,
104 subsystem='ldb')
106 if bld.PYTHON_BUILD_IS_ENABLED():
107 name = bld.pyembed_libname('pyldb-util')
108 bld.SAMBA_LIBRARY(name,
109 deps='replace ldb',
110 source='pyldb_util.c',
111 private_library=True,
112 pyembed=True,
113 enabled=bld.PYTHON_BUILD_IS_ENABLED())
115 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
116 deps='replace ldb ' + name,
117 realname='ldb.so',
118 cflags='-DPACKAGE_VERSION=\"%s\"' % LDB_VERSION)
120 bld.SAMBA_SCRIPT('_ldb_text.py',
121 pattern='_ldb_text.py',
122 installdir='python')
124 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
126 if bld.is_install:
127 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
128 else:
129 # when we run from the source directory, we want to use
130 # the current modules, not the installed ones
131 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
133 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
135 ldb_headers = ('include/ldb.h include/ldb_errors.h '
136 'include/ldb_module.h include/ldb_handlers.h')
138 bld.SAMBA_LIBRARY('ldb',
139 COMMON_SRC + ' ' + LDB_MAP_SRC,
140 deps='tevent LIBLDB_MAIN replace',
141 includes='include',
142 public_headers=ldb_headers,
143 public_headers_install=True,
144 pc_files='ldb.pc',
145 vnum=LDB_VERSION,
146 private_library=False,
147 manpages='man/ldb.3',
148 abi_directory='ABI',
149 abi_match = abi_match)
151 # generate a include/ldb_version.h
152 def generate_ldb_version_h(t):
153 '''generate a vscript file for our public libraries'''
155 tgt = t.outputs[0].bldpath(t.env)
157 v = t.env.LDB_VERSION.split('.')
159 f = open(tgt, mode='w')
160 try:
161 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
162 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
163 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
164 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
165 finally:
166 f.close()
167 return
168 t = bld.SAMBA_GENERATOR('ldb_version.h',
169 rule=generate_ldb_version_h,
170 dep_vars=['LDB_VERSION'],
171 target='include/ldb_version.h',
172 public_headers='include/ldb_version.h',
173 public_headers_install=bld.env.ldb_is_public_library)
174 t.env.LDB_VERSION = LDB_VERSION
176 bld.SAMBA_MODULE('ldb_asq',
177 'modules/asq.c',
178 init_function='ldb_asq_init',
179 module_init_name='ldb_init_module',
180 internal_module=False,
181 deps='ldb',
182 subsystem='ldb')
184 bld.SAMBA_MODULE('ldb_server_sort',
185 'modules/sort.c',
186 init_function='ldb_server_sort_init',
187 internal_module=False,
188 module_init_name='ldb_init_module',
189 deps='ldb',
190 subsystem='ldb')
192 bld.SAMBA_MODULE('ldb_paged_searches',
193 'modules/paged_searches.c',
194 init_function='ldb_paged_searches_init',
195 internal_module=False,
196 module_init_name='ldb_init_module',
197 deps='ldb',
198 subsystem='ldb')
200 bld.SAMBA_MODULE('ldb_rdn_name',
201 'modules/rdn_name.c',
202 init_function='ldb_rdn_name_init',
203 internal_module=False,
204 module_init_name='ldb_init_module',
205 deps='ldb',
206 subsystem='ldb')
208 bld.SAMBA_MODULE('ldb_sample',
209 'tests/sample_module.c',
210 init_function='ldb_sample_init',
211 internal_module=False,
212 module_init_name='ldb_init_module',
213 deps='ldb',
214 subsystem='ldb')
216 bld.SAMBA_MODULE('ldb_skel',
217 'modules/skel.c',
218 init_function='ldb_skel_init',
219 internal_module=False,
220 module_init_name='ldb_init_module',
221 deps='ldb',
222 subsystem='ldb')
224 bld.SAMBA_MODULE('ldb_sqlite3',
225 'sqlite3/ldb_sqlite3.c',
226 init_function='ldb_sqlite3_init',
227 internal_module=False,
228 module_init_name='ldb_init_module',
229 enabled=False,
230 deps='ldb',
231 subsystem='ldb')
233 bld.SAMBA_MODULE('ldb_tdb',
234 bld.SUBDIR('ldb_tdb',
235 '''ldb_tdb_init.c'''),
236 init_function='ldb_tdb_init',
237 module_init_name='ldb_init_module',
238 internal_module=False,
239 deps='ldb ldb_tdb_int ldb_key_value',
240 subsystem='ldb')
242 bld.SAMBA_LIBRARY('ldb_tdb_int',
243 bld.SUBDIR('ldb_tdb',
244 '''ldb_tdb_wrap.c ldb_tdb.c'''),
245 private_library=True,
246 deps='ldb tdb ldb_key_value ldb_tdb_err_map')
248 bld.SAMBA_LIBRARY('ldb_tdb_err_map',
249 bld.SUBDIR('ldb_tdb',
250 '''ldb_tdb_err_map.c '''),
251 private_library=True,
252 deps='ldb tdb')
254 bld.SAMBA_LIBRARY('ldb_key_value',
255 bld.SUBDIR('ldb_key_value',
256 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
257 ldb_kv_cache.c'''),
258 private_library=True,
259 deps='tdb ldb ldb_tdb_err_map')
261 if bld.CONFIG_SET('HAVE_LMDB'):
262 bld.SAMBA_MODULE('ldb_mdb',
263 bld.SUBDIR('ldb_mdb',
264 '''ldb_mdb_init.c'''),
265 init_function='ldb_mdb_init',
266 module_init_name='ldb_init_module',
267 internal_module=False,
268 deps='ldb ldb_key_value ldb_mdb_int',
269 subsystem='ldb')
271 bld.SAMBA_LIBRARY('ldb_mdb_int',
272 bld.SUBDIR('ldb_mdb',
273 '''ldb_mdb.c '''),
274 private_library=True,
275 deps='ldb lmdb ldb_key_value')
276 lmdb_deps = ' ldb_mdb_int'
277 else:
278 lmdb_deps = ''
281 bld.SAMBA_MODULE('ldb_ldb',
282 bld.SUBDIR('ldb_ldb',
283 '''ldb_ldb.c'''),
284 init_function='ldb_ldb_init',
285 module_init_name='ldb_init_module',
286 internal_module=False,
287 deps='ldb ldb_tdb_int ldb_key_value' + lmdb_deps,
288 subsystem='ldb')
290 # have a separate subsystem for common/ldb.c, so it can rebuild
291 # for install with a different -DLDB_MODULESDIR=
292 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
293 'common/ldb.c',
294 deps='tevent tdb',
295 includes='include',
296 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
298 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
299 for t in LDB_TOOLS.split():
300 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
301 manpages='man/%s.1' % t)
303 # ldbtest doesn't get installed
304 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
305 install=False)
307 if bld.CONFIG_SET('HAVE_LMDB'):
308 lmdb_deps = ' lmdb'
309 else:
310 lmdb_deps = ''
311 # ldbdump doesn't get installed
312 bld.SAMBA_BINARY('ldbdump',
313 'tools/ldbdump.c',
314 deps='ldb-cmdline ldb' + lmdb_deps,
315 install=False)
317 bld.SAMBA_LIBRARY('ldb-cmdline',
318 source='tools/ldbutil.c tools/cmdline.c',
319 deps='ldb dl popt',
320 private_library=True)
322 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
323 source='tests/ldb_mod_op_test.c',
324 cflags='-DTEST_BE=\"tdb\"',
325 deps='cmocka ldb',
326 install=False)
328 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
329 source='tests/ldb_mod_op_test.c',
330 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
331 deps='cmocka ldb',
332 install=False)
334 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
335 source='tests/ldb_kv_ops_test.c',
336 cflags='-DTEST_BE=\"tdb\"',
337 deps='cmocka ldb',
338 install=False)
340 bld.SAMBA_BINARY('ldb_tdb_test',
341 source='tests/ldb_tdb_test.c',
342 deps='cmocka ldb',
343 install=False)
345 bld.SAMBA_BINARY('ldb_msg_test',
346 source='tests/ldb_msg.c',
347 deps='cmocka ldb',
348 install=False)
350 bld.SAMBA_BINARY('test_ldb_qsort',
351 source='tests/test_ldb_qsort.c',
352 deps='cmocka ldb',
353 install=False)
355 bld.SAMBA_BINARY('test_ldb_dn',
356 source='tests/test_ldb_dn.c',
357 deps='cmocka ldb',
358 install=False)
360 bld.SAMBA_BINARY('ldb_match_test',
361 source='tests/ldb_match_test.c',
362 deps='cmocka ldb',
363 install=False)
365 bld.SAMBA_BINARY('test_ldb_comparison_fold',
366 source='tests/test_ldb_comparison_fold.c',
367 deps='cmocka ldb ldbwrap',
368 install=False)
370 bld.SAMBA_BINARY('ldb_key_value_test',
371 source='tests/ldb_key_value_test.c',
372 deps='cmocka ldb ldb_tdb_err_map',
373 install=False)
375 bld.SAMBA_BINARY('ldb_parse_test',
376 source='tests/ldb_parse_test.c',
377 deps='cmocka ldb ldb_tdb_err_map',
378 install=False)
380 bld.SAMBA_BINARY('ldb_filter_attrs_test',
381 source='tests/ldb_filter_attrs_test.c',
382 deps='cmocka ldb ldb_tdb_err_map',
383 install=False)
385 bld.SAMBA_BINARY('ldb_filter_attrs_in_place_test',
386 source='tests/ldb_filter_attrs_in_place_test.c',
387 deps='cmocka ldb ldb_tdb_err_map',
388 install=False)
390 bld.SAMBA_BINARY('ldb_key_value_sub_txn_tdb_test',
391 bld.SUBDIR('ldb_key_value',
392 '''ldb_kv_search.c
393 ldb_kv_index.c
394 ldb_kv_cache.c''') +
395 'tests/ldb_key_value_sub_txn_test.c',
396 cflags='-DTEST_BE=\"tdb\"',
397 deps='cmocka ldb ldb_tdb_err_map',
398 install=False)
400 # If both libldap and liblber are available, test ldb_ldap
401 # code for a regression of bz#14413 -- even if we don't build
402 # it ourselves and simply using the system version
403 if bld.env.LIB_LDAP and bld.env.LIB_LBER:
404 bld.SAMBA_BINARY('lldb_ldap_test',
405 source='tests/lldb_ldap.c',
406 deps='cmocka talloc lber ldap ldb',
407 install=False)
409 if bld.CONFIG_SET('HAVE_LMDB'):
410 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
411 source='tests/ldb_mod_op_test.c',
412 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
413 + '-DTEST_LMDB=1',
414 deps='cmocka ldb lmdb',
415 install=False)
417 bld.SAMBA_BINARY('ldb_lmdb_test',
418 source='tests/ldb_lmdb_test.c',
419 deps='cmocka ldb',
420 install=False)
422 bld.SAMBA_BINARY('ldb_lmdb_size_test',
423 source='tests/ldb_lmdb_size_test.c',
424 deps='cmocka ldb',
425 install=False)
427 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
428 source='tests/ldb_kv_ops_test.c',
429 cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
430 deps='cmocka ldb',
431 install=False)
433 bld.SAMBA_BINARY('ldb_lmdb_free_list_test',
434 source='tests/ldb_lmdb_free_list_test.c',
435 cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
436 deps='cmocka ldb',
437 install=False)
439 # We rely on the versions of the ldb_key_value functions included
440 # in ldb_key_value_sub_txn_test.c taking priority over the versions
441 # in the ldb_key_value shared library.
442 # If this turns out to not be the case, the dependencies will
443 # need to be unrolled, and all the source files included and the
444 # ldb_tdb module initialization code will need to be called
445 # manually.
446 bld.SAMBA_BINARY('ldb_key_value_sub_txn_mdb_test',
447 bld.SUBDIR('ldb_key_value',
448 '''ldb_kv_search.c
449 ldb_kv_index.c
450 ldb_kv_cache.c''') +
451 'tests/ldb_key_value_sub_txn_test.c',
452 cflags='-DTEST_BE=\"mdb\"',
453 deps='cmocka ldb ldb_tdb_err_map',
454 install=False)
455 else:
456 bld.SAMBA_BINARY('ldb_no_lmdb_test',
457 source='tests/ldb_no_lmdb_test.c',
458 deps='cmocka ldb',
459 install=False)