ldb: Bump ldb version to 1.3.7
[Samba.git] / lib / ldb / wscript
blobe6b3d4f2ced3ea84932d51e02de24373471e5e5a
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.3.7'
6 blddir = 'bin'
8 import sys, os
10 # find the buildtools directory
11 srcdir = '.'
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''')
24 samba_dist.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
26 def set_options(opt):
27 opt.BUILTIN_DEFAULT('replace')
28 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
29 opt.RECURSE('lib/tdb')
30 opt.RECURSE('lib/tevent')
31 opt.RECURSE('lib/replace')
32 opt.tool_options('python') # options for disabling pyc or pyo compilation
34 def configure(conf):
35 conf.RECURSE('lib/tdb')
36 conf.RECURSE('lib/tevent')
38 if conf.CHECK_FOR_THIRD_PARTY():
39 conf.RECURSE('third_party/popt')
40 conf.RECURSE('third_party/cmocka')
41 else:
42 if not conf.CHECK_POPT():
43 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
44 else:
45 conf.define('USING_SYSTEM_POPT', 1)
47 if not conf.CHECK_CMOCKA():
48 raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
49 else:
50 conf.define('USING_SYSTEM_CMOCKA', 1)
52 conf.RECURSE('lib/replace')
53 conf.find_program('python', var='PYTHON')
54 conf.find_program('xsltproc', var='XSLTPROC')
55 conf.check_tool('python')
56 conf.check_python_version((2,4,2))
57 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
59 # where does the default LIBDIR end up? in conf.env somewhere?
61 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
63 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
65 if not conf.env.standalone_ldb:
66 max_ldb_version = [int(x) for x in VERSION.split(".")]
67 max_ldb_version[2] = 999
68 max_ldb_version_dots = "%d.%d.%d" % tuple(max_ldb_version)
70 if conf.env.disable_python:
71 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
72 minversion=VERSION,
73 maxversion=max_ldb_version_dots,
74 onlyif='talloc tdb tevent',
75 implied_deps='replace talloc tdb tevent'):
76 conf.define('USING_SYSTEM_LDB', 1)
77 else:
78 using_system_pyldb_util = True
79 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util',
80 minversion=VERSION,
81 maxversion=max_ldb_version_dots,
82 onlyif='talloc tdb tevent',
83 implied_deps='replace talloc tdb tevent ldb'):
84 using_system_pyldb_util = False
86 # We need to get a pyldb-util for all the python versions
87 # we are building for
88 if conf.env['EXTRA_PYTHON']:
89 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
90 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name,
91 minversion=VERSION,
92 maxversion=max_ldb_version_dots,
93 onlyif='talloc tdb tevent',
94 implied_deps='replace talloc tdb tevent ldb'):
95 using_system_pyldb_util = False
97 if using_system_pyldb_util:
98 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
100 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
101 minversion=VERSION,
102 maxversion=max_ldb_version_dots,
103 onlyif='talloc tdb tevent pyldb-util',
104 implied_deps='replace talloc tdb tevent'):
105 conf.define('USING_SYSTEM_LDB', 1)
107 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
108 v = VERSION.split('.')
109 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
110 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
111 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
113 if conf.env.standalone_ldb:
114 conf.CHECK_XSLTPROC_MANPAGES()
116 # we need this for the ldap backend
117 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
118 conf.env.ENABLE_LDAP_BACKEND = True
120 # we don't want any libraries or modules to rely on runtime
121 # resolution of symbols
122 if not sys.platform.startswith("openbsd"):
123 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
125 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
127 conf.SAMBA_CONFIG_H()
129 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
131 def build(bld):
132 bld.RECURSE('lib/tevent')
134 if bld.CHECK_FOR_THIRD_PARTY():
135 bld.RECURSE('third_party/popt')
136 bld.RECURSE('third_party/cmocka')
138 bld.RECURSE('lib/replace')
139 bld.RECURSE('lib/tdb')
141 if bld.env.standalone_ldb:
142 private_library = False
143 else:
144 private_library = True
146 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
147 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
149 COMMON_SRC = bld.SUBDIR('common',
150 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
151 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
152 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
154 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
155 init_function='ldb_ldap_init',
156 module_init_name='ldb_init_module',
157 deps='talloc lber ldap ldb',
158 enabled=bld.env.ENABLE_LDAP_BACKEND,
159 internal_module=False,
160 subsystem='ldb')
162 if bld.PYTHON_BUILD_IS_ENABLED():
163 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
164 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
165 # we're not currently linking against the ldap libs, but ldb.pc.in
166 # has @LDAP_LIBS@
167 bld.env.LDAP_LIBS = ''
169 if not 'PACKAGE_VERSION' in bld.env:
170 bld.env.PACKAGE_VERSION = VERSION
171 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
173 name = bld.pyembed_libname('pyldb-util')
174 bld.SAMBA_LIBRARY(name,
175 deps='ldb',
176 source='pyldb_util.c',
177 public_headers=('' if private_library else 'pyldb.h'),
178 public_headers_install=not private_library,
179 vnum=VERSION,
180 private_library=private_library,
181 pc_files='pyldb-util.pc',
182 pyembed=True,
183 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
184 abi_directory='ABI',
185 abi_match='pyldb_*')
187 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
188 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
189 deps='ldb ' + name,
190 realname='ldb.so',
191 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
193 # Do only install this file as part of the Samba build if we do not
194 # use the system libldb!
195 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
196 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
197 bld.SAMBA_SCRIPT('_ldb_text.py',
198 pattern='_ldb_text.py',
199 installdir='python')
201 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
203 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
204 if bld.is_install:
205 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
206 else:
207 # when we run from the source directory, we want to use
208 # the current modules, not the installed ones
209 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
211 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
213 ldb_headers = ('include/ldb.h include/ldb_errors.h '
214 'include/ldb_module.h include/ldb_handlers.h')
216 bld.SAMBA_LIBRARY('ldb',
217 COMMON_SRC + ' ' + LDB_MAP_SRC,
218 deps='tevent LIBLDB_MAIN replace',
219 includes='include',
220 public_headers=('' if private_library else ldb_headers),
221 public_headers_install=not private_library,
222 pc_files='ldb.pc',
223 vnum=VERSION,
224 private_library=private_library,
225 manpages='man/ldb.3',
226 abi_directory='ABI',
227 abi_match = abi_match)
229 # generate a include/ldb_version.h
230 def generate_ldb_version_h(t):
231 '''generate a vscript file for our public libraries'''
233 tgt = t.outputs[0].bldpath(t.env)
235 v = t.env.LDB_VERSION.split('.')
237 f = open(tgt, mode='w')
238 try:
239 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
240 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
241 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
242 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
243 finally:
244 f.close()
245 return
246 t = bld.SAMBA_GENERATOR('ldb_version.h',
247 rule=generate_ldb_version_h,
248 dep_vars=['LDB_VERSION'],
249 target='include/ldb_version.h',
250 public_headers='include/ldb_version.h',
251 public_headers_install=not private_library)
252 t.env.LDB_VERSION = VERSION
255 bld.SAMBA_MODULE('ldb_paged_results',
256 'modules/paged_results.c',
257 init_function='ldb_paged_results_init',
258 module_init_name='ldb_init_module',
259 internal_module=False,
260 deps='ldb',
261 subsystem='ldb')
263 bld.SAMBA_MODULE('ldb_asq',
264 'modules/asq.c',
265 init_function='ldb_asq_init',
266 module_init_name='ldb_init_module',
267 internal_module=False,
268 deps='ldb',
269 subsystem='ldb')
271 bld.SAMBA_MODULE('ldb_server_sort',
272 'modules/sort.c',
273 init_function='ldb_server_sort_init',
274 internal_module=False,
275 module_init_name='ldb_init_module',
276 deps='ldb',
277 subsystem='ldb')
279 bld.SAMBA_MODULE('ldb_paged_searches',
280 'modules/paged_searches.c',
281 init_function='ldb_paged_searches_init',
282 internal_module=False,
283 module_init_name='ldb_init_module',
284 deps='ldb',
285 subsystem='ldb')
287 bld.SAMBA_MODULE('ldb_rdn_name',
288 'modules/rdn_name.c',
289 init_function='ldb_rdn_name_init',
290 internal_module=False,
291 module_init_name='ldb_init_module',
292 deps='ldb',
293 subsystem='ldb')
295 bld.SAMBA_MODULE('ldb_sample',
296 'tests/sample_module.c',
297 init_function='ldb_sample_init',
298 internal_module=False,
299 module_init_name='ldb_init_module',
300 deps='ldb',
301 subsystem='ldb')
303 bld.SAMBA_MODULE('ldb_skel',
304 'modules/skel.c',
305 init_function='ldb_skel_init',
306 internal_module=False,
307 module_init_name='ldb_init_module',
308 deps='ldb',
309 subsystem='ldb')
311 bld.SAMBA_MODULE('ldb_sqlite3',
312 'sqlite3/ldb_sqlite3.c',
313 init_function='ldb_sqlite3_init',
314 internal_module=False,
315 module_init_name='ldb_init_module',
316 enabled=False,
317 deps='ldb',
318 subsystem='ldb')
320 bld.SAMBA_MODULE('ldb_tdb',
321 bld.SUBDIR('ldb_tdb',
322 '''ldb_tdb.c ldb_search.c ldb_index.c
323 ldb_cache.c ldb_tdb_wrap.c'''),
324 init_function='ldb_tdb_init',
325 module_init_name='ldb_init_module',
326 internal_module=False,
327 deps='tdb ldb',
328 subsystem='ldb')
330 # have a separate subsystem for common/ldb.c, so it can rebuild
331 # for install with a different -DLDB_MODULESDIR=
332 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
333 'common/ldb.c',
334 deps='tevent tdb',
335 includes='include',
336 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
338 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
339 for t in LDB_TOOLS.split():
340 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
341 manpages='man/%s.1' % t)
343 # ldbtest doesn't get installed
344 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
345 install=False)
347 # ldbdump doesn't get installed
348 bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
349 install=False)
351 bld.SAMBA_LIBRARY('ldb-cmdline',
352 source='tools/ldbutil.c tools/cmdline.c',
353 deps='ldb dl popt',
354 private_library=True)
356 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
357 source='tests/ldb_mod_op_test.c',
358 cflags='-DTEST_BE=\"tdb\"',
359 deps='cmocka ldb',
360 install=False)
362 bld.SAMBA_BINARY('ldb_msg_test',
363 source='tests/ldb_msg.c',
364 deps='cmocka ldb',
365 install=False)
367 def test(ctx):
368 '''run ldb testsuite'''
369 import Utils, samba_utils, shutil
370 env = samba_utils.LOAD_ENVIRONMENT()
371 ctx.env = env
373 test_prefix = "%s/st" % (Utils.g_module.blddir)
374 shutil.rmtree(test_prefix, ignore_errors=True)
375 os.makedirs(test_prefix)
376 os.environ['TEST_DATA_PREFIX'] = test_prefix
377 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
378 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
379 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
381 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
382 ret = samba_utils.RUN_COMMAND(cmd)
383 print("testsuite returned %d" % ret)
385 tmp_dir = os.path.join(test_prefix, 'tmp')
386 if not os.path.exists(tmp_dir):
387 os.mkdir(tmp_dir)
388 pyret = samba_utils.RUN_PYTHON_TESTS(
389 ['tests/python/api.py', 'tests/python/index.py'],
390 extra_env={'SELFTEST_PREFIX': test_prefix})
391 print("Python testsuite returned %d" % pyret)
393 cmocka_ret = 0
394 for test_exe in ['ldb_tdb_mod_op_test',
395 'ldb_msg_test']:
396 cmd = os.path.join(Utils.g_module.blddir, test_exe)
397 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
399 sys.exit(ret or pyret or cmocka_ret)
401 def dist():
402 '''makes a tarball for distribution'''
403 samba_dist.dist()
405 def reconfigure(ctx):
406 '''reconfigure if config scripts have changed'''
407 import samba_utils
408 samba_utils.reconfigure(ctx)