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 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util',
89 maxversion=max_ldb_version_dots,
90 onlyif='talloc tdb tevent',
91 implied_deps='replace talloc tdb tevent ldb'):
92 using_system_pyldb_util = False
94 # We need to get a pyldb-util for all the python versions
96 if conf.env['EXTRA_PYTHON']:
97 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
98 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name,
100 maxversion=max_ldb_version_dots,
101 onlyif='talloc tdb tevent',
102 implied_deps='replace talloc tdb tevent ldb'):
103 using_system_pyldb_util = False
105 if using_system_pyldb_util:
106 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
108 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
110 maxversion=max_ldb_version_dots,
111 onlyif='talloc tdb tevent pyldb-util',
112 implied_deps='replace talloc tdb tevent'):
113 conf.define('USING_SYSTEM_LDB', 1)
115 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
116 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
118 msg='Checking for a 64-bit host to '
120 Logs.warn("--without-ldb-lmdb implied as this "
121 "host is not 64-bit")
123 if not conf.env.standalone_ldb and \
124 not Options.options.without_ad_dc and \
125 conf.CONFIG_GET('ENABLE_SELFTEST'):
126 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
128 conf.env.REQUIRE_LMDB = False
130 if conf.env.standalone_ldb:
131 if Options.options.without_ldb_lmdb:
132 conf.env.REQUIRE_LMDB = False
134 conf.env.REQUIRE_LMDB = True
135 elif Options.options.without_ad_dc:
136 conf.env.REQUIRE_LMDB = False
138 if Options.options.without_ldb_lmdb:
139 if not Options.options.without_ad_dc and \
140 conf.CONFIG_GET('ENABLE_SELFTEST'):
141 raise Errors.WafError('--without-ldb-lmdb conflicts '
142 'with --enable-selftest while '
143 'building the AD DC')
145 conf.env.REQUIRE_LMDB = False
147 conf.env.REQUIRE_LMDB = True
150 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
151 v = VERSION.split('.')
152 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
153 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
154 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
156 if conf.env.standalone_ldb:
157 conf.CHECK_XSLTPROC_MANPAGES()
159 # we need this for the ldap backend
160 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
161 conf.env.ENABLE_LDAP_BACKEND = True
163 # we don't want any libraries or modules to rely on runtime
164 # resolution of symbols
165 if not sys.platform.startswith("openbsd"):
166 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
168 # if lmdb support is enabled then we require lmdb
169 # is present, build the mdb back end and enable lmdb support in
171 if conf.env.REQUIRE_LMDB and \
172 not conf.CONFIG_SET('USING_SYSTEM_LDB'):
173 if not conf.CHECK_CFG(package='lmdb',
174 args='"lmdb >= 0.9.16" --cflags --libs',
175 msg='Checking for lmdb >= 0.9.16',
177 if not conf.CHECK_CODE('''
178 #if MDB_VERSION_MAJOR == 0 \
179 && MDB_VERSION_MINOR <= 9 \
180 && MDB_VERSION_PATCH < 16
184 'HAVE_GOOD_LMDB_VERSION',
186 msg='Checking for lmdb >= 0.9.16 via header check'):
188 if conf.env.standalone_ldb:
189 raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
191 'lmdb 0.9.16 or later')
192 elif not Options.options.without_ad_dc:
193 raise Errors.WafError('Samba AD DC and --enable-selftest '
195 'lmdb 0.9.16 or later')
197 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
198 conf.DEFINE('HAVE_LMDB', '1')
201 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
203 conf.SAMBA_CONFIG_H()
205 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
208 bld.RECURSE('lib/tevent')
210 if bld.CHECK_FOR_THIRD_PARTY():
211 bld.RECURSE('third_party/popt')
212 bld.RECURSE('third_party/cmocka')
214 bld.RECURSE('lib/replace')
215 bld.RECURSE('lib/tdb')
217 if bld.env.standalone_ldb:
218 if not 'PACKAGE_VERSION' in bld.env:
219 bld.env.PACKAGE_VERSION = VERSION
220 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
221 private_library = False
223 private_library = True
224 # we're not currently linking against the ldap libs, but ldb.pc.in
226 bld.env.LDAP_LIBS = ''
228 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
229 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
231 COMMON_SRC = bld.SUBDIR('common',
232 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
233 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
234 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
236 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
237 init_function='ldb_ldap_init',
238 module_init_name='ldb_init_module',
239 deps='talloc lber ldap ldb',
240 enabled=bld.env.ENABLE_LDAP_BACKEND,
241 internal_module=False,
244 if bld.PYTHON_BUILD_IS_ENABLED():
245 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
246 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
248 name = bld.pyembed_libname('pyldb-util')
249 bld.SAMBA_LIBRARY(name,
251 source='pyldb_util.c',
252 public_headers=('' if private_library else 'pyldb.h'),
253 public_headers_install=not private_library,
255 private_library=private_library,
256 pc_files='pyldb-util.pc',
258 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
262 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
263 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
266 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
268 # Do only install this file as part of the Samba build if we do not
269 # use the system libldb!
270 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
271 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
272 bld.SAMBA_SCRIPT('_ldb_text.py',
273 pattern='_ldb_text.py',
276 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
278 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
280 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
282 # when we run from the source directory, we want to use
283 # the current modules, not the installed ones
284 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
286 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
288 ldb_headers = ('include/ldb.h include/ldb_errors.h '
289 'include/ldb_module.h include/ldb_handlers.h')
291 bld.SAMBA_LIBRARY('ldb',
292 COMMON_SRC + ' ' + LDB_MAP_SRC,
293 deps='tevent LIBLDB_MAIN replace',
295 public_headers=('' if private_library else ldb_headers),
296 public_headers_install=not private_library,
299 private_library=private_library,
300 manpages='man/ldb.3',
302 abi_match = abi_match)
304 # generate a include/ldb_version.h
305 def generate_ldb_version_h(t):
306 '''generate a vscript file for our public libraries'''
308 tgt = t.outputs[0].bldpath(t.env)
310 v = t.env.LDB_VERSION.split('.')
312 f = open(tgt, mode='w')
314 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
315 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
316 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
317 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
321 t = bld.SAMBA_GENERATOR('ldb_version.h',
322 rule=generate_ldb_version_h,
323 dep_vars=['LDB_VERSION'],
324 target='include/ldb_version.h',
325 public_headers='include/ldb_version.h',
326 public_headers_install=not private_library)
327 t.env.LDB_VERSION = VERSION
330 bld.SAMBA_MODULE('ldb_paged_results',
331 'modules/paged_results.c',
332 init_function='ldb_paged_results_init',
333 module_init_name='ldb_init_module',
334 internal_module=False,
338 bld.SAMBA_MODULE('ldb_asq',
340 init_function='ldb_asq_init',
341 module_init_name='ldb_init_module',
342 internal_module=False,
346 bld.SAMBA_MODULE('ldb_server_sort',
348 init_function='ldb_server_sort_init',
349 internal_module=False,
350 module_init_name='ldb_init_module',
354 bld.SAMBA_MODULE('ldb_paged_searches',
355 'modules/paged_searches.c',
356 init_function='ldb_paged_searches_init',
357 internal_module=False,
358 module_init_name='ldb_init_module',
362 bld.SAMBA_MODULE('ldb_rdn_name',
363 'modules/rdn_name.c',
364 init_function='ldb_rdn_name_init',
365 internal_module=False,
366 module_init_name='ldb_init_module',
370 bld.SAMBA_MODULE('ldb_sample',
371 'tests/sample_module.c',
372 init_function='ldb_sample_init',
373 internal_module=False,
374 module_init_name='ldb_init_module',
378 bld.SAMBA_MODULE('ldb_skel',
380 init_function='ldb_skel_init',
381 internal_module=False,
382 module_init_name='ldb_init_module',
386 bld.SAMBA_MODULE('ldb_sqlite3',
387 'sqlite3/ldb_sqlite3.c',
388 init_function='ldb_sqlite3_init',
389 internal_module=False,
390 module_init_name='ldb_init_module',
395 bld.SAMBA_MODULE('ldb_tdb',
396 bld.SUBDIR('ldb_tdb',
397 '''ldb_tdb_init.c'''),
398 init_function='ldb_tdb_init',
399 module_init_name='ldb_init_module',
400 internal_module=False,
401 deps='ldb ldb_tdb_int ldb_key_value',
404 bld.SAMBA_LIBRARY('ldb_tdb_int',
405 bld.SUBDIR('ldb_tdb',
406 '''ldb_tdb_wrap.c ldb_tdb.c'''),
407 private_library=True,
408 deps='ldb tdb ldb_key_value ldb_tdb_err_map')
410 bld.SAMBA_LIBRARY('ldb_tdb_err_map',
411 bld.SUBDIR('ldb_tdb',
412 '''ldb_tdb_err_map.c '''),
413 private_library=True,
416 bld.SAMBA_LIBRARY('ldb_key_value',
417 bld.SUBDIR('ldb_key_value',
418 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
420 private_library=True,
421 deps='tdb ldb ldb_tdb_err_map')
423 if bld.CONFIG_SET('HAVE_LMDB'):
424 bld.SAMBA_MODULE('ldb_mdb',
425 bld.SUBDIR('ldb_mdb',
426 '''ldb_mdb_init.c'''),
427 init_function='ldb_mdb_init',
428 module_init_name='ldb_init_module',
429 internal_module=False,
430 deps='ldb ldb_key_value ldb_mdb_int',
433 bld.SAMBA_LIBRARY('ldb_mdb_int',
434 bld.SUBDIR('ldb_mdb',
436 private_library=True,
437 deps='ldb lmdb ldb_key_value')
438 lmdb_deps = ' ldb_mdb_int'
443 bld.SAMBA_MODULE('ldb_ldb',
444 bld.SUBDIR('ldb_ldb',
446 init_function='ldb_ldb_init',
447 module_init_name='ldb_init_module',
448 internal_module=False,
449 deps='ldb ldb_tdb ldb_key_value' + lmdb_deps,
452 # have a separate subsystem for common/ldb.c, so it can rebuild
453 # for install with a different -DLDB_MODULESDIR=
454 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
458 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
460 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
461 for t in LDB_TOOLS.split():
462 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
463 manpages='man/%s.1' % t)
465 # ldbtest doesn't get installed
466 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
469 if bld.CONFIG_SET('HAVE_LMDB'):
473 # ldbdump doesn't get installed
474 bld.SAMBA_BINARY('ldbdump',
476 deps='ldb-cmdline ldb' + lmdb_deps,
479 bld.SAMBA_LIBRARY('ldb-cmdline',
480 source='tools/ldbutil.c tools/cmdline.c',
482 private_library=True)
484 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
485 source='tests/ldb_mod_op_test.c',
486 cflags='-DTEST_BE=\"tdb\"',
490 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
491 source='tests/ldb_mod_op_test.c',
492 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
496 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
497 source='tests/ldb_kv_ops_test.c',
498 cflags='-DTEST_BE=\"tdb\"',
502 bld.SAMBA_BINARY('ldb_tdb_test',
503 source='tests/ldb_tdb_test.c',
507 bld.SAMBA_BINARY('ldb_msg_test',
508 source='tests/ldb_msg.c',
512 bld.SAMBA_BINARY('test_ldb_qsort',
513 source='tests/test_ldb_qsort.c',
517 bld.SAMBA_BINARY('test_ldb_dn',
518 source='tests/test_ldb_dn.c',
522 if bld.CONFIG_SET('HAVE_LMDB'):
523 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
524 source='tests/ldb_mod_op_test.c',
525 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
527 deps='cmocka ldb lmdb',
530 bld.SAMBA_BINARY('ldb_lmdb_test',
531 source='tests/ldb_lmdb_test.c',
535 bld.SAMBA_BINARY('ldb_lmdb_size_test',
536 source='tests/ldb_lmdb_size_test.c',
540 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
541 source='tests/ldb_kv_ops_test.c',
542 cflags='-DTEST_BE=\"mdb\"',
547 '''run ldb testsuite'''
548 env = samba_utils.LOAD_ENVIRONMENT()
551 if not env.HAVE_LMDB:
552 raise Errors.WafError('make test called, but ldb was built '
553 '--without-ldb-lmdb')
555 test_prefix = "%s/st" % (Context.g_module.out)
556 shutil.rmtree(test_prefix, ignore_errors=True)
557 os.makedirs(test_prefix)
558 os.environ['TEST_DATA_PREFIX'] = test_prefix
559 os.environ['LDB_MODULES_PATH'] = Context.g_module.out + "/modules/ldb"
560 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
561 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
563 cmd = 'tests/test-tdb.sh %s' % Context.g_module.out
564 ret = samba_utils.RUN_COMMAND(cmd)
565 print("testsuite returned %d" % ret)
567 tmp_dir = os.path.join(test_prefix, 'tmp')
568 if not os.path.exists(tmp_dir):
570 pyret = samba_utils.RUN_PYTHON_TESTS(
571 ['tests/python/api.py', 'tests/python/index.py'],
572 extra_env={'SELFTEST_PREFIX': test_prefix})
573 print("Python testsuite returned %d" % pyret)
576 test_exes = ['test_ldb_qsort',
579 'ldb_tdb_mod_op_test',
580 'ldb_tdb_guid_mod_op_test',
582 'ldb_tdb_kv_ops_test',
584 'ldb_mdb_mod_op_test',
586 # we don't want to run ldb_lmdb_size_test (which proves we can
587 # fit > 4G of data into the DB), it would fill up the disk on
588 # many of our test instances
589 'ldb_mdb_kv_ops_test']
591 for test_exe in test_exes:
592 cmd = os.path.join(Context.g_module.out, test_exe)
593 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
595 sys.exit(ret or pyret or cmocka_ret)
598 '''makes a tarball for distribution'''
601 def reconfigure(ctx):
602 '''reconfigure if config scripts have changed'''
604 samba_utils.reconfigure(ctx)