ctdb-daemon: Use ctdb_parse_node_address() in ctdbd
[samba4-gss.git] / lib / ldb / wscript
blobeca66a7fe97c96e196bd69eafc0a55c21e3140cd
1 #!/usr/bin/env python
3 # For Samba 4.21.x
4 LDB_VERSION = '2.10.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 else:
38 if Options.options.without_ad_dc:
39 conf.env.REQUIRE_LMDB = False
40 else:
41 if Options.options.without_ldb_lmdb:
42 if not Options.options.without_ad_dc and \
43 conf.CONFIG_GET('ENABLE_SELFTEST'):
44 raise Errors.WafError('--without-ldb-lmdb conflicts '
45 'with --enable-selftest while '
46 'building the AD DC')
48 conf.env.REQUIRE_LMDB = False
49 else:
50 conf.env.REQUIRE_LMDB = True
52 # if lmdb support is enabled then we require lmdb
53 # is present, build the mdb back end and enable lmdb support in
54 # the tools.
55 if conf.env.REQUIRE_LMDB:
56 if not conf.CHECK_CFG(package='lmdb',
57 args='"lmdb >= 0.9.16" --cflags --libs',
58 msg='Checking for lmdb >= 0.9.16',
59 mandatory=False):
60 if not conf.CHECK_CODE('''
61 #if MDB_VERSION_MAJOR == 0 \
62 && MDB_VERSION_MINOR <= 9 \
63 && MDB_VERSION_PATCH < 16
64 #error LMDB too old
65 #endif
66 ''',
67 'HAVE_GOOD_LMDB_VERSION',
68 headers='lmdb.h',
69 msg='Checking for lmdb >= 0.9.16 via header check'):
71 if not Options.options.without_ad_dc:
72 raise Errors.WafError('Samba AD DC and --enable-selftest '
73 'requires '
74 'lmdb 0.9.16 or later')
75 else:
76 raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
77 'requires '
78 'lmdb 0.9.16 or later')
80 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
81 conf.DEFINE('HAVE_LMDB', '1')
82 conf.env.HAVE_LMDB = True
84 conf.env.ldb_is_public_library \
85 = not samba_bundled.LIB_MUST_BE_PRIVATE(conf, 'ldb')
87 def build(bld):
88 bld.env.LDB_PACKAGE_VERSION = LDB_VERSION
90 # we're not currently linking against the ldap libs, but ldb.pc.in
91 # has @LDAP_LIBS@
92 bld.env.LDAP_LIBS = ''
94 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
95 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
97 COMMON_SRC = bld.SUBDIR('common',
98 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
99 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
100 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
102 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
103 init_function='ldb_ldap_init',
104 module_init_name='ldb_init_module',
105 deps='talloc lber ldap ldb',
106 enabled=bld.env.ENABLE_LDAP_BACKEND,
107 internal_module=False,
108 subsystem='ldb')
110 if bld.PYTHON_BUILD_IS_ENABLED():
111 name = bld.pyembed_libname('pyldb-util')
112 bld.SAMBA_LIBRARY(name,
113 deps='replace ldb',
114 source='pyldb_util.c',
115 private_library=True,
116 pyembed=True,
117 enabled=bld.PYTHON_BUILD_IS_ENABLED())
119 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
120 deps='replace ldb ' + name,
121 realname='ldb.so',
122 cflags='-DPACKAGE_VERSION=\"%s\"' % LDB_VERSION)
124 bld.SAMBA_SCRIPT('_ldb_text.py',
125 pattern='_ldb_text.py',
126 installdir='python')
128 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
130 if bld.is_install:
131 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
132 else:
133 # when we run from the source directory, we want to use
134 # the current modules, not the installed ones
135 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
137 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
139 ldb_headers = ('include/ldb.h include/ldb_errors.h '
140 'include/ldb_module.h include/ldb_handlers.h')
142 bld.SAMBA_LIBRARY('ldb',
143 COMMON_SRC + ' ' + LDB_MAP_SRC,
144 deps='tevent LIBLDB_MAIN replace',
145 includes='include',
146 public_headers=ldb_headers,
147 public_headers_install=True,
148 pc_files='ldb.pc',
149 vnum=LDB_VERSION,
150 private_library=False,
151 manpages='man/ldb.3',
152 abi_directory='ABI',
153 abi_match = abi_match)
155 # generate a include/ldb_version.h
156 def generate_ldb_version_h(t):
157 '''generate a vscript file for our public libraries'''
159 tgt = t.outputs[0].bldpath(t.env)
161 v = t.env.LDB_VERSION.split('.')
163 f = open(tgt, mode='w')
164 try:
165 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
166 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
167 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
168 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
169 finally:
170 f.close()
171 return
172 t = bld.SAMBA_GENERATOR('ldb_version.h',
173 rule=generate_ldb_version_h,
174 dep_vars=['LDB_VERSION'],
175 target='include/ldb_version.h',
176 public_headers='include/ldb_version.h',
177 public_headers_install=not bld.env.ldb_is_public_library)
178 t.env.LDB_VERSION = LDB_VERSION
180 bld.SAMBA_MODULE('ldb_asq',
181 'modules/asq.c',
182 init_function='ldb_asq_init',
183 module_init_name='ldb_init_module',
184 internal_module=False,
185 deps='ldb',
186 subsystem='ldb')
188 bld.SAMBA_MODULE('ldb_server_sort',
189 'modules/sort.c',
190 init_function='ldb_server_sort_init',
191 internal_module=False,
192 module_init_name='ldb_init_module',
193 deps='ldb',
194 subsystem='ldb')
196 bld.SAMBA_MODULE('ldb_paged_searches',
197 'modules/paged_searches.c',
198 init_function='ldb_paged_searches_init',
199 internal_module=False,
200 module_init_name='ldb_init_module',
201 deps='ldb',
202 subsystem='ldb')
204 bld.SAMBA_MODULE('ldb_rdn_name',
205 'modules/rdn_name.c',
206 init_function='ldb_rdn_name_init',
207 internal_module=False,
208 module_init_name='ldb_init_module',
209 deps='ldb',
210 subsystem='ldb')
212 bld.SAMBA_MODULE('ldb_sample',
213 'tests/sample_module.c',
214 init_function='ldb_sample_init',
215 internal_module=False,
216 module_init_name='ldb_init_module',
217 deps='ldb',
218 subsystem='ldb')
220 bld.SAMBA_MODULE('ldb_skel',
221 'modules/skel.c',
222 init_function='ldb_skel_init',
223 internal_module=False,
224 module_init_name='ldb_init_module',
225 deps='ldb',
226 subsystem='ldb')
228 bld.SAMBA_MODULE('ldb_sqlite3',
229 'sqlite3/ldb_sqlite3.c',
230 init_function='ldb_sqlite3_init',
231 internal_module=False,
232 module_init_name='ldb_init_module',
233 enabled=False,
234 deps='ldb',
235 subsystem='ldb')
237 bld.SAMBA_MODULE('ldb_tdb',
238 bld.SUBDIR('ldb_tdb',
239 '''ldb_tdb_init.c'''),
240 init_function='ldb_tdb_init',
241 module_init_name='ldb_init_module',
242 internal_module=False,
243 deps='ldb ldb_tdb_int ldb_key_value',
244 subsystem='ldb')
246 bld.SAMBA_LIBRARY('ldb_tdb_int',
247 bld.SUBDIR('ldb_tdb',
248 '''ldb_tdb_wrap.c ldb_tdb.c'''),
249 private_library=True,
250 deps='ldb tdb ldb_key_value ldb_tdb_err_map')
252 bld.SAMBA_LIBRARY('ldb_tdb_err_map',
253 bld.SUBDIR('ldb_tdb',
254 '''ldb_tdb_err_map.c '''),
255 private_library=True,
256 deps='ldb tdb')
258 bld.SAMBA_LIBRARY('ldb_key_value',
259 bld.SUBDIR('ldb_key_value',
260 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
261 ldb_kv_cache.c'''),
262 private_library=True,
263 deps='tdb ldb ldb_tdb_err_map')
265 if bld.CONFIG_SET('HAVE_LMDB'):
266 bld.SAMBA_MODULE('ldb_mdb',
267 bld.SUBDIR('ldb_mdb',
268 '''ldb_mdb_init.c'''),
269 init_function='ldb_mdb_init',
270 module_init_name='ldb_init_module',
271 internal_module=False,
272 deps='ldb ldb_key_value ldb_mdb_int',
273 subsystem='ldb')
275 bld.SAMBA_LIBRARY('ldb_mdb_int',
276 bld.SUBDIR('ldb_mdb',
277 '''ldb_mdb.c '''),
278 private_library=True,
279 deps='ldb lmdb ldb_key_value')
280 lmdb_deps = ' ldb_mdb_int'
281 else:
282 lmdb_deps = ''
285 bld.SAMBA_MODULE('ldb_ldb',
286 bld.SUBDIR('ldb_ldb',
287 '''ldb_ldb.c'''),
288 init_function='ldb_ldb_init',
289 module_init_name='ldb_init_module',
290 internal_module=False,
291 deps='ldb ldb_tdb_int ldb_key_value' + lmdb_deps,
292 subsystem='ldb')
294 # have a separate subsystem for common/ldb.c, so it can rebuild
295 # for install with a different -DLDB_MODULESDIR=
296 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
297 'common/ldb.c',
298 deps='tevent tdb',
299 includes='include',
300 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
302 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
303 for t in LDB_TOOLS.split():
304 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
305 manpages='man/%s.1' % t)
307 # ldbtest doesn't get installed
308 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
309 install=False)
311 if bld.CONFIG_SET('HAVE_LMDB'):
312 lmdb_deps = ' lmdb'
313 else:
314 lmdb_deps = ''
315 # ldbdump doesn't get installed
316 bld.SAMBA_BINARY('ldbdump',
317 'tools/ldbdump.c',
318 deps='ldb-cmdline ldb' + lmdb_deps,
319 install=False)
321 bld.SAMBA_LIBRARY('ldb-cmdline',
322 source='tools/ldbutil.c tools/cmdline.c',
323 deps='ldb dl popt',
324 private_library=True)
326 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
327 source='tests/ldb_mod_op_test.c',
328 cflags='-DTEST_BE=\"tdb\"',
329 deps='cmocka ldb',
330 install=False)
332 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
333 source='tests/ldb_mod_op_test.c',
334 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
335 deps='cmocka ldb',
336 install=False)
338 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
339 source='tests/ldb_kv_ops_test.c',
340 cflags='-DTEST_BE=\"tdb\"',
341 deps='cmocka ldb',
342 install=False)
344 bld.SAMBA_BINARY('ldb_tdb_test',
345 source='tests/ldb_tdb_test.c',
346 deps='cmocka ldb',
347 install=False)
349 bld.SAMBA_BINARY('ldb_msg_test',
350 source='tests/ldb_msg.c',
351 deps='cmocka ldb',
352 install=False)
354 bld.SAMBA_BINARY('test_ldb_qsort',
355 source='tests/test_ldb_qsort.c',
356 deps='cmocka ldb',
357 install=False)
359 bld.SAMBA_BINARY('test_ldb_dn',
360 source='tests/test_ldb_dn.c',
361 deps='cmocka ldb',
362 install=False)
364 bld.SAMBA_BINARY('ldb_match_test',
365 source='tests/ldb_match_test.c',
366 deps='cmocka ldb',
367 install=False)
369 bld.SAMBA_BINARY('test_ldb_comparison_fold',
370 source='tests/test_ldb_comparison_fold.c',
371 deps='cmocka ldb ldbwrap',
372 install=False)
374 bld.SAMBA_BINARY('ldb_key_value_test',
375 source='tests/ldb_key_value_test.c',
376 deps='cmocka ldb ldb_tdb_err_map',
377 install=False)
379 bld.SAMBA_BINARY('ldb_parse_test',
380 source='tests/ldb_parse_test.c',
381 deps='cmocka ldb ldb_tdb_err_map',
382 install=False)
384 bld.SAMBA_BINARY('ldb_filter_attrs_test',
385 source='tests/ldb_filter_attrs_test.c',
386 deps='cmocka ldb ldb_tdb_err_map',
387 install=False)
389 bld.SAMBA_BINARY('ldb_filter_attrs_in_place_test',
390 source='tests/ldb_filter_attrs_in_place_test.c',
391 deps='cmocka ldb ldb_tdb_err_map',
392 install=False)
394 bld.SAMBA_BINARY('ldb_key_value_sub_txn_tdb_test',
395 bld.SUBDIR('ldb_key_value',
396 '''ldb_kv_search.c
397 ldb_kv_index.c
398 ldb_kv_cache.c''') +
399 'tests/ldb_key_value_sub_txn_test.c',
400 cflags='-DTEST_BE=\"tdb\"',
401 deps='cmocka ldb ldb_tdb_err_map',
402 install=False)
404 # If both libldap and liblber are available, test ldb_ldap
405 # code for a regression of bz#14413 -- even if we don't build
406 # it ourselves and simply using the system version
407 if bld.env.LIB_LDAP and bld.env.LIB_LBER:
408 bld.SAMBA_BINARY('lldb_ldap_test',
409 source='tests/lldb_ldap.c',
410 deps='cmocka talloc lber ldap ldb',
411 install=False)
413 if bld.CONFIG_SET('HAVE_LMDB'):
414 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
415 source='tests/ldb_mod_op_test.c',
416 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
417 + '-DTEST_LMDB=1',
418 deps='cmocka ldb lmdb',
419 install=False)
421 bld.SAMBA_BINARY('ldb_lmdb_test',
422 source='tests/ldb_lmdb_test.c',
423 deps='cmocka ldb',
424 install=False)
426 bld.SAMBA_BINARY('ldb_lmdb_size_test',
427 source='tests/ldb_lmdb_size_test.c',
428 deps='cmocka ldb',
429 install=False)
431 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
432 source='tests/ldb_kv_ops_test.c',
433 cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
434 deps='cmocka ldb',
435 install=False)
437 bld.SAMBA_BINARY('ldb_lmdb_free_list_test',
438 source='tests/ldb_lmdb_free_list_test.c',
439 cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
440 deps='cmocka ldb',
441 install=False)
443 # We rely on the versions of the ldb_key_value functions included
444 # in ldb_key_value_sub_txn_test.c taking priority over the versions
445 # in the ldb_key_value shared library.
446 # If this turns out to not be the case, the dependencies will
447 # need to be unrolled, and all the source files included and the
448 # ldb_tdb module initialization code will need to be called
449 # manually.
450 bld.SAMBA_BINARY('ldb_key_value_sub_txn_mdb_test',
451 bld.SUBDIR('ldb_key_value',
452 '''ldb_kv_search.c
453 ldb_kv_index.c
454 ldb_kv_cache.c''') +
455 'tests/ldb_key_value_sub_txn_test.c',
456 cflags='-DTEST_BE=\"mdb\"',
457 deps='cmocka ldb ldb_tdb_err_map',
458 install=False)
459 else:
460 bld.SAMBA_BINARY('ldb_no_lmdb_test',
461 source='tests/ldb_no_lmdb_test.c',
462 deps='cmocka ldb',
463 install=False)