VERSION: Bump version up to 4.7.0rc4...
[Samba.git] / lib / ldb / wscript
blob6f3b32665d325976ae241ecbb013be979f9befdd
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.2.1'
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''')
25 def set_options(opt):
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
33 def configure(conf):
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')
40 else:
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.')
43 else:
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.')
48 else:
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)
70 else:
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
78 # we are building for
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()
118 def build(bld):
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
130 else:
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,
147 subsystem='ldb')
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
153 # has @LDAP_LIBS@
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,
162 deps='ldb',
163 source='pyldb_util.c',
164 public_headers=('' if private_library else 'pyldb.h'),
165 public_headers_install=not private_library,
166 vnum=VERSION,
167 private_library=private_library,
168 pc_files='pyldb-util.pc',
169 pyembed=True,
170 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
171 abi_directory='ABI',
172 abi_match='pyldb_*')
174 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
175 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
176 deps='ldb ' + name,
177 realname='ldb.so',
178 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
180 # Do only install this file as part of the Samba build if we do not
181 # use the system libldb!
182 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
183 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
184 bld.SAMBA_SCRIPT('_ldb_text.py',
185 pattern='_ldb_text.py',
186 installdir='python')
188 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
190 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
191 if bld.is_install:
192 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
193 else:
194 # when we run from the source directory, we want to use
195 # the current modules, not the installed ones
196 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
198 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
200 ldb_headers = ('include/ldb.h include/ldb_errors.h '
201 'include/ldb_module.h include/ldb_handlers.h')
203 bld.SAMBA_LIBRARY('ldb',
204 COMMON_SRC + ' ' + LDB_MAP_SRC,
205 deps='tevent LIBLDB_MAIN replace',
206 includes='include',
207 public_headers=('' if private_library else ldb_headers),
208 public_headers_install=not private_library,
209 pc_files='ldb.pc',
210 vnum=VERSION,
211 private_library=private_library,
212 manpages='man/ldb.3',
213 abi_directory='ABI',
214 abi_match = abi_match)
216 # generate a include/ldb_version.h
217 def generate_ldb_version_h(t):
218 '''generate a vscript file for our public libraries'''
220 tgt = t.outputs[0].bldpath(t.env)
222 v = t.env.LDB_VERSION.split('.')
224 f = open(tgt, mode='w')
225 try:
226 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
227 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
228 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
229 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
230 finally:
231 f.close()
232 return
233 t = bld.SAMBA_GENERATOR('ldb_version.h',
234 rule=generate_ldb_version_h,
235 dep_vars=['LDB_VERSION'],
236 target='include/ldb_version.h',
237 public_headers='include/ldb_version.h',
238 public_headers_install=not private_library)
239 t.env.LDB_VERSION = VERSION
242 bld.SAMBA_MODULE('ldb_paged_results',
243 'modules/paged_results.c',
244 init_function='ldb_paged_results_init',
245 module_init_name='ldb_init_module',
246 internal_module=False,
247 deps='ldb',
248 subsystem='ldb')
250 bld.SAMBA_MODULE('ldb_asq',
251 'modules/asq.c',
252 init_function='ldb_asq_init',
253 module_init_name='ldb_init_module',
254 internal_module=False,
255 deps='ldb',
256 subsystem='ldb')
258 bld.SAMBA_MODULE('ldb_server_sort',
259 'modules/sort.c',
260 init_function='ldb_server_sort_init',
261 internal_module=False,
262 module_init_name='ldb_init_module',
263 deps='ldb',
264 subsystem='ldb')
266 bld.SAMBA_MODULE('ldb_paged_searches',
267 'modules/paged_searches.c',
268 init_function='ldb_paged_searches_init',
269 internal_module=False,
270 module_init_name='ldb_init_module',
271 deps='ldb',
272 subsystem='ldb')
274 bld.SAMBA_MODULE('ldb_rdn_name',
275 'modules/rdn_name.c',
276 init_function='ldb_rdn_name_init',
277 internal_module=False,
278 module_init_name='ldb_init_module',
279 deps='ldb',
280 subsystem='ldb')
282 bld.SAMBA_MODULE('ldb_sample',
283 'tests/sample_module.c',
284 init_function='ldb_sample_init',
285 internal_module=False,
286 module_init_name='ldb_init_module',
287 deps='ldb',
288 subsystem='ldb')
290 bld.SAMBA_MODULE('ldb_skel',
291 'modules/skel.c',
292 init_function='ldb_skel_init',
293 internal_module=False,
294 module_init_name='ldb_init_module',
295 deps='ldb',
296 subsystem='ldb')
298 bld.SAMBA_MODULE('ldb_sqlite3',
299 'sqlite3/ldb_sqlite3.c',
300 init_function='ldb_sqlite3_init',
301 internal_module=False,
302 module_init_name='ldb_init_module',
303 enabled=False,
304 deps='ldb',
305 subsystem='ldb')
307 bld.SAMBA_MODULE('ldb_tdb',
308 bld.SUBDIR('ldb_tdb',
309 '''ldb_tdb.c ldb_search.c ldb_index.c
310 ldb_cache.c ldb_tdb_wrap.c'''),
311 init_function='ldb_tdb_init',
312 module_init_name='ldb_init_module',
313 internal_module=False,
314 deps='tdb ldb',
315 subsystem='ldb')
317 # have a separate subsystem for common/ldb.c, so it can rebuild
318 # for install with a different -DLDB_MODULESDIR=
319 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
320 'common/ldb.c',
321 deps='tevent tdb',
322 includes='include',
323 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
325 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
326 for t in LDB_TOOLS.split():
327 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
328 manpages='man/%s.1' % t)
330 # ldbtest doesn't get installed
331 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
332 install=False)
334 # ldbdump doesn't get installed
335 bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
336 install=False)
338 bld.SAMBA_LIBRARY('ldb-cmdline',
339 source='tools/ldbutil.c tools/cmdline.c',
340 deps='ldb dl popt',
341 private_library=True)
343 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
344 source='tests/ldb_mod_op_test.c',
345 cflags='-DTEST_BE=\"tdb\"',
346 deps='cmocka ldb',
347 install=False)
349 bld.SAMBA_BINARY('ldb_msg_test',
350 source='tests/ldb_msg.c',
351 deps='cmocka ldb',
352 install=False)
354 def test(ctx):
355 '''run ldb testsuite'''
356 import Utils, samba_utils, shutil
357 env = samba_utils.LOAD_ENVIRONMENT()
358 ctx.env = env
360 test_prefix = "%s/st" % (Utils.g_module.blddir)
361 shutil.rmtree(test_prefix, ignore_errors=True)
362 os.makedirs(test_prefix)
363 os.environ['TEST_DATA_PREFIX'] = test_prefix
364 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
365 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
366 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
368 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
369 ret = samba_utils.RUN_COMMAND(cmd)
370 print("testsuite returned %d" % ret)
372 tmp_dir = os.path.join(test_prefix, 'tmp')
373 if not os.path.exists(tmp_dir):
374 os.mkdir(tmp_dir)
375 pyret = samba_utils.RUN_PYTHON_TESTS(
376 ['tests/python/api.py'],
377 extra_env={'SELFTEST_PREFIX': test_prefix})
378 print("Python testsuite returned %d" % pyret)
380 cmocka_ret = 0
381 for test_exe in ['ldb_tdb_mod_op_test',
382 'ldb_msg_test']:
383 cmd = os.path.join(Utils.g_module.blddir, test_exe)
384 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
386 sys.exit(ret or pyret or cmocka_ret)
388 def dist():
389 '''makes a tarball for distribution'''
390 samba_dist.dist()
392 def reconfigure(ctx):
393 '''reconfigure if config scripts have changed'''
394 import samba_utils
395 samba_utils.reconfigure(ctx)