ldb: Release ldb 1.3.0
[Samba.git] / lib / ldb / wscript
blob0b8ba26850ea32790aac1b7a836191378b495055
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.3.0'
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 if conf.env.disable_python:
67 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
68 onlyif='talloc tdb tevent',
69 implied_deps='replace talloc tdb tevent'):
70 conf.define('USING_SYSTEM_LDB', 1)
71 else:
72 using_system_pyldb_util = True
73 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
74 onlyif='talloc tdb tevent',
75 implied_deps='replace talloc tdb tevent ldb'):
76 using_system_pyldb_util = False
78 # We need to get a pyldb-util for all the python versions
79 # we are building for
80 if conf.env['EXTRA_PYTHON']:
81 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
82 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
83 onlyif='talloc tdb tevent',
84 implied_deps='replace talloc tdb tevent ldb'):
85 using_system_pyldb_util = False
87 if using_system_pyldb_util:
88 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
90 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
91 onlyif='talloc tdb tevent pyldb-util',
92 implied_deps='replace talloc tdb tevent'):
93 conf.define('USING_SYSTEM_LDB', 1)
95 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
96 v = VERSION.split('.')
97 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
98 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
99 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
101 if conf.env.standalone_ldb:
102 conf.CHECK_XSLTPROC_MANPAGES()
104 # we need this for the ldap backend
105 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
106 conf.env.ENABLE_LDAP_BACKEND = True
108 # we don't want any libraries or modules to rely on runtime
109 # resolution of symbols
110 if not sys.platform.startswith("openbsd"):
111 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
113 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
115 conf.SAMBA_CONFIG_H()
117 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
119 def build(bld):
120 bld.RECURSE('lib/tevent')
122 if bld.CHECK_FOR_THIRD_PARTY():
123 bld.RECURSE('third_party/popt')
124 bld.RECURSE('third_party/cmocka')
126 bld.RECURSE('lib/replace')
127 bld.RECURSE('lib/tdb')
129 if bld.env.standalone_ldb:
130 private_library = False
131 else:
132 private_library = True
134 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
135 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
137 COMMON_SRC = bld.SUBDIR('common',
138 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
139 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
140 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
142 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
143 init_function='ldb_ldap_init',
144 module_init_name='ldb_init_module',
145 deps='talloc lber ldap ldb',
146 enabled=bld.env.ENABLE_LDAP_BACKEND,
147 internal_module=False,
148 subsystem='ldb')
150 if bld.PYTHON_BUILD_IS_ENABLED():
151 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
152 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
153 # we're not currently linking against the ldap libs, but ldb.pc.in
154 # has @LDAP_LIBS@
155 bld.env.LDAP_LIBS = ''
157 if not 'PACKAGE_VERSION' in bld.env:
158 bld.env.PACKAGE_VERSION = VERSION
159 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
161 name = bld.pyembed_libname('pyldb-util')
162 bld.SAMBA_LIBRARY(name,
163 deps='ldb',
164 source='pyldb_util.c',
165 public_headers=('' if private_library else 'pyldb.h'),
166 public_headers_install=not private_library,
167 vnum=VERSION,
168 private_library=private_library,
169 pc_files='pyldb-util.pc',
170 pyembed=True,
171 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
172 abi_directory='ABI',
173 abi_match='pyldb_*')
175 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
176 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
177 deps='ldb ' + name,
178 realname='ldb.so',
179 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
181 # Do only install this file as part of the Samba build if we do not
182 # use the system libldb!
183 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
184 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
185 bld.SAMBA_SCRIPT('_ldb_text.py',
186 pattern='_ldb_text.py',
187 installdir='python')
189 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
191 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
192 if bld.is_install:
193 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
194 else:
195 # when we run from the source directory, we want to use
196 # the current modules, not the installed ones
197 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
199 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
201 ldb_headers = ('include/ldb.h include/ldb_errors.h '
202 'include/ldb_module.h include/ldb_handlers.h')
204 bld.SAMBA_LIBRARY('ldb',
205 COMMON_SRC + ' ' + LDB_MAP_SRC,
206 deps='tevent LIBLDB_MAIN replace',
207 includes='include',
208 public_headers=('' if private_library else ldb_headers),
209 public_headers_install=not private_library,
210 pc_files='ldb.pc',
211 vnum=VERSION,
212 private_library=private_library,
213 manpages='man/ldb.3',
214 abi_directory='ABI',
215 abi_match = abi_match)
217 # generate a include/ldb_version.h
218 def generate_ldb_version_h(t):
219 '''generate a vscript file for our public libraries'''
221 tgt = t.outputs[0].bldpath(t.env)
223 v = t.env.LDB_VERSION.split('.')
225 f = open(tgt, mode='w')
226 try:
227 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
228 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
229 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
230 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
231 finally:
232 f.close()
233 return
234 t = bld.SAMBA_GENERATOR('ldb_version.h',
235 rule=generate_ldb_version_h,
236 dep_vars=['LDB_VERSION'],
237 target='include/ldb_version.h',
238 public_headers='include/ldb_version.h',
239 public_headers_install=not private_library)
240 t.env.LDB_VERSION = VERSION
243 bld.SAMBA_MODULE('ldb_paged_results',
244 'modules/paged_results.c',
245 init_function='ldb_paged_results_init',
246 module_init_name='ldb_init_module',
247 internal_module=False,
248 deps='ldb',
249 subsystem='ldb')
251 bld.SAMBA_MODULE('ldb_asq',
252 'modules/asq.c',
253 init_function='ldb_asq_init',
254 module_init_name='ldb_init_module',
255 internal_module=False,
256 deps='ldb',
257 subsystem='ldb')
259 bld.SAMBA_MODULE('ldb_server_sort',
260 'modules/sort.c',
261 init_function='ldb_server_sort_init',
262 internal_module=False,
263 module_init_name='ldb_init_module',
264 deps='ldb',
265 subsystem='ldb')
267 bld.SAMBA_MODULE('ldb_paged_searches',
268 'modules/paged_searches.c',
269 init_function='ldb_paged_searches_init',
270 internal_module=False,
271 module_init_name='ldb_init_module',
272 deps='ldb',
273 subsystem='ldb')
275 bld.SAMBA_MODULE('ldb_rdn_name',
276 'modules/rdn_name.c',
277 init_function='ldb_rdn_name_init',
278 internal_module=False,
279 module_init_name='ldb_init_module',
280 deps='ldb',
281 subsystem='ldb')
283 bld.SAMBA_MODULE('ldb_sample',
284 'tests/sample_module.c',
285 init_function='ldb_sample_init',
286 internal_module=False,
287 module_init_name='ldb_init_module',
288 deps='ldb',
289 subsystem='ldb')
291 bld.SAMBA_MODULE('ldb_skel',
292 'modules/skel.c',
293 init_function='ldb_skel_init',
294 internal_module=False,
295 module_init_name='ldb_init_module',
296 deps='ldb',
297 subsystem='ldb')
299 bld.SAMBA_MODULE('ldb_sqlite3',
300 'sqlite3/ldb_sqlite3.c',
301 init_function='ldb_sqlite3_init',
302 internal_module=False,
303 module_init_name='ldb_init_module',
304 enabled=False,
305 deps='ldb',
306 subsystem='ldb')
308 bld.SAMBA_MODULE('ldb_tdb',
309 bld.SUBDIR('ldb_tdb',
310 '''ldb_tdb.c ldb_search.c ldb_index.c
311 ldb_cache.c ldb_tdb_wrap.c'''),
312 init_function='ldb_tdb_init',
313 module_init_name='ldb_init_module',
314 internal_module=False,
315 deps='tdb ldb',
316 subsystem='ldb')
318 # have a separate subsystem for common/ldb.c, so it can rebuild
319 # for install with a different -DLDB_MODULESDIR=
320 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
321 'common/ldb.c',
322 deps='tevent tdb',
323 includes='include',
324 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
326 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
327 for t in LDB_TOOLS.split():
328 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
329 manpages='man/%s.1' % t)
331 # ldbtest doesn't get installed
332 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
333 install=False)
335 # ldbdump doesn't get installed
336 bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
337 install=False)
339 bld.SAMBA_LIBRARY('ldb-cmdline',
340 source='tools/ldbutil.c tools/cmdline.c',
341 deps='ldb dl popt',
342 private_library=True)
344 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
345 source='tests/ldb_mod_op_test.c',
346 cflags='-DTEST_BE=\"tdb\"',
347 deps='cmocka ldb',
348 install=False)
350 bld.SAMBA_BINARY('ldb_msg_test',
351 source='tests/ldb_msg.c',
352 deps='cmocka ldb',
353 install=False)
355 def test(ctx):
356 '''run ldb testsuite'''
357 import Utils, samba_utils, shutil
358 env = samba_utils.LOAD_ENVIRONMENT()
359 ctx.env = env
361 test_prefix = "%s/st" % (Utils.g_module.blddir)
362 shutil.rmtree(test_prefix, ignore_errors=True)
363 os.makedirs(test_prefix)
364 os.environ['TEST_DATA_PREFIX'] = test_prefix
365 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
366 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
367 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
369 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
370 ret = samba_utils.RUN_COMMAND(cmd)
371 print("testsuite returned %d" % ret)
373 tmp_dir = os.path.join(test_prefix, 'tmp')
374 if not os.path.exists(tmp_dir):
375 os.mkdir(tmp_dir)
376 pyret = samba_utils.RUN_PYTHON_TESTS(
377 ['tests/python/api.py'],
378 extra_env={'SELFTEST_PREFIX': test_prefix})
379 print("Python testsuite returned %d" % pyret)
381 cmocka_ret = 0
382 for test_exe in ['ldb_tdb_mod_op_test',
383 'ldb_msg_test']:
384 cmd = os.path.join(Utils.g_module.blddir, test_exe)
385 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
387 sys.exit(ret or pyret or cmocka_ret)
389 def dist():
390 '''makes a tarball for distribution'''
391 samba_dist.dist()
393 def reconfigure(ctx):
394 '''reconfigure if config scripts have changed'''
395 import samba_utils
396 samba_utils.reconfigure(ctx)