11 # find the buildtools directory
13 while not os
.path
.exists(srcdir
+'/buildtools') and len(srcdir
.split('/')) < 5:
14 srcdir
= srcdir
+ '/..'
15 sys
.path
.insert(0, srcdir
+ '/buildtools/wafsamba')
17 import wafsamba
, samba_dist
, Utils
, Options
19 samba_dist
.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
20 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
21 third_party/popt:third_party/popt
22 third_party/cmocka:third_party/cmocka
23 buildtools:buildtools third_party/waf:third_party/waf''')
25 samba_dist
.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
28 opt
.BUILTIN_DEFAULT('replace')
29 opt
.PRIVATE_EXTENSION_DEFAULT('ldb', noextension
='ldb')
30 opt
.RECURSE('lib/tdb')
31 opt
.RECURSE('lib/tevent')
32 opt
.RECURSE('lib/replace')
33 opt
.tool_options('python') # options for disabling pyc or pyo compilation
35 opt
.add_option('--without-ldb-lmdb',
36 help='disable new LMDB backend for LDB',
37 action
='store_true', dest
='without_ldb_lmdb', default
=False)
41 conf
.RECURSE('lib/tdb')
42 conf
.RECURSE('lib/tevent')
44 if conf
.CHECK_FOR_THIRD_PARTY():
45 conf
.RECURSE('third_party/popt')
46 conf
.RECURSE('third_party/cmocka')
48 if not conf
.CHECK_POPT():
49 raise Utils
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
51 conf
.define('USING_SYSTEM_POPT', 1)
53 if not conf
.CHECK_CMOCKA():
54 raise Utils
.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
56 conf
.define('USING_SYSTEM_CMOCKA', 1)
58 conf
.RECURSE('lib/replace')
59 conf
.find_program('python', var
='PYTHON')
60 conf
.find_program('xsltproc', var
='XSLTPROC')
61 conf
.check_tool('python')
62 conf
.check_python_version((2,4,2))
63 conf
.SAMBA_CHECK_PYTHON_HEADERS(mandatory
=not conf
.env
.disable_python
)
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 if not conf
.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util',
87 maxversion
=max_ldb_version_dots
,
88 onlyif
='talloc tdb tevent',
89 implied_deps
='replace talloc tdb tevent ldb'):
90 using_system_pyldb_util
= False
92 # We need to get a pyldb-util for all the python versions
94 if conf
.env
['EXTRA_PYTHON']:
95 name
= 'pyldb-util' + conf
.all_envs
['extrapython']['PYTHON_SO_ABI_FLAG']
96 if not conf
.CHECK_BUNDLED_SYSTEM_PKG(name
,
98 maxversion
=max_ldb_version_dots
,
99 onlyif
='talloc tdb tevent',
100 implied_deps
='replace talloc tdb tevent ldb'):
101 using_system_pyldb_util
= False
103 if using_system_pyldb_util
:
104 conf
.define('USING_SYSTEM_PYLDB_UTIL', 1)
106 if conf
.CHECK_BUNDLED_SYSTEM_PKG('ldb',
108 maxversion
=max_ldb_version_dots
,
109 onlyif
='talloc tdb tevent pyldb-util',
110 implied_deps
='replace talloc tdb tevent'):
111 conf
.define('USING_SYSTEM_LDB', 1)
113 if not conf
.CHECK_CODE('return !(sizeof(size_t) >= 8)',
114 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
116 msg
='Checking for a 64-bit host to '
118 Logs
.warn("--without-ldb-lmdb implied as this "
119 "host is not 64-bit")
121 if not conf
.env
.standalone_ldb
and \
122 not Options
.options
.without_ad_dc
and \
123 conf
.CONFIG_GET('ENABLE_SELFTEST'):
124 Logs
.warn("NOTE: Some AD DC parts of selftest will fail")
126 conf
.env
.REQUIRE_LMDB
= False
128 if conf
.env
.standalone_ldb
:
129 if Options
.options
.without_ldb_lmdb
:
130 conf
.env
.REQUIRE_LMDB
= False
132 conf
.env
.REQUIRE_LMDB
= True
133 elif Options
.options
.without_ad_dc
:
134 conf
.env
.REQUIRE_LMDB
= False
136 if Options
.options
.without_ldb_lmdb
:
137 if not Options
.options
.without_ad_dc
and \
138 conf
.CONFIG_GET('ENABLE_SELFTEST'):
139 raise Utils
.WafError('--without-ldb-lmdb conflicts '
140 'with --enable-selftest while '
141 'building the AD DC')
143 conf
.env
.REQUIRE_LMDB
= False
145 conf
.env
.REQUIRE_LMDB
= True
148 if conf
.CONFIG_SET('USING_SYSTEM_LDB'):
149 v
= VERSION
.split('.')
150 conf
.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v
[0]))
151 conf
.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v
[1]))
152 conf
.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v
[2]))
154 if conf
.env
.standalone_ldb
:
155 conf
.CHECK_XSLTPROC_MANPAGES()
157 # we need this for the ldap backend
158 if conf
.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers
='lber.h ldap.h'):
159 conf
.env
.ENABLE_LDAP_BACKEND
= True
161 # we don't want any libraries or modules to rely on runtime
162 # resolution of symbols
163 if not sys
.platform
.startswith("openbsd"):
164 conf
.ADD_LDFLAGS('-Wl,-no-undefined', testflags
=True)
166 # if lmdb support is enabled then we require lmdb
167 # is present, build the mdb back end and enable lmdb support in
169 if conf
.env
.REQUIRE_LMDB
and \
170 not conf
.CONFIG_SET('USING_SYSTEM_LDB'):
171 if not conf
.CHECK_CFG(package
='lmdb',
172 args
='"lmdb >= 0.9.16" --cflags --libs',
173 msg
='Checking for lmdb >= 0.9.16',
175 if not conf
.CHECK_CODE('''
176 #if MDB_VERSION_MAJOR == 0 \
177 && MDB_VERSION_MINOR <= 9 \
178 && MDB_VERSION_PATCH < 16
182 'HAVE_GOOD_LMDB_VERSION',
184 msg
='Checking for lmdb >= 0.9.16 via header check'):
186 if conf
.env
.standalone_ldb
:
187 raise Utils
.WafError('ldb build (unless --without-ldb-lmdb) '
189 'lmdb 0.9.16 or later')
190 elif not Options
.options
.without_ad_dc
:
191 raise Utils
.WafError('Samba AD DC and --enable-selftest '
193 'lmdb 0.9.16 or later')
195 if conf
.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers
='lmdb.h'):
196 conf
.DEFINE('HAVE_LMDB', '1')
199 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
201 conf
.SAMBA_CONFIG_H()
203 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
206 bld
.RECURSE('lib/tevent')
208 if bld
.CHECK_FOR_THIRD_PARTY():
209 bld
.RECURSE('third_party/popt')
210 bld
.RECURSE('third_party/cmocka')
212 bld
.RECURSE('lib/replace')
213 bld
.RECURSE('lib/tdb')
215 if bld
.env
.standalone_ldb
:
216 if not 'PACKAGE_VERSION' in bld
.env
:
217 bld
.env
.PACKAGE_VERSION
= VERSION
218 bld
.env
.PKGCONFIGDIR
= '${LIBDIR}/pkgconfig'
219 private_library
= False
221 private_library
= True
222 # we're not currently linking against the ldap libs, but ldb.pc.in
224 bld
.env
.LDAP_LIBS
= ''
226 LDB_MAP_SRC
= bld
.SUBDIR('ldb_map',
227 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
229 COMMON_SRC
= bld
.SUBDIR('common',
230 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
231 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
232 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
234 bld
.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
235 init_function
='ldb_ldap_init',
236 module_init_name
='ldb_init_module',
237 deps
='talloc lber ldap ldb',
238 enabled
=bld
.env
.ENABLE_LDAP_BACKEND
,
239 internal_module
=False,
242 if bld
.PYTHON_BUILD_IS_ENABLED():
243 if not bld
.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
244 for env
in bld
.gen_python_environments(['PKGCONFIGDIR']):
246 name
= bld
.pyembed_libname('pyldb-util')
247 bld
.SAMBA_LIBRARY(name
,
249 source
='pyldb_util.c',
250 public_headers
=('' if private_library
else 'pyldb.h'),
251 public_headers_install
=not private_library
,
253 private_library
=private_library
,
254 pc_files
='pyldb-util.pc',
256 enabled
=bld
.PYTHON_BUILD_IS_ENABLED(),
260 if not bld
.CONFIG_SET('USING_SYSTEM_LDB'):
261 bld
.SAMBA_PYTHON('pyldb', 'pyldb.c',
264 cflags
='-DPACKAGE_VERSION=\"%s\"' % VERSION
)
266 # Do only install this file as part of the Samba build if we do not
267 # use the system libldb!
268 if not bld
.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
269 for env
in bld
.gen_python_environments(['PKGCONFIGDIR']):
270 bld
.SAMBA_SCRIPT('_ldb_text.py',
271 pattern
='_ldb_text.py',
274 bld
.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
276 if not bld
.CONFIG_SET('USING_SYSTEM_LDB'):
278 modules_dir
= bld
.EXPAND_VARIABLES('${LDB_MODULESDIR}')
280 # when we run from the source directory, we want to use
281 # the current modules, not the installed ones
282 modules_dir
= os
.path
.join(os
.getcwd(), 'bin/modules/ldb')
284 abi_match
= '!ldb_*module_ops !ldb_*backend_ops ldb_*'
286 ldb_headers
= ('include/ldb.h include/ldb_errors.h '
287 'include/ldb_module.h include/ldb_handlers.h')
289 bld
.SAMBA_LIBRARY('ldb',
290 COMMON_SRC
+ ' ' + LDB_MAP_SRC
,
291 deps
='tevent LIBLDB_MAIN replace',
293 public_headers
=('' if private_library
else ldb_headers
),
294 public_headers_install
=not private_library
,
297 private_library
=private_library
,
298 manpages
='man/ldb.3',
300 abi_match
= abi_match
)
302 # generate a include/ldb_version.h
303 def generate_ldb_version_h(t
):
304 '''generate a vscript file for our public libraries'''
306 tgt
= t
.outputs
[0].bldpath(t
.env
)
308 v
= t
.env
.LDB_VERSION
.split('.')
310 f
= open(tgt
, mode
='w')
312 f
.write('#define LDB_VERSION "%s"\n' % t
.env
.LDB_VERSION
)
313 f
.write('#define LDB_VERSION_MAJOR %d\n' % int(v
[0]))
314 f
.write('#define LDB_VERSION_MINOR %d\n' % int(v
[1]))
315 f
.write('#define LDB_VERSION_RELEASE %d\n' % int(v
[2]))
319 t
= bld
.SAMBA_GENERATOR('ldb_version.h',
320 rule
=generate_ldb_version_h
,
321 dep_vars
=['LDB_VERSION'],
322 target
='include/ldb_version.h',
323 public_headers
='include/ldb_version.h',
324 public_headers_install
=not private_library
)
325 t
.env
.LDB_VERSION
= VERSION
328 bld
.SAMBA_MODULE('ldb_paged_results',
329 'modules/paged_results.c',
330 init_function
='ldb_paged_results_init',
331 module_init_name
='ldb_init_module',
332 internal_module
=False,
336 bld
.SAMBA_MODULE('ldb_asq',
338 init_function
='ldb_asq_init',
339 module_init_name
='ldb_init_module',
340 internal_module
=False,
344 bld
.SAMBA_MODULE('ldb_server_sort',
346 init_function
='ldb_server_sort_init',
347 internal_module
=False,
348 module_init_name
='ldb_init_module',
352 bld
.SAMBA_MODULE('ldb_paged_searches',
353 'modules/paged_searches.c',
354 init_function
='ldb_paged_searches_init',
355 internal_module
=False,
356 module_init_name
='ldb_init_module',
360 bld
.SAMBA_MODULE('ldb_rdn_name',
361 'modules/rdn_name.c',
362 init_function
='ldb_rdn_name_init',
363 internal_module
=False,
364 module_init_name
='ldb_init_module',
368 bld
.SAMBA_MODULE('ldb_sample',
369 'tests/sample_module.c',
370 init_function
='ldb_sample_init',
371 internal_module
=False,
372 module_init_name
='ldb_init_module',
376 bld
.SAMBA_MODULE('ldb_skel',
378 init_function
='ldb_skel_init',
379 internal_module
=False,
380 module_init_name
='ldb_init_module',
384 bld
.SAMBA_MODULE('ldb_sqlite3',
385 'sqlite3/ldb_sqlite3.c',
386 init_function
='ldb_sqlite3_init',
387 internal_module
=False,
388 module_init_name
='ldb_init_module',
393 bld
.SAMBA_MODULE('ldb_tdb',
394 bld
.SUBDIR('ldb_tdb',
395 '''ldb_tdb_init.c'''),
396 init_function
='ldb_tdb_init',
397 module_init_name
='ldb_init_module',
398 internal_module
=False,
399 deps
='tdb ldb ldb_key_value',
402 bld
.SAMBA_LIBRARY('ldb_key_value',
403 bld
.SUBDIR('ldb_tdb',
404 '''ldb_tdb.c ldb_search.c ldb_index.c
405 ldb_cache.c ldb_tdb_wrap.c'''),
406 private_library
=True,
409 if bld
.CONFIG_SET('HAVE_LMDB'):
410 bld
.SAMBA_MODULE('ldb_mdb',
411 bld
.SUBDIR('ldb_mdb',
412 '''ldb_mdb_init.c'''),
413 init_function
='ldb_mdb_init',
414 module_init_name
='ldb_init_module',
415 internal_module
=False,
416 deps
='ldb ldb_key_value ldb_mdb_int',
419 bld
.SAMBA_LIBRARY('ldb_mdb_int',
420 bld
.SUBDIR('ldb_mdb',
422 private_library
=True,
423 deps
='ldb lmdb ldb_key_value')
424 lmdb_deps
= ' ldb_mdb_int'
429 bld
.SAMBA_MODULE('ldb_ldb',
430 bld
.SUBDIR('ldb_ldb',
432 init_function
='ldb_ldb_init',
433 module_init_name
='ldb_init_module',
434 internal_module
=False,
435 deps
='ldb ldb_key_value' + lmdb_deps
,
438 # have a separate subsystem for common/ldb.c, so it can rebuild
439 # for install with a different -DLDB_MODULESDIR=
440 bld
.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
444 cflags
=['-DLDB_MODULESDIR=\"%s\"' % modules_dir
])
446 LDB_TOOLS
='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
447 for t
in LDB_TOOLS
.split():
448 bld
.SAMBA_BINARY(t
, 'tools/%s.c' % t
, deps
='ldb-cmdline ldb',
449 manpages
='man/%s.1' % t
)
451 # ldbtest doesn't get installed
452 bld
.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps
='ldb-cmdline ldb',
455 if bld
.CONFIG_SET('HAVE_LMDB'):
459 # ldbdump doesn't get installed
460 bld
.SAMBA_BINARY('ldbdump',
462 deps
='ldb-cmdline ldb' + lmdb_deps
,
465 bld
.SAMBA_LIBRARY('ldb-cmdline',
466 source
='tools/ldbutil.c tools/cmdline.c',
468 private_library
=True)
470 bld
.SAMBA_BINARY('ldb_tdb_mod_op_test',
471 source
='tests/ldb_mod_op_test.c',
472 cflags
='-DTEST_BE=\"tdb\"',
476 bld
.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
477 source
='tests/ldb_mod_op_test.c',
478 cflags
='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
482 bld
.SAMBA_BINARY('ldb_tdb_kv_ops_test',
483 source
='tests/ldb_kv_ops_test.c',
484 cflags
='-DTEST_BE=\"tdb\"',
488 bld
.SAMBA_BINARY('ldb_tdb_test',
489 source
='tests/ldb_tdb_test.c',
493 bld
.SAMBA_BINARY('ldb_msg_test',
494 source
='tests/ldb_msg.c',
498 bld
.SAMBA_BINARY('test_ldb_qsort',
499 source
='tests/test_ldb_qsort.c',
503 if bld
.CONFIG_SET('HAVE_LMDB'):
504 bld
.SAMBA_BINARY('ldb_mdb_mod_op_test',
505 source
='tests/ldb_mod_op_test.c',
506 cflags
='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
508 deps
='cmocka ldb lmdb',
511 bld
.SAMBA_BINARY('ldb_lmdb_test',
512 source
='tests/ldb_lmdb_test.c',
516 bld
.SAMBA_BINARY('ldb_lmdb_size_test',
517 source
='tests/ldb_lmdb_size_test.c',
521 bld
.SAMBA_BINARY('ldb_mdb_kv_ops_test',
522 source
='tests/ldb_kv_ops_test.c',
523 cflags
='-DTEST_BE=\"mdb\"',
528 '''run ldb testsuite'''
529 import Utils
, samba_utils
, shutil
530 env
= samba_utils
.LOAD_ENVIRONMENT()
533 if not env
.HAVE_LMDB
:
534 raise Utils
.WafError('make test called, but ldb was built '
535 '--without-ldb-lmdb')
537 test_prefix
= "%s/st" % (Utils
.g_module
.blddir
)
538 shutil
.rmtree(test_prefix
, ignore_errors
=True)
539 os
.makedirs(test_prefix
)
540 os
.environ
['TEST_DATA_PREFIX'] = test_prefix
541 os
.environ
['LDB_MODULES_PATH'] = Utils
.g_module
.blddir
+ "/modules/ldb"
542 samba_utils
.ADD_LD_LIBRARY_PATH('bin/shared')
543 samba_utils
.ADD_LD_LIBRARY_PATH('bin/shared/private')
545 cmd
= 'tests/test-tdb.sh %s' % Utils
.g_module
.blddir
546 ret
= samba_utils
.RUN_COMMAND(cmd
)
547 print("testsuite returned %d" % ret
)
549 tmp_dir
= os
.path
.join(test_prefix
, 'tmp')
550 if not os
.path
.exists(tmp_dir
):
552 pyret
= samba_utils
.RUN_PYTHON_TESTS(
553 ['tests/python/api.py', 'tests/python/index.py'],
554 extra_env
={'SELFTEST_PREFIX': test_prefix
})
555 print("Python testsuite returned %d" % pyret
)
558 test_exes
= ['test_ldb_qsort',
560 'ldb_tdb_mod_op_test',
561 'ldb_tdb_guid_mod_op_test',
563 'ldb_tdb_kv_ops_test',
565 'ldb_mdb_mod_op_test',
567 # we don't want to run ldb_lmdb_size_test (which proves we can
568 # fit > 4G of data into the DB), it would fill up the disk on
569 # many of our test instances
570 'ldb_mdb_kv_ops_test']
572 for test_exe
in test_exes
:
573 cmd
= os
.path
.join(Utils
.g_module
.blddir
, test_exe
)
574 cmocka_ret
= cmocka_ret
or samba_utils
.RUN_COMMAND(cmd
)
576 sys
.exit(ret
or pyret
or cmocka_ret
)
579 '''makes a tarball for distribution'''
582 def reconfigure(ctx
):
583 '''reconfigure if config scripts have changed'''
585 samba_utils
.reconfigure(ctx
)