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('python', var='PYTHON')
62 conf.find_program('xsltproc', var='XSLTPROC')
64 conf.check_python_version((2,4,2))
65 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
67 # where does the default LIBDIR end up? in conf.env somewhere?
69 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
71 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
73 if not conf.env.standalone_ldb:
74 max_ldb_version = [int(x) for x in VERSION.split(".")]
75 max_ldb_version[2] = 999
76 max_ldb_version_dots = "%d.%d.%d" % tuple(max_ldb_version)
78 if conf.env.disable_python:
79 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
81 maxversion=max_ldb_version_dots,
82 onlyif='talloc tdb tevent',
83 implied_deps='replace talloc tdb tevent'):
84 conf.define('USING_SYSTEM_LDB', 1)
86 using_system_pyldb_util = True
87 dflt_name = 'pyldb-util' + conf.all_envs['default']['PYTHON_SO_ABI_FLAG']
88 if not conf.CHECK_BUNDLED_SYSTEM_PKG(dflt_name,
90 maxversion=max_ldb_version_dots,
91 onlyif='talloc tdb tevent',
92 implied_deps='replace talloc tdb tevent ldb'):
93 using_system_pyldb_util = False
95 # We need to get a pyldb-util for all the python versions
97 if conf.env['EXTRA_PYTHON']:
98 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
99 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name,
101 maxversion=max_ldb_version_dots,
102 onlyif='talloc tdb tevent',
103 implied_deps='replace talloc tdb tevent ldb'):
104 using_system_pyldb_util = False
106 if using_system_pyldb_util:
107 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
109 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
111 maxversion=max_ldb_version_dots,
112 onlyif='talloc tdb tevent %s' % dflt_name,
113 implied_deps='replace talloc tdb tevent'):
114 conf.define('USING_SYSTEM_LDB', 1)
116 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
117 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
119 msg='Checking for a 64-bit host to '
121 Logs.warn("--without-ldb-lmdb implied as this "
122 "host is not 64-bit")
124 if not conf.env.standalone_ldb and \
125 not Options.options.without_ad_dc and \
126 conf.CONFIG_GET('ENABLE_SELFTEST'):
127 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
129 conf.env.REQUIRE_LMDB = False
131 if conf.env.standalone_ldb:
132 if Options.options.without_ldb_lmdb:
133 conf.env.REQUIRE_LMDB = False
135 conf.env.REQUIRE_LMDB = True
136 elif Options.options.without_ad_dc:
137 conf.env.REQUIRE_LMDB = False
139 if Options.options.without_ldb_lmdb:
140 if not Options.options.without_ad_dc and \
141 conf.CONFIG_GET('ENABLE_SELFTEST'):
142 raise Errors.WafError('--without-ldb-lmdb conflicts '
143 'with --enable-selftest while '
144 'building the AD DC')
146 conf.env.REQUIRE_LMDB = False
148 conf.env.REQUIRE_LMDB = True
151 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
152 v = VERSION.split('.')
153 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
154 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
155 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
157 if conf.env.standalone_ldb:
158 conf.CHECK_XSLTPROC_MANPAGES()
160 # we need this for the ldap backend
161 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
162 conf.env.ENABLE_LDAP_BACKEND = True
164 # we don't want any libraries or modules to rely on runtime
165 # resolution of symbols
166 if not sys.platform.startswith("openbsd"):
167 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
169 # if lmdb support is enabled then we require lmdb
170 # is present, build the mdb back end and enable lmdb support in
172 if conf.env.REQUIRE_LMDB and \
173 not conf.CONFIG_SET('USING_SYSTEM_LDB'):
174 if not conf.CHECK_CFG(package='lmdb',
175 args='"lmdb >= 0.9.16" --cflags --libs',
176 msg='Checking for lmdb >= 0.9.16',
178 if not conf.CHECK_CODE('''
179 #if MDB_VERSION_MAJOR == 0 \
180 && MDB_VERSION_MINOR <= 9 \
181 && MDB_VERSION_PATCH < 16
185 'HAVE_GOOD_LMDB_VERSION',
187 msg='Checking for lmdb >= 0.9.16 via header check'):
189 if conf.env.standalone_ldb:
190 raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
192 'lmdb 0.9.16 or later')
193 elif not Options.options.without_ad_dc:
194 raise Errors.WafError('Samba AD DC and --enable-selftest '
196 'lmdb 0.9.16 or later')
198 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
199 conf.DEFINE('HAVE_LMDB', '1')
202 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
204 conf.SAMBA_CONFIG_H()
206 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
209 bld.RECURSE('lib/tevent')
211 if bld.CHECK_FOR_THIRD_PARTY():
212 bld.RECURSE('third_party/popt')
213 bld.RECURSE('third_party/cmocka')
215 bld.RECURSE('lib/replace')
216 bld.RECURSE('lib/tdb')
218 if bld.env.standalone_ldb:
219 if not 'PACKAGE_VERSION' in bld.env:
220 bld.env.PACKAGE_VERSION = VERSION
221 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
222 private_library = False
224 private_library = True
225 # we're not currently linking against the ldap libs, but ldb.pc.in
227 bld.env.LDAP_LIBS = ''
229 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
230 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
232 COMMON_SRC = bld.SUBDIR('common',
233 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
234 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
235 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
237 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
238 init_function='ldb_ldap_init',
239 module_init_name='ldb_init_module',
240 deps='talloc lber ldap ldb',
241 enabled=bld.env.ENABLE_LDAP_BACKEND,
242 internal_module=False,
245 if bld.PYTHON_BUILD_IS_ENABLED():
246 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
247 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
249 name = bld.pyembed_libname('pyldb-util')
250 bld.SAMBA_LIBRARY(name,
252 source='pyldb_util.c',
253 public_headers=('' if private_library else 'pyldb.h'),
254 public_headers_install=not private_library,
256 private_library=private_library,
257 pc_files='pyldb-util.pc',
259 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
263 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
264 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
265 deps='replace ldb ' + name,
267 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
269 # Do only install this file as part of the Samba build if we do not
270 # use the system libldb!
271 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
272 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
273 bld.SAMBA_SCRIPT('_ldb_text.py',
274 pattern='_ldb_text.py',
277 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
279 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
281 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
283 # when we run from the source directory, we want to use
284 # the current modules, not the installed ones
285 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
287 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
289 ldb_headers = ('include/ldb.h include/ldb_errors.h '
290 'include/ldb_module.h include/ldb_handlers.h')
292 bld.SAMBA_LIBRARY('ldb',
293 COMMON_SRC + ' ' + LDB_MAP_SRC,
294 deps='tevent LIBLDB_MAIN replace',
296 public_headers=('' if private_library else ldb_headers),
297 public_headers_install=not private_library,
300 private_library=private_library,
301 manpages='man/ldb.3',
303 abi_match = abi_match)
305 # generate a include/ldb_version.h
306 def generate_ldb_version_h(t):
307 '''generate a vscript file for our public libraries'''
309 tgt = t.outputs[0].bldpath(t.env)
311 v = t.env.LDB_VERSION.split('.')
313 f = open(tgt, mode='w')
315 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
316 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
317 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
318 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
322 t = bld.SAMBA_GENERATOR('ldb_version.h',
323 rule=generate_ldb_version_h,
324 dep_vars=['LDB_VERSION'],
325 target='include/ldb_version.h',
326 public_headers='include/ldb_version.h',
327 public_headers_install=not private_library)
328 t.env.LDB_VERSION = VERSION
330 bld.SAMBA_MODULE('ldb_asq',
332 init_function='ldb_asq_init',
333 module_init_name='ldb_init_module',
334 internal_module=False,
338 bld.SAMBA_MODULE('ldb_server_sort',
340 init_function='ldb_server_sort_init',
341 internal_module=False,
342 module_init_name='ldb_init_module',
346 bld.SAMBA_MODULE('ldb_paged_searches',
347 'modules/paged_searches.c',
348 init_function='ldb_paged_searches_init',
349 internal_module=False,
350 module_init_name='ldb_init_module',
354 bld.SAMBA_MODULE('ldb_rdn_name',
355 'modules/rdn_name.c',
356 init_function='ldb_rdn_name_init',
357 internal_module=False,
358 module_init_name='ldb_init_module',
362 bld.SAMBA_MODULE('ldb_sample',
363 'tests/sample_module.c',
364 init_function='ldb_sample_init',
365 internal_module=False,
366 module_init_name='ldb_init_module',
370 bld.SAMBA_MODULE('ldb_skel',
372 init_function='ldb_skel_init',
373 internal_module=False,
374 module_init_name='ldb_init_module',
378 bld.SAMBA_MODULE('ldb_sqlite3',
379 'sqlite3/ldb_sqlite3.c',
380 init_function='ldb_sqlite3_init',
381 internal_module=False,
382 module_init_name='ldb_init_module',
387 bld.SAMBA_MODULE('ldb_tdb',
388 bld.SUBDIR('ldb_tdb',
389 '''ldb_tdb_init.c'''),
390 init_function='ldb_tdb_init',
391 module_init_name='ldb_init_module',
392 internal_module=False,
393 deps='ldb ldb_tdb_int ldb_key_value',
396 bld.SAMBA_LIBRARY('ldb_tdb_int',
397 bld.SUBDIR('ldb_tdb',
398 '''ldb_tdb_wrap.c ldb_tdb.c'''),
399 private_library=True,
400 deps='ldb tdb ldb_key_value ldb_tdb_err_map')
402 bld.SAMBA_LIBRARY('ldb_tdb_err_map',
403 bld.SUBDIR('ldb_tdb',
404 '''ldb_tdb_err_map.c '''),
405 private_library=True,
408 bld.SAMBA_LIBRARY('ldb_key_value',
409 bld.SUBDIR('ldb_key_value',
410 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
412 private_library=True,
413 deps='tdb ldb ldb_tdb_err_map')
415 if bld.CONFIG_SET('HAVE_LMDB'):
416 bld.SAMBA_MODULE('ldb_mdb',
417 bld.SUBDIR('ldb_mdb',
418 '''ldb_mdb_init.c'''),
419 init_function='ldb_mdb_init',
420 module_init_name='ldb_init_module',
421 internal_module=False,
422 deps='ldb ldb_key_value ldb_mdb_int',
425 bld.SAMBA_LIBRARY('ldb_mdb_int',
426 bld.SUBDIR('ldb_mdb',
428 private_library=True,
429 deps='ldb lmdb ldb_key_value')
430 lmdb_deps = ' ldb_mdb_int'
435 bld.SAMBA_MODULE('ldb_ldb',
436 bld.SUBDIR('ldb_ldb',
438 init_function='ldb_ldb_init',
439 module_init_name='ldb_init_module',
440 internal_module=False,
441 deps='ldb ldb_tdb_int ldb_key_value' + lmdb_deps,
444 # have a separate subsystem for common/ldb.c, so it can rebuild
445 # for install with a different -DLDB_MODULESDIR=
446 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
450 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
452 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
453 for t in LDB_TOOLS.split():
454 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
455 manpages='man/%s.1' % t)
457 # ldbtest doesn't get installed
458 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
461 if bld.CONFIG_SET('HAVE_LMDB'):
465 # ldbdump doesn't get installed
466 bld.SAMBA_BINARY('ldbdump',
468 deps='ldb-cmdline ldb' + lmdb_deps,
471 bld.SAMBA_LIBRARY('ldb-cmdline',
472 source='tools/ldbutil.c tools/cmdline.c',
474 private_library=True)
476 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
477 source='tests/ldb_mod_op_test.c',
478 cflags='-DTEST_BE=\"tdb\"',
482 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
483 source='tests/ldb_mod_op_test.c',
484 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
488 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
489 source='tests/ldb_kv_ops_test.c',
490 cflags='-DTEST_BE=\"tdb\"',
494 bld.SAMBA_BINARY('ldb_tdb_test',
495 source='tests/ldb_tdb_test.c',
499 bld.SAMBA_BINARY('ldb_msg_test',
500 source='tests/ldb_msg.c',
504 bld.SAMBA_BINARY('test_ldb_qsort',
505 source='tests/test_ldb_qsort.c',
509 bld.SAMBA_BINARY('test_ldb_dn',
510 source='tests/test_ldb_dn.c',
514 bld.SAMBA_BINARY('ldb_match_test',
515 source='tests/ldb_match_test.c',
519 if bld.CONFIG_SET('HAVE_LMDB'):
520 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
521 source='tests/ldb_mod_op_test.c',
522 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
524 deps='cmocka ldb lmdb',
527 bld.SAMBA_BINARY('ldb_lmdb_test',
528 source='tests/ldb_lmdb_test.c',
532 bld.SAMBA_BINARY('ldb_lmdb_size_test',
533 source='tests/ldb_lmdb_size_test.c',
537 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
538 source='tests/ldb_kv_ops_test.c',
539 cflags='-DTEST_BE=\"mdb\"',
544 '''run ldb testsuite'''
545 env = samba_utils.LOAD_ENVIRONMENT()
548 if not env.HAVE_LMDB:
549 raise Errors.WafError('make test called, but ldb was built '
550 '--without-ldb-lmdb')
552 test_prefix = "%s/st" % (Context.g_module.out)
553 shutil.rmtree(test_prefix, ignore_errors=True)
554 os.makedirs(test_prefix)
555 os.environ['TEST_DATA_PREFIX'] = test_prefix
556 os.environ['LDB_MODULES_PATH'] = Context.g_module.out + "/modules/ldb"
557 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
558 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
560 cmd = 'tests/test-tdb.sh %s' % Context.g_module.out
561 ret = samba_utils.RUN_COMMAND(cmd)
562 print("testsuite returned %d" % ret)
564 tmp_dir = os.path.join(test_prefix, 'tmp')
565 if not os.path.exists(tmp_dir):
567 pyret = samba_utils.RUN_PYTHON_TESTS(
568 ['tests/python/api.py', 'tests/python/index.py'],
569 extra_env={'SELFTEST_PREFIX': test_prefix})
570 print("Python testsuite returned %d" % pyret)
573 test_exes = ['test_ldb_qsort',
576 'ldb_tdb_mod_op_test',
577 'ldb_tdb_guid_mod_op_test',
579 'ldb_tdb_kv_ops_test',
581 'ldb_mdb_mod_op_test',
583 # we don't want to run ldb_lmdb_size_test (which proves we can
584 # fit > 4G of data into the DB), it would fill up the disk on
585 # many of our test instances
586 'ldb_mdb_kv_ops_test',
589 for test_exe in test_exes:
590 cmd = os.path.join(Context.g_module.out, test_exe)
591 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
593 sys.exit(ret or pyret or cmocka_ret)
596 '''makes a tarball for distribution'''
599 def reconfigure(ctx):
600 '''reconfigure if config scripts have changed'''
602 samba_utils.reconfigure(ctx)