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