10 # find the buildtools directory
12 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
13 srcdir = srcdir + '/..'
14 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
16 import wafsamba, samba_dist, Utils
18 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
19 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
20 third_party/popt:third_party/popt
21 third_party/cmocka:third_party/cmocka
22 buildtools:buildtools third_party/waf:third_party/waf''')
26 opt.BUILTIN_DEFAULT('replace')
27 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
28 opt.RECURSE('lib/tdb')
29 opt.RECURSE('lib/tevent')
30 opt.RECURSE('lib/replace')
31 opt.tool_options('python') # options for disabling pyc or pyo compilation
34 conf.RECURSE('lib/tdb')
35 conf.RECURSE('lib/tevent')
37 if conf.CHECK_FOR_THIRD_PARTY():
38 conf.RECURSE('third_party/popt')
39 conf.RECURSE('third_party/cmocka')
41 if not conf.CHECK_POPT():
42 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
44 conf.define('USING_SYSTEM_POPT', 1)
46 if not conf.CHECK_CMOCKA():
47 raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
49 conf.define('USING_SYSTEM_CMOCKA', 1)
51 conf.RECURSE('lib/replace')
52 conf.find_program('python', var='PYTHON')
53 conf.find_program('xsltproc', var='XSLTPROC')
54 conf.check_tool('python')
55 conf.check_python_version((2,4,2))
56 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
58 # where does the default LIBDIR end up? in conf.env somewhere?
60 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
62 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
64 if not conf.env.standalone_ldb:
65 if conf.env.disable_python:
66 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
67 onlyif='talloc tdb tevent',
68 implied_deps='replace talloc tdb tevent'):
69 conf.define('USING_SYSTEM_LDB', 1)
71 using_system_pyldb_util = True
72 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
73 onlyif='talloc tdb tevent',
74 implied_deps='replace talloc tdb tevent ldb'):
75 using_system_pyldb_util = False
77 # We need to get a pyldb-util for all the python versions
79 if conf.env['EXTRA_PYTHON']:
80 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
81 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
82 onlyif='talloc tdb tevent',
83 implied_deps='replace talloc tdb tevent ldb'):
84 using_system_pyldb_util = False
86 if using_system_pyldb_util:
87 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
89 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
90 onlyif='talloc tdb tevent pyldb-util',
91 implied_deps='replace talloc tdb tevent'):
92 conf.define('USING_SYSTEM_LDB', 1)
94 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
95 v = VERSION.split('.')
96 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
97 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
98 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
100 if conf.env.standalone_ldb:
101 conf.CHECK_XSLTPROC_MANPAGES()
103 # we need this for the ldap backend
104 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
105 conf.env.ENABLE_LDAP_BACKEND = True
107 # we don't want any libraries or modules to rely on runtime
108 # resolution of symbols
109 if not sys.platform.startswith("openbsd"):
110 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
112 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
114 conf.SAMBA_CONFIG_H()
116 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
119 bld.RECURSE('lib/tevent')
121 if bld.CHECK_FOR_THIRD_PARTY():
122 bld.RECURSE('third_party/popt')
123 bld.RECURSE('third_party/cmocka')
125 bld.RECURSE('lib/replace')
126 bld.RECURSE('lib/tdb')
128 if bld.env.standalone_ldb:
129 private_library = False
131 private_library = True
133 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
134 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
136 COMMON_SRC = bld.SUBDIR('common',
137 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
138 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
139 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
141 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
142 init_function='ldb_ldap_init',
143 module_init_name='ldb_init_module',
144 deps='talloc lber ldap ldb',
145 enabled=bld.env.ENABLE_LDAP_BACKEND,
146 internal_module=False,
149 if bld.PYTHON_BUILD_IS_ENABLED():
150 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
151 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
152 # we're not currently linking against the ldap libs, but ldb.pc.in
154 bld.env.LDAP_LIBS = ''
156 if not 'PACKAGE_VERSION' in bld.env:
157 bld.env.PACKAGE_VERSION = VERSION
158 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
160 name = bld.pyembed_libname('pyldb-util')
161 bld.SAMBA_LIBRARY(name,
163 source='pyldb_util.c',
164 public_headers=('' if private_library else 'pyldb.h'),
165 public_headers_install=not private_library,
167 private_library=private_library,
168 pc_files='pyldb-util.pc',
170 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
174 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
175 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
178 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
180 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
181 bld.SAMBA_SCRIPT('_ldb_text.py',
182 pattern='_ldb_text.py',
185 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
187 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
189 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
191 # when we run from the source directory, we want to use
192 # the current modules, not the installed ones
193 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
195 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
197 ldb_headers = ('include/ldb.h include/ldb_errors.h '
198 'include/ldb_module.h include/ldb_handlers.h')
200 bld.SAMBA_LIBRARY('ldb',
201 COMMON_SRC + ' ' + LDB_MAP_SRC,
202 deps='tevent LIBLDB_MAIN replace',
204 public_headers=('' if private_library else ldb_headers),
205 public_headers_install=not private_library,
208 private_library=private_library,
209 manpages='man/ldb.3',
211 abi_match = abi_match)
213 # generate a include/ldb_version.h
214 def generate_ldb_version_h(t):
215 '''generate a vscript file for our public libraries'''
217 tgt = t.outputs[0].bldpath(t.env)
219 v = t.env.LDB_VERSION.split('.')
221 f = open(tgt, mode='w')
223 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
224 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
225 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
226 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
230 t = bld.SAMBA_GENERATOR('ldb_version.h',
231 rule=generate_ldb_version_h,
232 dep_vars=['LDB_VERSION'],
233 target='include/ldb_version.h',
234 public_headers='include/ldb_version.h',
235 public_headers_install=not private_library)
236 t.env.LDB_VERSION = VERSION
239 bld.SAMBA_MODULE('ldb_paged_results',
240 'modules/paged_results.c',
241 init_function='ldb_paged_results_init',
242 module_init_name='ldb_init_module',
243 internal_module=False,
247 bld.SAMBA_MODULE('ldb_asq',
249 init_function='ldb_asq_init',
250 module_init_name='ldb_init_module',
251 internal_module=False,
255 bld.SAMBA_MODULE('ldb_server_sort',
257 init_function='ldb_server_sort_init',
258 internal_module=False,
259 module_init_name='ldb_init_module',
263 bld.SAMBA_MODULE('ldb_paged_searches',
264 'modules/paged_searches.c',
265 init_function='ldb_paged_searches_init',
266 internal_module=False,
267 module_init_name='ldb_init_module',
271 bld.SAMBA_MODULE('ldb_rdn_name',
272 'modules/rdn_name.c',
273 init_function='ldb_rdn_name_init',
274 internal_module=False,
275 module_init_name='ldb_init_module',
279 bld.SAMBA_MODULE('ldb_sample',
280 'tests/sample_module.c',
281 init_function='ldb_sample_init',
282 internal_module=False,
283 module_init_name='ldb_init_module',
287 bld.SAMBA_MODULE('ldb_skel',
289 init_function='ldb_skel_init',
290 internal_module=False,
291 module_init_name='ldb_init_module',
295 bld.SAMBA_MODULE('ldb_sqlite3',
296 'sqlite3/ldb_sqlite3.c',
297 init_function='ldb_sqlite3_init',
298 internal_module=False,
299 module_init_name='ldb_init_module',
304 bld.SAMBA_MODULE('ldb_tdb',
305 bld.SUBDIR('ldb_tdb',
306 '''ldb_tdb.c ldb_search.c ldb_index.c
307 ldb_cache.c ldb_tdb_wrap.c'''),
308 init_function='ldb_tdb_init',
309 module_init_name='ldb_init_module',
310 internal_module=False,
314 # have a separate subsystem for common/ldb.c, so it can rebuild
315 # for install with a different -DLDB_MODULESDIR=
316 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
320 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
322 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
323 for t in LDB_TOOLS.split():
324 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
325 manpages='man/%s.1' % t)
327 # ldbtest doesn't get installed
328 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
331 # ldbdump doesn't get installed
332 bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
335 bld.SAMBA_LIBRARY('ldb-cmdline',
336 source='tools/ldbutil.c tools/cmdline.c',
338 private_library=True)
340 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
341 source='tests/ldb_mod_op_test.c',
342 cflags='-DTEST_BE=\"tdb\"',
346 bld.SAMBA_BINARY('ldb_msg_test',
347 source='tests/ldb_msg.c',
352 '''run ldb testsuite'''
353 import Utils, samba_utils, shutil
354 env = samba_utils.LOAD_ENVIRONMENT()
357 test_prefix = "%s/st" % (Utils.g_module.blddir)
358 shutil.rmtree(test_prefix, ignore_errors=True)
359 os.makedirs(test_prefix)
360 os.environ['TEST_DATA_PREFIX'] = test_prefix
361 os.environ['LD_LIBRARY_PATH'] = Utils.g_module.blddir + '/bin/default/lib/ldb'
362 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
363 ret = samba_utils.RUN_COMMAND(cmd)
364 print("testsuite returned %d" % ret)
366 tmp_dir = os.path.join(test_prefix, 'tmp')
367 if not os.path.exists(tmp_dir):
369 pyret = samba_utils.RUN_PYTHON_TESTS(
370 ['tests/python/api.py'],
371 extra_env={'SELFTEST_PREFIX': test_prefix})
372 print("Python testsuite returned %d" % pyret)
374 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + '/modules/ldb'
375 os.environ['LD_LIBRARY_PATH'] = Utils.g_module.blddir + '/bin/default/lib/ldb'
377 for test_exe in ['ldb_tdb_mod_op_test',
379 cmd = os.path.join(Utils.g_module.blddir, test_exe)
380 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
382 sys.exit(ret or pyret or cmocka_ret)
385 '''makes a tarball for distribution'''
388 def reconfigure(ctx):
389 '''reconfigure if config scripts have changed'''
391 samba_utils.reconfigure(ctx)