8 # find the buildtools directory
10 while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5:
12 sys.path.insert(0, top + '/buildtools/wafsamba')
17 from wafsamba import samba_dist, samba_utils
18 from waflib import Errors, Options, Logs, Context
21 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
22 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
23 third_party/popt:third_party/popt
24 third_party/cmocka:third_party/cmocka
25 buildtools:buildtools third_party/waf:third_party/waf''')
27 samba_dist.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
30 opt.BUILTIN_DEFAULT('replace')
31 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
32 opt.RECURSE('lib/tdb')
33 opt.RECURSE('lib/tevent')
34 opt.RECURSE('lib/replace')
35 opt.load('python') # options for disabling pyc or pyo compilation
37 opt.add_option('--without-ldb-lmdb',
38 help='disable new LMDB backend for LDB',
39 action='store_true', dest='without_ldb_lmdb', default=False)
43 conf.RECURSE('lib/tdb')
44 conf.RECURSE('lib/tevent')
46 if conf.CHECK_FOR_THIRD_PARTY():
47 conf.RECURSE('third_party/popt')
48 conf.RECURSE('third_party/cmocka')
50 if not conf.CHECK_POPT():
51 raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
53 conf.define('USING_SYSTEM_POPT', 1)
55 if not conf.CHECK_CMOCKA():
56 raise Errors.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
58 conf.define('USING_SYSTEM_CMOCKA', 1)
60 conf.RECURSE('lib/replace')
61 conf.find_program('xsltproc', var='XSLTPROC')
62 conf.SAMBA_CHECK_PYTHON()
63 conf.SAMBA_CHECK_PYTHON_HEADERS()
65 # where does the default LIBDIR end up? in conf.env somewhere?
67 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
69 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
71 if not conf.env.standalone_ldb:
72 max_ldb_version = [int(x) for x in VERSION.split(".")]
73 max_ldb_version[2] = 999
74 max_ldb_version_dots = "%d.%d.%d" % tuple(max_ldb_version)
76 if conf.env.disable_python:
77 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
79 maxversion=max_ldb_version_dots,
80 onlyif='talloc tdb tevent',
81 implied_deps='replace talloc tdb tevent'):
82 conf.define('USING_SYSTEM_LDB', 1)
84 using_system_pyldb_util = True
85 dflt_name = 'pyldb-util' + conf.all_envs['default']['PYTHON_SO_ABI_FLAG']
86 if not conf.CHECK_BUNDLED_SYSTEM_PKG(dflt_name,
88 maxversion=max_ldb_version_dots,
89 onlyif='talloc tdb tevent',
90 implied_deps='replace talloc tdb tevent ldb'):
91 using_system_pyldb_util = False
93 if using_system_pyldb_util:
94 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
96 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
98 maxversion=max_ldb_version_dots,
99 onlyif='talloc tdb tevent %s' % dflt_name,
100 implied_deps='replace talloc tdb tevent'):
101 conf.define('USING_SYSTEM_LDB', 1)
103 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
104 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
106 msg='Checking for a 64-bit host to '
108 Logs.warn("--without-ldb-lmdb implied as this "
109 "host is not 64-bit")
111 if not conf.env.standalone_ldb and \
112 not Options.options.without_ad_dc and \
113 conf.CONFIG_GET('ENABLE_SELFTEST'):
114 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
116 conf.env.REQUIRE_LMDB = False
118 if conf.env.standalone_ldb:
119 if Options.options.without_ldb_lmdb:
120 conf.env.REQUIRE_LMDB = False
122 conf.env.REQUIRE_LMDB = True
123 elif Options.options.without_ad_dc:
124 conf.env.REQUIRE_LMDB = False
126 if Options.options.without_ldb_lmdb:
127 if not Options.options.without_ad_dc and \
128 conf.CONFIG_GET('ENABLE_SELFTEST'):
129 raise Errors.WafError('--without-ldb-lmdb conflicts '
130 'with --enable-selftest while '
131 'building the AD DC')
133 conf.env.REQUIRE_LMDB = False
135 conf.env.REQUIRE_LMDB = True
138 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
139 v = VERSION.split('.')
140 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
141 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
142 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
144 if conf.env.standalone_ldb:
145 conf.CHECK_XSLTPROC_MANPAGES()
147 # we need this for the ldap backend
148 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
149 conf.env.ENABLE_LDAP_BACKEND = True
151 # we don't want any libraries or modules to rely on runtime
152 # resolution of symbols
153 if not sys.platform.startswith("openbsd"):
154 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
156 # if lmdb support is enabled then we require lmdb
157 # is present, build the mdb back end and enable lmdb support in
159 if conf.env.REQUIRE_LMDB and \
160 not conf.CONFIG_SET('USING_SYSTEM_LDB'):
161 if not conf.CHECK_CFG(package='lmdb',
162 args='"lmdb >= 0.9.16" --cflags --libs',
163 msg='Checking for lmdb >= 0.9.16',
165 if not conf.CHECK_CODE('''
166 #if MDB_VERSION_MAJOR == 0 \
167 && MDB_VERSION_MINOR <= 9 \
168 && MDB_VERSION_PATCH < 16
172 'HAVE_GOOD_LMDB_VERSION',
174 msg='Checking for lmdb >= 0.9.16 via header check'):
176 if conf.env.standalone_ldb:
177 raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
179 'lmdb 0.9.16 or later')
180 elif not Options.options.without_ad_dc:
181 raise Errors.WafError('Samba AD DC and --enable-selftest '
183 'lmdb 0.9.16 or later')
185 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
186 conf.DEFINE('HAVE_LMDB', '1')
187 conf.env.HAVE_LMDB = True
190 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
192 conf.SAMBA_CONFIG_H()
194 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
197 bld.RECURSE('lib/tevent')
199 if bld.CHECK_FOR_THIRD_PARTY():
200 bld.RECURSE('third_party/popt')
201 bld.RECURSE('third_party/cmocka')
203 bld.RECURSE('lib/replace')
204 bld.RECURSE('lib/tdb')
206 if bld.env.standalone_ldb:
207 if not 'PACKAGE_VERSION' in bld.env:
208 bld.env.PACKAGE_VERSION = VERSION
209 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
210 private_library = False
212 private_library = True
213 # we're not currently linking against the ldap libs, but ldb.pc.in
215 bld.env.LDAP_LIBS = ''
217 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
218 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
220 COMMON_SRC = bld.SUBDIR('common',
221 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
222 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
223 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
225 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
226 init_function='ldb_ldap_init',
227 module_init_name='ldb_init_module',
228 deps='talloc lber ldap ldb',
229 enabled=bld.env.ENABLE_LDAP_BACKEND,
230 internal_module=False,
233 if bld.PYTHON_BUILD_IS_ENABLED():
234 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
235 name = bld.pyembed_libname('pyldb-util')
236 bld.SAMBA_LIBRARY(name,
238 source='pyldb_util.c',
239 public_headers=('' if private_library else 'pyldb.h'),
240 public_headers_install=not private_library,
242 private_library=private_library,
243 pc_files='pyldb-util.pc',
245 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
249 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
250 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
251 deps='replace ldb ' + name,
253 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
255 # Do only install this file as part of the Samba build if we do not
256 # use the system libldb!
257 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
258 bld.SAMBA_SCRIPT('_ldb_text.py',
259 pattern='_ldb_text.py',
262 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
264 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
266 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
268 # when we run from the source directory, we want to use
269 # the current modules, not the installed ones
270 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
272 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
274 ldb_headers = ('include/ldb.h include/ldb_errors.h '
275 'include/ldb_module.h include/ldb_handlers.h')
277 bld.SAMBA_LIBRARY('ldb',
278 COMMON_SRC + ' ' + LDB_MAP_SRC,
279 deps='tevent LIBLDB_MAIN replace',
281 public_headers=('' if private_library else ldb_headers),
282 public_headers_install=not private_library,
285 private_library=private_library,
286 manpages='man/ldb.3',
288 abi_match = abi_match)
290 # generate a include/ldb_version.h
291 def generate_ldb_version_h(t):
292 '''generate a vscript file for our public libraries'''
294 tgt = t.outputs[0].bldpath(t.env)
296 v = t.env.LDB_VERSION.split('.')
298 f = open(tgt, mode='w')
300 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
301 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
302 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
303 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
307 t = bld.SAMBA_GENERATOR('ldb_version.h',
308 rule=generate_ldb_version_h,
309 dep_vars=['LDB_VERSION'],
310 target='include/ldb_version.h',
311 public_headers='include/ldb_version.h',
312 public_headers_install=not private_library)
313 t.env.LDB_VERSION = VERSION
315 bld.SAMBA_MODULE('ldb_asq',
317 init_function='ldb_asq_init',
318 module_init_name='ldb_init_module',
319 internal_module=False,
323 bld.SAMBA_MODULE('ldb_server_sort',
325 init_function='ldb_server_sort_init',
326 internal_module=False,
327 module_init_name='ldb_init_module',
331 bld.SAMBA_MODULE('ldb_paged_searches',
332 'modules/paged_searches.c',
333 init_function='ldb_paged_searches_init',
334 internal_module=False,
335 module_init_name='ldb_init_module',
339 bld.SAMBA_MODULE('ldb_rdn_name',
340 'modules/rdn_name.c',
341 init_function='ldb_rdn_name_init',
342 internal_module=False,
343 module_init_name='ldb_init_module',
347 bld.SAMBA_MODULE('ldb_sample',
348 'tests/sample_module.c',
349 init_function='ldb_sample_init',
350 internal_module=False,
351 module_init_name='ldb_init_module',
355 bld.SAMBA_MODULE('ldb_skel',
357 init_function='ldb_skel_init',
358 internal_module=False,
359 module_init_name='ldb_init_module',
363 bld.SAMBA_MODULE('ldb_sqlite3',
364 'sqlite3/ldb_sqlite3.c',
365 init_function='ldb_sqlite3_init',
366 internal_module=False,
367 module_init_name='ldb_init_module',
372 bld.SAMBA_MODULE('ldb_tdb',
373 bld.SUBDIR('ldb_tdb',
374 '''ldb_tdb_init.c'''),
375 init_function='ldb_tdb_init',
376 module_init_name='ldb_init_module',
377 internal_module=False,
378 deps='ldb ldb_tdb_int ldb_key_value',
381 bld.SAMBA_LIBRARY('ldb_tdb_int',
382 bld.SUBDIR('ldb_tdb',
383 '''ldb_tdb_wrap.c ldb_tdb.c'''),
384 private_library=True,
385 deps='ldb tdb ldb_key_value ldb_tdb_err_map')
387 bld.SAMBA_LIBRARY('ldb_tdb_err_map',
388 bld.SUBDIR('ldb_tdb',
389 '''ldb_tdb_err_map.c '''),
390 private_library=True,
393 bld.SAMBA_LIBRARY('ldb_key_value',
394 bld.SUBDIR('ldb_key_value',
395 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
397 private_library=True,
398 deps='tdb ldb ldb_tdb_err_map')
400 if bld.CONFIG_SET('HAVE_LMDB'):
401 bld.SAMBA_MODULE('ldb_mdb',
402 bld.SUBDIR('ldb_mdb',
403 '''ldb_mdb_init.c'''),
404 init_function='ldb_mdb_init',
405 module_init_name='ldb_init_module',
406 internal_module=False,
407 deps='ldb ldb_key_value ldb_mdb_int',
410 bld.SAMBA_LIBRARY('ldb_mdb_int',
411 bld.SUBDIR('ldb_mdb',
413 private_library=True,
414 deps='ldb lmdb ldb_key_value')
415 lmdb_deps = ' ldb_mdb_int'
420 bld.SAMBA_MODULE('ldb_ldb',
421 bld.SUBDIR('ldb_ldb',
423 init_function='ldb_ldb_init',
424 module_init_name='ldb_init_module',
425 internal_module=False,
426 deps='ldb ldb_tdb_int ldb_key_value' + lmdb_deps,
429 # have a separate subsystem for common/ldb.c, so it can rebuild
430 # for install with a different -DLDB_MODULESDIR=
431 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
435 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
437 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
438 for t in LDB_TOOLS.split():
439 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
440 manpages='man/%s.1' % t)
442 # ldbtest doesn't get installed
443 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
446 if bld.CONFIG_SET('HAVE_LMDB'):
450 # ldbdump doesn't get installed
451 bld.SAMBA_BINARY('ldbdump',
453 deps='ldb-cmdline ldb' + lmdb_deps,
456 bld.SAMBA_LIBRARY('ldb-cmdline',
457 source='tools/ldbutil.c tools/cmdline.c',
459 private_library=True)
461 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
462 source='tests/ldb_mod_op_test.c',
463 cflags='-DTEST_BE=\"tdb\"',
467 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
468 source='tests/ldb_mod_op_test.c',
469 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
473 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
474 source='tests/ldb_kv_ops_test.c',
475 cflags='-DTEST_BE=\"tdb\"',
479 bld.SAMBA_BINARY('ldb_tdb_test',
480 source='tests/ldb_tdb_test.c',
484 bld.SAMBA_BINARY('ldb_msg_test',
485 source='tests/ldb_msg.c',
489 bld.SAMBA_BINARY('test_ldb_qsort',
490 source='tests/test_ldb_qsort.c',
494 bld.SAMBA_BINARY('test_ldb_dn',
495 source='tests/test_ldb_dn.c',
499 bld.SAMBA_BINARY('ldb_match_test',
500 source='tests/ldb_match_test.c',
504 if bld.CONFIG_SET('HAVE_LMDB'):
505 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
506 source='tests/ldb_mod_op_test.c',
507 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
509 deps='cmocka ldb lmdb',
512 bld.SAMBA_BINARY('ldb_lmdb_test',
513 source='tests/ldb_lmdb_test.c',
517 bld.SAMBA_BINARY('ldb_lmdb_size_test',
518 source='tests/ldb_lmdb_size_test.c',
522 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
523 source='tests/ldb_kv_ops_test.c',
524 cflags='-DTEST_BE=\"mdb\"',
528 bld.SAMBA_BINARY('ldb_no_lmdb_test',
529 source='tests/ldb_no_lmdb_test.c',
534 '''run ldb testsuite'''
535 env = samba_utils.LOAD_ENVIRONMENT()
538 test_prefix = "%s/st" % (Context.g_module.out)
539 shutil.rmtree(test_prefix, ignore_errors=True)
540 os.makedirs(test_prefix)
541 os.environ['TEST_DATA_PREFIX'] = test_prefix
542 os.environ['LDB_MODULES_PATH'] = Context.g_module.out + "/modules/ldb"
544 os.environ['HAVE_LMDB'] = '1'
546 os.environ['HAVE_LMDB'] = '0'
547 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
548 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
550 cmd = 'tests/test-tdb.sh %s' % Context.g_module.out
551 ret = samba_utils.RUN_COMMAND(cmd)
552 print("testsuite returned %d" % ret)
554 tmp_dir = os.path.join(test_prefix, 'tmp')
555 if not os.path.exists(tmp_dir):
557 pyret = samba_utils.RUN_PYTHON_TESTS(
558 ['tests/python/api.py', 'tests/python/index.py'],
559 extra_env={'SELFTEST_PREFIX': test_prefix})
560 print("Python testsuite returned %d" % pyret)
563 test_exes = ['test_ldb_qsort',
566 'ldb_tdb_mod_op_test',
567 'ldb_tdb_guid_mod_op_test',
569 'ldb_tdb_kv_ops_test',
574 test_exes += ['ldb_mdb_mod_op_test',
576 # we don't want to run ldb_lmdb_size_test (which proves we can
577 # fit > 4G of data into the DB), it would fill up the disk on
578 # many of our test instances
579 'ldb_mdb_kv_ops_test']
581 test_exes += ['ldb_no_lmdb_test']
583 for test_exe in test_exes:
584 cmd = os.path.join(Context.g_module.out, test_exe)
585 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
587 sys.exit(ret or pyret or cmocka_ret)
590 '''makes a tarball for distribution'''
593 def reconfigure(ctx):
594 '''reconfigure if config scripts have changed'''
596 samba_utils.reconfigure(ctx)