WIP RBTREE
[asn/samba.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 # For Samba 4.21.x
4 LDB_VERSION = '2.10.0'
5
6 import sys, os
7
8 from wafsamba import samba_dist, samba_utils, samba_bundled
9 from waflib import Errors, Options, Logs, Context
10 import shutil
11
12 def options(opt):
13
14     opt.add_option('--without-ldb-lmdb',
15                    help='disable new LMDB backend for LDB',
16                    action='store_true', dest='without_ldb_lmdb', default=False)
17
18 def configure(conf):
19     # where does the default LIBDIR end up? in conf.env somewhere?
20     #
21     conf.env.ldb_modules_install_dir = conf.SUBST_ENV_VAR('LDBMODULESDIR')
22     conf.CONFIG_PATH('LDB_MODULESDIR', conf.env.ldb_modules_install_dir)
23
24     if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
25                            "HAVE_64_BIT_SIZE_T_FOR_LMDB",
26                            execute=True,
27                            msg='Checking for a 64-bit host to '
28                            'support lmdb'):
29         Logs.warn("--without-ldb-lmdb implied as this "
30                   "host is not 64-bit")
31
32         if not Options.options.without_ad_dc and \
33            conf.CONFIG_GET('ENABLE_SELFTEST'):
34             Logs.warn("NOTE: Some AD DC parts of selftest will fail")
35
36         conf.env.REQUIRE_LMDB = False
37     else:
38         if Options.options.without_ad_dc:
39             conf.env.REQUIRE_LMDB = False
40         else:
41             if Options.options.without_ldb_lmdb:
42                 if not Options.options.without_ad_dc and \
43                    conf.CONFIG_GET('ENABLE_SELFTEST'):
44                     raise Errors.WafError('--without-ldb-lmdb conflicts '
45                                          'with --enable-selftest while '
46                                          'building the AD DC')
47
48                 conf.env.REQUIRE_LMDB = False
49             else:
50                 conf.env.REQUIRE_LMDB = True
51
52     # if lmdb support is enabled then we require lmdb
53     # is present, build the mdb back end and enable lmdb support in
54     # the tools.
55     if conf.env.REQUIRE_LMDB:
56         if not conf.CHECK_CFG(package='lmdb',
57                               args='"lmdb >= 0.9.16" --cflags --libs',
58                               msg='Checking for lmdb >= 0.9.16',
59                               mandatory=False):
60             if not conf.CHECK_CODE('''
61                     #if MDB_VERSION_MAJOR == 0 \
62                       && MDB_VERSION_MINOR <= 9 \
63                       && MDB_VERSION_PATCH < 16
64                     #error LMDB too old
65                     #endif
66                     ''',
67                     'HAVE_GOOD_LMDB_VERSION',
68                     headers='lmdb.h',
69                     msg='Checking for lmdb >= 0.9.16 via header check'):
70
71                 if not Options.options.without_ad_dc:
72                     raise Errors.WafError('Samba AD DC and --enable-selftest '
73                                          'requires '
74                                          'lmdb 0.9.16 or later')
75                 else:
76                     raise Errors.WafError('ldb build (unless --without-ldb-lmdb) '
77                                          'requires '
78                                          'lmdb 0.9.16 or later')
79
80         if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
81             conf.DEFINE('HAVE_LMDB', '1')
82             conf.env.HAVE_LMDB = True
83
84     conf.env.ldb_is_public_library \
85         = not samba_bundled.LIB_MUST_BE_PRIVATE(conf, 'ldb')
86
87 def build(bld):
88     bld.env.LDB_PACKAGE_VERSION = LDB_VERSION
89
90     # we're not currently linking against the ldap libs, but ldb.pc.in
91     # has @LDAP_LIBS@
92     bld.env.LDAP_LIBS = ''
93
94     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
95                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
96
97     COMMON_SRC = bld.SUBDIR('common',
98                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
99                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
100                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
101
102     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
103                      init_function='ldb_ldap_init',
104                      module_init_name='ldb_init_module',
105                      deps='talloc lber ldap ldb',
106                      enabled=bld.env.ENABLE_LDAP_BACKEND,
107                      internal_module=False,
108                      subsystem='ldb')
109
110     if bld.PYTHON_BUILD_IS_ENABLED():
111         name = bld.pyembed_libname('pyldb-util')
112         bld.SAMBA_LIBRARY(name,
113                           deps='replace ldb',
114                           source='pyldb_util.c',
115                           private_library=True,
116                           pyembed=True,
117                           enabled=bld.PYTHON_BUILD_IS_ENABLED())
118
119         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
120                          deps='replace ldb ' + name,
121                          realname='ldb.so',
122                          cflags='-DPACKAGE_VERSION=\"%s\"' % LDB_VERSION)
123
124         bld.SAMBA_SCRIPT('_ldb_text.py',
125                          pattern='_ldb_text.py',
126                          installdir='python')
127
128         bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
129
130     if bld.is_install:
131         modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
132     else:
133         # when we run from the source directory, we want to use
134         # the current modules, not the installed ones
135         modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
136
137     abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
138
139     ldb_headers = ('include/ldb.h include/ldb_errors.h '
140                    'include/ldb_module.h include/ldb_handlers.h')
141
142     bld.SAMBA_LIBRARY('ldb',
143                       COMMON_SRC + ' ' + LDB_MAP_SRC,
144                       deps='tevent LIBLDB_MAIN replace',
145                       includes='include',
146                       public_headers=ldb_headers,
147                       public_headers_install=True,
148                       pc_files='ldb.pc',
149                       vnum=LDB_VERSION,
150                       private_library=False,
151                       manpages='man/ldb.3',
152                       abi_directory='ABI',
153                       abi_match = abi_match)
154
155     # generate a include/ldb_version.h
156     def generate_ldb_version_h(t):
157         '''generate a vscript file for our public libraries'''
158
159         tgt = t.outputs[0].bldpath(t.env)
160
161         v = t.env.LDB_VERSION.split('.')
162
163         f = open(tgt, mode='w')
164         try:
165             f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
166             f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
167             f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
168             f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
169         finally:
170             f.close()
171         return
172     t = bld.SAMBA_GENERATOR('ldb_version.h',
173                             rule=generate_ldb_version_h,
174                             dep_vars=['LDB_VERSION'],
175                             target='include/ldb_version.h',
176                             public_headers='include/ldb_version.h',
177                             public_headers_install=not bld.env.ldb_is_public_library)
178     t.env.LDB_VERSION = LDB_VERSION
179
180     bld.SAMBA_MODULE('ldb_asq',
181                      'modules/asq.c',
182                      init_function='ldb_asq_init',
183                      module_init_name='ldb_init_module',
184                      internal_module=False,
185                      deps='ldb',
186                      subsystem='ldb')
187
188     bld.SAMBA_MODULE('ldb_server_sort',
189                      'modules/sort.c',
190                      init_function='ldb_server_sort_init',
191                      internal_module=False,
192                      module_init_name='ldb_init_module',
193                      deps='ldb',
194                      subsystem='ldb')
195
196     bld.SAMBA_MODULE('ldb_paged_searches',
197                      'modules/paged_searches.c',
198                      init_function='ldb_paged_searches_init',
199                      internal_module=False,
200                      module_init_name='ldb_init_module',
201                      deps='ldb',
202                      subsystem='ldb')
203
204     bld.SAMBA_MODULE('ldb_rdn_name',
205                      'modules/rdn_name.c',
206                      init_function='ldb_rdn_name_init',
207                      internal_module=False,
208                      module_init_name='ldb_init_module',
209                      deps='ldb',
210                      subsystem='ldb')
211
212     bld.SAMBA_MODULE('ldb_sample',
213                      'tests/sample_module.c',
214                      init_function='ldb_sample_init',
215                      internal_module=False,
216                      module_init_name='ldb_init_module',
217                      deps='ldb',
218                      subsystem='ldb')
219
220     bld.SAMBA_MODULE('ldb_skel',
221                      'modules/skel.c',
222                      init_function='ldb_skel_init',
223                      internal_module=False,
224                      module_init_name='ldb_init_module',
225                      deps='ldb',
226                      subsystem='ldb')
227
228     bld.SAMBA_MODULE('ldb_sqlite3',
229                      'sqlite3/ldb_sqlite3.c',
230                      init_function='ldb_sqlite3_init',
231                      internal_module=False,
232                      module_init_name='ldb_init_module',
233                      enabled=False,
234                      deps='ldb',
235                      subsystem='ldb')
236
237     bld.SAMBA_MODULE('ldb_tdb',
238                      bld.SUBDIR('ldb_tdb',
239                                 '''ldb_tdb_init.c'''),
240                      init_function='ldb_tdb_init',
241                      module_init_name='ldb_init_module',
242                      internal_module=False,
243                      deps='ldb ldb_tdb_int ldb_key_value',
244                      subsystem='ldb')
245
246     bld.SAMBA_LIBRARY('ldb_tdb_int',
247                       bld.SUBDIR('ldb_tdb',
248                                  '''ldb_tdb_wrap.c ldb_tdb.c'''),
249                       private_library=True,
250                       deps='ldb tdb ldb_key_value ldb_tdb_err_map')
251
252     bld.SAMBA_LIBRARY('ldb_tdb_err_map',
253                       bld.SUBDIR('ldb_tdb',
254                                  '''ldb_tdb_err_map.c '''),
255                       private_library=True,
256                       deps='ldb tdb')
257
258     bld.SAMBA_LIBRARY('ldb_key_value',
259                       bld.SUBDIR('ldb_key_value',
260                                 '''ldb_kv.c ldb_kv_search.c ldb_kv_index.c
261                                 ldb_kv_cache.c'''),
262                       private_library=True,
263                       deps='tdb ldb ldb_tdb_err_map dbwrap')
264
265     if bld.CONFIG_SET('HAVE_LMDB'):
266         bld.SAMBA_MODULE('ldb_mdb',
267                          bld.SUBDIR('ldb_mdb',
268                                     '''ldb_mdb_init.c'''),
269                          init_function='ldb_mdb_init',
270                          module_init_name='ldb_init_module',
271                          internal_module=False,
272                          deps='ldb ldb_key_value ldb_mdb_int',
273                          subsystem='ldb')
274
275         bld.SAMBA_LIBRARY('ldb_mdb_int',
276                           bld.SUBDIR('ldb_mdb',
277                                      '''ldb_mdb.c '''),
278                           private_library=True,
279                           deps='ldb lmdb ldb_key_value')
280         lmdb_deps = ' ldb_mdb_int'
281     else:
282         lmdb_deps = ''
283
284
285     bld.SAMBA_MODULE('ldb_ldb',
286                      bld.SUBDIR('ldb_ldb',
287                                 '''ldb_ldb.c'''),
288                      init_function='ldb_ldb_init',
289                      module_init_name='ldb_init_module',
290                      internal_module=False,
291                      deps='ldb ldb_tdb_int ldb_key_value' + lmdb_deps,
292                      subsystem='ldb')
293
294     # have a separate subsystem for common/ldb.c, so it can rebuild
295     # for install with a different -DLDB_MODULESDIR=
296     bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
297                         'common/ldb.c',
298                         deps='tevent tdb',
299                         includes='include',
300                         cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
301
302     LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
303     for t in LDB_TOOLS.split():
304         bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
305                          manpages='man/%s.1' % t)
306
307     # ldbtest doesn't get installed
308     bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
309                      install=False)
310
311     if bld.CONFIG_SET('HAVE_LMDB'):
312         lmdb_deps = ' lmdb'
313     else:
314         lmdb_deps = ''
315     # ldbdump doesn't get installed
316     bld.SAMBA_BINARY('ldbdump',
317                      'tools/ldbdump.c',
318                      deps='ldb-cmdline ldb' + lmdb_deps,
319                      install=False)
320
321     bld.SAMBA_LIBRARY('ldb-cmdline',
322                       source='tools/ldbutil.c tools/cmdline.c',
323                       deps='ldb dl popt',
324                       private_library=True)
325
326     bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
327                      source='tests/ldb_mod_op_test.c',
328                      cflags='-DTEST_BE=\"tdb\"',
329                      deps='cmocka ldb',
330                      install=False)
331
332     bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
333                      source='tests/ldb_mod_op_test.c',
334                      cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
335                      deps='cmocka ldb',
336                      install=False)
337
338     bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
339                      source='tests/ldb_kv_ops_test.c',
340                      cflags='-DTEST_BE=\"tdb\"',
341                      deps='cmocka ldb',
342                      install=False)
343
344     bld.SAMBA_BINARY('ldb_tdb_test',
345                      source='tests/ldb_tdb_test.c',
346                      deps='cmocka ldb',
347                      install=False)
348
349     bld.SAMBA_BINARY('ldb_msg_test',
350                      source='tests/ldb_msg.c',
351                      deps='cmocka ldb',
352                      install=False)
353
354     bld.SAMBA_BINARY('test_ldb_qsort',
355                      source='tests/test_ldb_qsort.c',
356                      deps='cmocka ldb',
357                      install=False)
358
359     bld.SAMBA_BINARY('test_ldb_dn',
360                      source='tests/test_ldb_dn.c',
361                      deps='cmocka ldb',
362                      install=False)
363
364     bld.SAMBA_BINARY('ldb_match_test',
365                      source='tests/ldb_match_test.c',
366                      deps='cmocka ldb',
367                      install=False)
368
369     bld.SAMBA_BINARY('ldb_parse_test',
370                      source='tests/ldb_parse_test.c',
371                      deps='cmocka ldb ldb_tdb_err_map',
372                      install=False)
373
374     bld.SAMBA_BINARY('ldb_filter_attrs_test',
375                      source='tests/ldb_filter_attrs_test.c',
376                      deps='cmocka ldb ldb_tdb_err_map',
377                      install=False)
378
379     bld.SAMBA_BINARY('ldb_filter_attrs_in_place_test',
380                      source='tests/ldb_filter_attrs_in_place_test.c',
381                      deps='cmocka ldb ldb_tdb_err_map',
382                      install=False)
383
384     bld.SAMBA_BINARY('ldb_key_value_sub_txn_tdb_test',
385                      bld.SUBDIR('ldb_key_value',
386                          '''ldb_kv_search.c
387                             ldb_kv_index.c
388                             ldb_kv_cache.c''') +
389                      'tests/ldb_key_value_sub_txn_test.c',
390                      cflags='-DTEST_BE=\"tdb\"',
391                      deps='cmocka ldb ldb_tdb_err_map dbwrap',
392                      install=False)
393
394     # If both libldap and liblber are available, test ldb_ldap
395     # code for a regression of bz#14413 -- even if we don't build
396     # it ourselves and simply using the system version
397     if bld.env.LIB_LDAP and bld.env.LIB_LBER:
398         bld.SAMBA_BINARY('lldb_ldap_test',
399                          source='tests/lldb_ldap.c',
400                          deps='cmocka talloc lber ldap ldb',
401                          install=False)
402
403     if bld.CONFIG_SET('HAVE_LMDB'):
404         bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
405                          source='tests/ldb_mod_op_test.c',
406                          cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
407                               + '-DTEST_LMDB=1',
408                          deps='cmocka ldb lmdb',
409                          install=False)
410
411         bld.SAMBA_BINARY('ldb_lmdb_test',
412                          source='tests/ldb_lmdb_test.c',
413                          deps='cmocka ldb',
414                          install=False)
415
416         bld.SAMBA_BINARY('ldb_lmdb_size_test',
417                          source='tests/ldb_lmdb_size_test.c',
418                          deps='cmocka ldb',
419                          install=False)
420
421         bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
422                          source='tests/ldb_kv_ops_test.c',
423                          cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
424                          deps='cmocka ldb',
425                          install=False)
426
427         bld.SAMBA_BINARY('ldb_lmdb_free_list_test',
428                          source='tests/ldb_lmdb_free_list_test.c',
429                          cflags='-DTEST_BE=\"mdb\" -DTEST_LMDB=1',
430                          deps='cmocka ldb',
431                          install=False)
432         #
433         # We rely on the versions of the ldb_key_value functions included
434         # in ldb_key_value_sub_txn_test.c taking priority over the versions
435         # in the ldb_key_value shared library.
436         # If this turns out to not be the case, the dependencies will
437         # need to be unrolled, and all the source files included and the
438         # ldb_tdb module initialization code will need to be called
439         # manually.
440         bld.SAMBA_BINARY('ldb_key_value_sub_txn_mdb_test',
441                          bld.SUBDIR('ldb_key_value',
442                              '''ldb_kv_search.c
443                                 ldb_kv_index.c
444                                 ldb_kv_cache.c''') +
445                          'tests/ldb_key_value_sub_txn_test.c',
446                          cflags='-DTEST_BE=\"mdb\"',
447                          deps='cmocka ldb ldb_tdb_err_map dbwrap',
448                          install=False)
449     else:
450         bld.SAMBA_BINARY('ldb_no_lmdb_test',
451                          source='tests/ldb_no_lmdb_test.c',
452                          deps='cmocka ldb',
453                          install=False)
454