ldb: version 1.2.0
[metze/samba/wip.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.2.0'
5
6 blddir = 'bin'
7
8 import sys, os
9
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')
15
16 import wafsamba, samba_dist, Utils
17
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''')
23
24
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
32
33 def configure(conf):
34     conf.RECURSE('lib/tdb')
35     conf.RECURSE('lib/tevent')
36
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)
45
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)
50
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)
57
58     # where does the default LIBDIR end up? in conf.env somewhere?
59     #
60     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
61
62     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
63
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
76
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
85
86             if using_system_pyldb_util:
87                 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
88
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)
93
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]))
99
100     if conf.env.standalone_ldb:
101         conf.CHECK_XSLTPROC_MANPAGES()
102
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
106
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)
111
112     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
113
114     conf.SAMBA_CONFIG_H()
115
116     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
117
118 def build(bld):
119     bld.RECURSE('lib/tevent')
120
121     if bld.CHECK_FOR_THIRD_PARTY():
122         bld.RECURSE('third_party/popt')
123         bld.RECURSE('third_party/cmocka')
124
125     bld.RECURSE('lib/replace')
126     bld.RECURSE('lib/tdb')
127
128     if bld.env.standalone_ldb:
129         private_library = False
130     else:
131         private_library = True
132
133     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
134                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
135
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''')
140
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')
148
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 = ''
155
156                 if not 'PACKAGE_VERSION' in bld.env:
157                     bld.env.PACKAGE_VERSION = VERSION
158                     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
159
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_*')
173
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)
179
180         for env in bld.gen_python_environments(['PKGCONFIGDIR']):
181                 bld.SAMBA_SCRIPT('_ldb_text.py',
182                                  pattern='_ldb_text.py',
183                                  installdir='python')
184
185                 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
186
187     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
188         if bld.is_install:
189             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
190         else:
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')
194
195         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
196
197         ldb_headers = ('include/ldb.h include/ldb_errors.h '
198                        'include/ldb_module.h include/ldb_handlers.h')
199
200         bld.SAMBA_LIBRARY('ldb',
201                           COMMON_SRC + ' ' + LDB_MAP_SRC,
202                           deps='tevent LIBLDB_MAIN replace',
203                           includes='include',
204                           public_headers=('' if private_library else ldb_headers),
205                           public_headers_install=not private_library,
206                           pc_files='ldb.pc',
207                           vnum=VERSION,
208                           private_library=private_library,
209                           manpages='man/ldb.3',
210                           abi_directory='ABI',
211                           abi_match = abi_match)
212
213         # generate a include/ldb_version.h
214         def generate_ldb_version_h(t):
215             '''generate a vscript file for our public libraries'''
216
217             tgt = t.outputs[0].bldpath(t.env)
218
219             v = t.env.LDB_VERSION.split('.')
220
221             f = open(tgt, mode='w')
222             try:
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]))
227             finally:
228                 f.close()
229             return
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
237
238
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,
244                          deps='ldb',
245                          subsystem='ldb')
246
247         bld.SAMBA_MODULE('ldb_asq',
248                          'modules/asq.c',
249                          init_function='ldb_asq_init',
250                          module_init_name='ldb_init_module',
251                          internal_module=False,
252                          deps='ldb',
253                          subsystem='ldb')
254
255         bld.SAMBA_MODULE('ldb_server_sort',
256                          'modules/sort.c',
257                          init_function='ldb_server_sort_init',
258                          internal_module=False,
259                          module_init_name='ldb_init_module',
260                          deps='ldb',
261                          subsystem='ldb')
262
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',
268                          deps='ldb',
269                          subsystem='ldb')
270
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',
276                          deps='ldb',
277                          subsystem='ldb')
278
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',
284                          deps='ldb',
285                          subsystem='ldb')
286
287         bld.SAMBA_MODULE('ldb_skel',
288                          'modules/skel.c',
289                          init_function='ldb_skel_init',
290                          internal_module=False,
291                          module_init_name='ldb_init_module',
292                          deps='ldb',
293                          subsystem='ldb')
294
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',
300                          enabled=False,
301                          deps='ldb',
302                          subsystem='ldb')
303
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,
311                          deps='tdb ldb',
312                          subsystem='ldb')
313
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',
317                             'common/ldb.c',
318                             deps='tevent tdb',
319                             includes='include',
320                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
321
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)
326
327         # ldbtest doesn't get installed
328         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
329                          install=False)
330
331         # ldbdump doesn't get installed
332         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
333                          install=False)
334
335         bld.SAMBA_LIBRARY('ldb-cmdline',
336                           source='tools/ldbutil.c tools/cmdline.c',
337                           deps='ldb dl popt',
338                           private_library=True)
339
340         bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
341                          source='tests/ldb_mod_op_test.c',
342                          cflags='-DTEST_BE=\"tdb\"',
343                          deps='cmocka ldb',
344                          install=False)
345
346         bld.SAMBA_BINARY('ldb_msg_test',
347                          source='tests/ldb_msg.c',
348                          deps='cmocka ldb',
349                          install=False)
350
351 def test(ctx):
352     '''run ldb testsuite'''
353     import Utils, samba_utils, shutil
354     env = samba_utils.LOAD_ENVIRONMENT()
355     ctx.env = env
356
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)
365
366     tmp_dir = os.path.join(test_prefix, 'tmp')
367     if not os.path.exists(tmp_dir):
368         os.mkdir(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)
373
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'
376     cmocka_ret = 0
377     for test_exe in ['ldb_tdb_mod_op_test',
378                      'ldb_msg_test']:
379             cmd = os.path.join(Utils.g_module.blddir, test_exe)
380             cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
381
382     sys.exit(ret or pyret or cmocka_ret)
383
384 def dist():
385     '''makes a tarball for distribution'''
386     samba_dist.dist()
387
388 def reconfigure(ctx):
389     '''reconfigure if config scripts have changed'''
390     import samba_utils
391     samba_utils.reconfigure(ctx)