ldb: increment version due to added ldb_unpack_data_only_attr_list
[samba.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.1.25'
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         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.env.disable_python:
124         if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
125             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
126                 name = bld.pyembed_libname('pyldb-util')
127                 bld.SAMBA_LIBRARY(name,
128                                   deps='ldb',
129                                   source='pyldb_util.c',
130                                   public_headers='pyldb.h',
131                                   public_headers_install=not private_library,
132                                   vnum=VERSION,
133                                   private_library=private_library,
134                                   pc_files='pyldb-util.pc',
135                                   pyembed=True,
136                                   abi_directory='ABI',
137                                   abi_match='pyldb_*')
138
139                 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
140                     bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
141                                      deps='ldb ' + name,
142                                      realname='ldb.so',
143                                      cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
144
145             for env in bld.gen_python_environments(['PKGCONFIGDIR']):
146                 bld.SAMBA_SCRIPT('_ldb_text.py',
147                                  pattern='_ldb_text.py',
148                                  installdir='python')
149
150                 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
151
152     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
153         if bld.is_install:
154             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
155         else:
156             # when we run from the source directory, we want to use
157             # the current modules, not the installed ones
158             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
159
160         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
161
162         bld.SAMBA_LIBRARY('ldb',
163                           COMMON_SRC + ' ' + LDB_MAP_SRC,
164                           deps='tevent LIBLDB_MAIN replace',
165                           includes='include',
166                           public_headers='include/ldb.h include/ldb_errors.h '\
167                           'include/ldb_module.h include/ldb_handlers.h',
168                           public_headers_install=not private_library,
169                           pc_files='ldb.pc',
170                           vnum=VERSION,
171                           private_library=private_library,
172                           manpages='man/ldb.3',
173                           abi_directory='ABI',
174                           abi_match = abi_match)
175
176         # generate a include/ldb_version.h
177         t = bld.SAMBA_GENERATOR('ldb_version.h',
178                                 rule='echo "#define LDB_VERSION \\"${LDB_VERSION}\\"" > ${TGT}',
179                                 dep_vars=['LDB_VERSION'],
180                                 target='include/ldb_version.h',
181                                 public_headers='include/ldb_version.h',
182                                 public_headers_install=not private_library)
183         t.env.LDB_VERSION = VERSION
184
185
186         bld.SAMBA_MODULE('ldb_paged_results',
187                          'modules/paged_results.c',
188                          init_function='ldb_paged_results_init',
189                          module_init_name='ldb_init_module',
190                          internal_module=False,
191                          deps='ldb',
192                          subsystem='ldb')
193
194         bld.SAMBA_MODULE('ldb_asq',
195                          'modules/asq.c',
196                          init_function='ldb_asq_init',
197                          module_init_name='ldb_init_module',
198                          internal_module=False,
199                          deps='ldb',
200                          subsystem='ldb')
201
202         bld.SAMBA_MODULE('ldb_server_sort',
203                          'modules/sort.c',
204                          init_function='ldb_server_sort_init',
205                          internal_module=False,
206                          module_init_name='ldb_init_module',
207                          deps='ldb',
208                          subsystem='ldb')
209
210         bld.SAMBA_MODULE('ldb_paged_searches',
211                          'modules/paged_searches.c',
212                          init_function='ldb_paged_searches_init',
213                          internal_module=False,
214                          module_init_name='ldb_init_module',
215                          deps='ldb',
216                          subsystem='ldb')
217
218         bld.SAMBA_MODULE('ldb_rdn_name',
219                          'modules/rdn_name.c',
220                          init_function='ldb_rdn_name_init',
221                          internal_module=False,
222                          module_init_name='ldb_init_module',
223                          deps='ldb',
224                          subsystem='ldb')
225
226         bld.SAMBA_MODULE('ldb_sample',
227                          'tests/sample_module.c',
228                          init_function='ldb_sample_init',
229                          internal_module=False,
230                          module_init_name='ldb_init_module',
231                          deps='ldb',
232                          subsystem='ldb')
233
234         bld.SAMBA_MODULE('ldb_skel',
235                          'modules/skel.c',
236                          init_function='ldb_skel_init',
237                          internal_module=False,
238                          module_init_name='ldb_init_module',
239                          deps='ldb',
240                          subsystem='ldb')
241
242         bld.SAMBA_MODULE('ldb_sqlite3',
243                          'sqlite3/ldb_sqlite3.c',
244                          init_function='ldb_sqlite3_init',
245                          internal_module=False,
246                          module_init_name='ldb_init_module',
247                          enabled=False,
248                          deps='ldb',
249                          subsystem='ldb')
250
251         bld.SAMBA_MODULE('ldb_tdb',
252                          bld.SUBDIR('ldb_tdb',
253                                     '''ldb_tdb.c ldb_search.c ldb_index.c
254                                     ldb_cache.c ldb_tdb_wrap.c'''),
255                          init_function='ldb_tdb_init',
256                          module_init_name='ldb_init_module',
257                          internal_module=False,
258                          deps='tdb ldb',
259                          subsystem='ldb')
260
261         # have a separate subsystem for common/ldb.c, so it can rebuild
262         # for install with a different -DLDB_MODULESDIR=
263         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
264                             'common/ldb.c',
265                             deps='tevent tdb',
266                             includes='include',
267                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
268
269         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
270         for t in LDB_TOOLS.split():
271             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
272                              manpages='man/%s.1' % t)
273
274         # ldbtest doesn't get installed
275         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
276                          install=False)
277
278         # ldbdump doesn't get installed
279         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
280                          install=False)
281
282         bld.SAMBA_LIBRARY('ldb-cmdline',
283                           source='tools/ldbutil.c tools/cmdline.c',
284                           deps='ldb dl popt',
285                           private_library=True)
286
287
288 def test(ctx):
289     '''run ldb testsuite'''
290     import Utils, samba_utils, shutil
291     test_prefix = "%s/st" % (Utils.g_module.blddir)
292     shutil.rmtree(test_prefix, ignore_errors=True)
293     os.makedirs(test_prefix)
294     os.environ['TEST_DATA_PREFIX'] = test_prefix
295     cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
296     ret = samba_utils.RUN_COMMAND(cmd)
297     print("testsuite returned %d" % ret)
298
299     tmp_dir = os.path.join(test_prefix, 'tmp')
300     if not os.path.exists(tmp_dir):
301         os.mkdir(tmp_dir)
302     pyret = samba_utils.RUN_PYTHON_TESTS(
303         ['tests/python/api.py'],
304         extra_env={'SELFTEST_PREFIX': test_prefix})
305     print("Python testsuite returned %d" % pyret)
306     sys.exit(ret or pyret)
307
308 def dist():
309     '''makes a tarball for distribution'''
310     samba_dist.dist()
311
312 def reconfigure(ctx):
313     '''reconfigure if config scripts have changed'''
314     import samba_utils
315     samba_utils.reconfigure(ctx)