1455f92eb2e5c88a284788deee6b5214a814e924
[samba.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.3.2'
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 samba_dist.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
25
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
33
34 def configure(conf):
35     conf.RECURSE('lib/tdb')
36     conf.RECURSE('lib/tevent')
37
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)
46
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)
51
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)
58
59     # where does the default LIBDIR end up? in conf.env somewhere?
60     #
61     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
62
63     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
64
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
77
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
86
87             if using_system_pyldb_util:
88                 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
89
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)
94
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]))
100
101     if conf.env.standalone_ldb:
102         conf.CHECK_XSLTPROC_MANPAGES()
103
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
107
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)
112
113     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
114
115     conf.SAMBA_CONFIG_H()
116
117     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
118
119 def build(bld):
120     bld.RECURSE('lib/tevent')
121
122     if bld.CHECK_FOR_THIRD_PARTY():
123         bld.RECURSE('third_party/popt')
124         bld.RECURSE('third_party/cmocka')
125
126     bld.RECURSE('lib/replace')
127     bld.RECURSE('lib/tdb')
128
129     if bld.env.standalone_ldb:
130         private_library = False
131     else:
132         private_library = True
133
134     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
135                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
136
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''')
141
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')
149
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 = ''
156
157                 if not 'PACKAGE_VERSION' in bld.env:
158                     bld.env.PACKAGE_VERSION = VERSION
159                     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
160
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_*')
174
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)
180
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')
188
189                     bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
190
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')
198
199         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
200
201         ldb_headers = ('include/ldb.h include/ldb_errors.h '
202                        'include/ldb_module.h include/ldb_handlers.h')
203
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)
216
217         # generate a include/ldb_version.h
218         def generate_ldb_version_h(t):
219             '''generate a vscript file for our public libraries'''
220
221             tgt = t.outputs[0].bldpath(t.env)
222
223             v = t.env.LDB_VERSION.split('.')
224
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
241
242
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')
250
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')
258
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')
266
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')
274
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')
282
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')
290
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')
298
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')
307
308         bld.SAMBA_MODULE('ldb_tdb',
309                          bld.SUBDIR('ldb_tdb',
310                                     '''ldb_tdb_init.c'''),
311                          init_function='ldb_tdb_init',
312                          module_init_name='ldb_init_module',
313                          internal_module=False,
314                          deps='tdb ldb ldb_key_value',
315                          subsystem='ldb')
316
317         bld.SAMBA_LIBRARY('ldb_key_value',
318                           bld.SUBDIR('ldb_tdb',
319                                     '''ldb_tdb.c ldb_search.c ldb_index.c
320                                     ldb_cache.c ldb_tdb_wrap.c'''),
321                           private_library=True,
322                           deps='tdb ldb')
323
324         # have a separate subsystem for common/ldb.c, so it can rebuild
325         # for install with a different -DLDB_MODULESDIR=
326         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
327                             'common/ldb.c',
328                             deps='tevent tdb',
329                             includes='include',
330                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
331
332         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
333         for t in LDB_TOOLS.split():
334             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
335                              manpages='man/%s.1' % t)
336
337         # ldbtest doesn't get installed
338         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
339                          install=False)
340
341         # ldbdump doesn't get installed
342         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
343                          install=False)
344
345         bld.SAMBA_LIBRARY('ldb-cmdline',
346                           source='tools/ldbutil.c tools/cmdline.c',
347                           deps='ldb dl popt',
348                           private_library=True)
349
350         bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
351                          source='tests/ldb_mod_op_test.c',
352                          cflags='-DTEST_BE=\"tdb\"',
353                          deps='cmocka ldb',
354                          install=False)
355
356         bld.SAMBA_BINARY('ldb_msg_test',
357                          source='tests/ldb_msg.c',
358                          deps='cmocka ldb',
359                          install=False)
360
361 def test(ctx):
362     '''run ldb testsuite'''
363     import Utils, samba_utils, shutil
364     env = samba_utils.LOAD_ENVIRONMENT()
365     ctx.env = env
366
367     test_prefix = "%s/st" % (Utils.g_module.blddir)
368     shutil.rmtree(test_prefix, ignore_errors=True)
369     os.makedirs(test_prefix)
370     os.environ['TEST_DATA_PREFIX'] = test_prefix
371     os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
372     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
373     samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
374
375     cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
376     ret = samba_utils.RUN_COMMAND(cmd)
377     print("testsuite returned %d" % ret)
378
379     tmp_dir = os.path.join(test_prefix, 'tmp')
380     if not os.path.exists(tmp_dir):
381         os.mkdir(tmp_dir)
382     pyret = samba_utils.RUN_PYTHON_TESTS(
383         ['tests/python/api.py', 'tests/python/index.py'],
384         extra_env={'SELFTEST_PREFIX': test_prefix})
385     print("Python testsuite returned %d" % pyret)
386
387     cmocka_ret = 0
388     for test_exe in ['ldb_tdb_mod_op_test',
389                      'ldb_msg_test']:
390             cmd = os.path.join(Utils.g_module.blddir, test_exe)
391             cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
392
393     sys.exit(ret or pyret or cmocka_ret)
394
395 def dist():
396     '''makes a tarball for distribution'''
397     samba_dist.dist()
398
399 def reconfigure(ctx):
400     '''reconfigure if config scripts have changed'''
401     import samba_utils
402     samba_utils.reconfigure(ctx)