lib/ldb: Enable use of a python3 pyldb-util system library
[samba.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.1.29'
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                         buildtools:buildtools third_party/waf:third_party/waf''')
22
23
24 def set_options(opt):
25     opt.BUILTIN_DEFAULT('replace')
26     opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
27     opt.RECURSE('lib/tdb')
28     opt.RECURSE('lib/tevent')
29     opt.RECURSE('lib/replace')
30     opt.tool_options('python') # options for disabling pyc or pyo compilation
31
32 def configure(conf):
33     conf.RECURSE('lib/tdb')
34     conf.RECURSE('lib/tevent')
35
36     if conf.CHECK_FOR_THIRD_PARTY():
37         conf.RECURSE('third_party/popt')
38     else:
39         if not conf.CHECK_POPT():
40             raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
41         else:
42             conf.define('USING_SYSTEM_POPT', 1)
43
44     conf.RECURSE('lib/replace')
45     conf.find_program('python', var='PYTHON')
46     conf.find_program('xsltproc', var='XSLTPROC')
47     conf.check_tool('python')
48     conf.check_python_version((2,4,2))
49     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
50
51     # where does the default LIBDIR end up? in conf.env somewhere?
52     #
53     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
54
55     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
56
57     if not conf.env.standalone_ldb:
58         using_system_pyldb_util = True
59         if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
60                                              onlyif='talloc tdb tevent',
61                                              implied_deps='replace talloc tdb tevent ldb'):
62             using_system_pyldb_util = False
63
64         # We need to get a pyldb-util for all the python versions
65         # we are building for
66         if conf.env['EXTRA_PYTHON']:
67             name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
68             if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
69                                                  onlyif='talloc tdb tevent',
70                                                  implied_deps='replace talloc tdb tevent ldb'):
71                 using_system_pyldb_util = False
72
73         if using_system_pyldb_util:
74             conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
75             if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
76                                          onlyif='talloc tdb tevent pyldb-util',
77                                          implied_deps='replace talloc tdb tevent'):
78                 conf.define('USING_SYSTEM_LDB', 1)
79
80     if conf.env.standalone_ldb:
81         conf.CHECK_XSLTPROC_MANPAGES()
82
83         # we need this for the ldap backend
84         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
85             conf.env.ENABLE_LDAP_BACKEND = True
86
87         # we don't want any libraries or modules to rely on runtime
88         # resolution of symbols
89         if not sys.platform.startswith("openbsd"):
90             conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
91
92     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
93
94     conf.SAMBA_CONFIG_H()
95
96     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
97
98 def build(bld):
99     bld.RECURSE('lib/tevent')
100
101     if bld.CHECK_FOR_THIRD_PARTY():
102         bld.RECURSE('third_party/popt')
103
104     bld.RECURSE('lib/replace')
105     bld.RECURSE('lib/tdb')
106
107     if bld.env.standalone_ldb:
108         private_library = False
109     else:
110         private_library = True
111
112     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
113                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
114
115     COMMON_SRC = bld.SUBDIR('common',
116                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
117                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
118                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
119
120     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
121                      init_function='ldb_ldap_init',
122                      module_init_name='ldb_init_module',
123                      deps='talloc lber ldap ldb',
124                      enabled=bld.env.ENABLE_LDAP_BACKEND,
125                      internal_module=False,
126                      subsystem='ldb')
127
128     if not bld.env.disable_python:
129         if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
130             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
131                 # we're not currently linking against the ldap libs, but ldb.pc.in
132                 # has @LDAP_LIBS@
133                 bld.env.LDAP_LIBS = ''
134
135                 if not 'PACKAGE_VERSION' in bld.env:
136                     bld.env.PACKAGE_VERSION = VERSION
137                     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
138
139                 name = bld.pyembed_libname('pyldb-util')
140                 bld.SAMBA_LIBRARY(name,
141                                   deps='ldb',
142                                   source='pyldb_util.c',
143                                   public_headers=('' if private_library else 'pyldb.h'),
144                                   public_headers_install=not private_library,
145                                   vnum=VERSION,
146                                   private_library=private_library,
147                                   pc_files='pyldb-util.pc',
148                                   pyembed=True,
149                                   abi_directory='ABI',
150                                   abi_match='pyldb_*')
151
152                 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
153                     bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
154                                      deps='ldb ' + name,
155                                      realname='ldb.so',
156                                      cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
157
158             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
159                 bld.SAMBA_SCRIPT('_ldb_text.py',
160                                  pattern='_ldb_text.py',
161                                  installdir='python')
162
163                 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
164
165     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
166         if bld.is_install:
167             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
168         else:
169             # when we run from the source directory, we want to use
170             # the current modules, not the installed ones
171             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
172
173         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
174
175         ldb_headers = ('include/ldb.h include/ldb_errors.h '
176                        'include/ldb_module.h include/ldb_handlers.h')
177
178         bld.SAMBA_LIBRARY('ldb',
179                           COMMON_SRC + ' ' + LDB_MAP_SRC,
180                           deps='tevent LIBLDB_MAIN replace',
181                           includes='include',
182                           public_headers=('' if private_library else ldb_headers),
183                           public_headers_install=not private_library,
184                           pc_files='ldb.pc',
185                           vnum=VERSION,
186                           private_library=private_library,
187                           manpages='man/ldb.3',
188                           abi_directory='ABI',
189                           abi_match = abi_match)
190
191         # generate a include/ldb_version.h
192         t = bld.SAMBA_GENERATOR('ldb_version.h',
193                                 rule='echo "#define LDB_VERSION \\"${LDB_VERSION}\\"" > ${TGT}',
194                                 dep_vars=['LDB_VERSION'],
195                                 target='include/ldb_version.h',
196                                 public_headers='include/ldb_version.h',
197                                 public_headers_install=not private_library)
198         t.env.LDB_VERSION = VERSION
199
200
201         bld.SAMBA_MODULE('ldb_paged_results',
202                          'modules/paged_results.c',
203                          init_function='ldb_paged_results_init',
204                          module_init_name='ldb_init_module',
205                          internal_module=False,
206                          deps='ldb',
207                          subsystem='ldb')
208
209         bld.SAMBA_MODULE('ldb_asq',
210                          'modules/asq.c',
211                          init_function='ldb_asq_init',
212                          module_init_name='ldb_init_module',
213                          internal_module=False,
214                          deps='ldb',
215                          subsystem='ldb')
216
217         bld.SAMBA_MODULE('ldb_server_sort',
218                          'modules/sort.c',
219                          init_function='ldb_server_sort_init',
220                          internal_module=False,
221                          module_init_name='ldb_init_module',
222                          deps='ldb',
223                          subsystem='ldb')
224
225         bld.SAMBA_MODULE('ldb_paged_searches',
226                          'modules/paged_searches.c',
227                          init_function='ldb_paged_searches_init',
228                          internal_module=False,
229                          module_init_name='ldb_init_module',
230                          deps='ldb',
231                          subsystem='ldb')
232
233         bld.SAMBA_MODULE('ldb_rdn_name',
234                          'modules/rdn_name.c',
235                          init_function='ldb_rdn_name_init',
236                          internal_module=False,
237                          module_init_name='ldb_init_module',
238                          deps='ldb',
239                          subsystem='ldb')
240
241         bld.SAMBA_MODULE('ldb_sample',
242                          'tests/sample_module.c',
243                          init_function='ldb_sample_init',
244                          internal_module=False,
245                          module_init_name='ldb_init_module',
246                          deps='ldb',
247                          subsystem='ldb')
248
249         bld.SAMBA_MODULE('ldb_skel',
250                          'modules/skel.c',
251                          init_function='ldb_skel_init',
252                          internal_module=False,
253                          module_init_name='ldb_init_module',
254                          deps='ldb',
255                          subsystem='ldb')
256
257         bld.SAMBA_MODULE('ldb_sqlite3',
258                          'sqlite3/ldb_sqlite3.c',
259                          init_function='ldb_sqlite3_init',
260                          internal_module=False,
261                          module_init_name='ldb_init_module',
262                          enabled=False,
263                          deps='ldb',
264                          subsystem='ldb')
265
266         bld.SAMBA_MODULE('ldb_tdb',
267                          bld.SUBDIR('ldb_tdb',
268                                     '''ldb_tdb.c ldb_search.c ldb_index.c
269                                     ldb_cache.c ldb_tdb_wrap.c'''),
270                          init_function='ldb_tdb_init',
271                          module_init_name='ldb_init_module',
272                          internal_module=False,
273                          deps='tdb ldb',
274                          subsystem='ldb')
275
276         # have a separate subsystem for common/ldb.c, so it can rebuild
277         # for install with a different -DLDB_MODULESDIR=
278         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
279                             'common/ldb.c',
280                             deps='tevent tdb',
281                             includes='include',
282                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
283
284         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
285         for t in LDB_TOOLS.split():
286             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
287                              manpages='man/%s.1' % t)
288
289         # ldbtest doesn't get installed
290         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
291                          install=False)
292
293         # ldbdump doesn't get installed
294         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
295                          install=False)
296
297         bld.SAMBA_LIBRARY('ldb-cmdline',
298                           source='tools/ldbutil.c tools/cmdline.c',
299                           deps='ldb dl popt',
300                           private_library=True)
301
302
303 def test(ctx):
304     '''run ldb testsuite'''
305     import Utils, samba_utils, shutil
306     test_prefix = "%s/st" % (Utils.g_module.blddir)
307     shutil.rmtree(test_prefix, ignore_errors=True)
308     os.makedirs(test_prefix)
309     os.environ['TEST_DATA_PREFIX'] = test_prefix
310     cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
311     ret = samba_utils.RUN_COMMAND(cmd)
312     print("testsuite returned %d" % ret)
313
314     tmp_dir = os.path.join(test_prefix, 'tmp')
315     if not os.path.exists(tmp_dir):
316         os.mkdir(tmp_dir)
317     pyret = samba_utils.RUN_PYTHON_TESTS(
318         ['tests/python/api.py'],
319         extra_env={'SELFTEST_PREFIX': test_prefix})
320     print("Python testsuite returned %d" % pyret)
321     sys.exit(ret or pyret)
322
323 def dist():
324     '''makes a tarball for distribution'''
325     samba_dist.dist()
326
327 def reconfigure(ctx):
328     '''reconfigure if config scripts have changed'''
329     import samba_utils
330     samba_utils.reconfigure(ctx)