s4-ldb: convert the openldap ldb backend to the new style of module
[nivanova/samba-autobuild/.git] / source4 / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '0.9.18'
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
17
18 samba_dist.DIST_DIRS('''source4/lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
19                         lib/tdb:lib/tdb lib/tevent:lib/tevent lib/popt:lib/popt
20                         buildtools:buildtools''')
21
22
23 def set_options(opt):
24     opt.BUILTIN_DEFAULT('replace')
25     opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
26     opt.RECURSE('lib/tdb')
27     opt.RECURSE('lib/tevent')
28     opt.RECURSE('lib/replace')
29
30 def configure(conf):
31     conf.RECURSE('lib/tdb')
32     conf.RECURSE('lib/tevent')
33     conf.RECURSE('lib/popt')
34     conf.RECURSE('lib/replace')
35
36     # where does the default LIBDIR end up? in conf.env somewhere?
37     #
38     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
39
40     s4_build = getattr(conf.env, '_SAMBA_BUILD_', 0) == 4
41
42     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
43
44     if not conf.env.standalone_ldb:
45         if conf.CHECK_BUNDLED_SYSTEM('ldb', minversion=VERSION,
46                                      onlyif='talloc tdb tevent',
47                                      implied_deps='replace talloc tdb tevent'):
48             conf.define('USING_SYSTEM_LDB', 1)
49         if conf.CHECK_BUNDLED_SYSTEM('pyldb-util', minversion=VERSION,
50                                      onlyif='talloc tdb tevent ldb',
51                                      implied_deps='replace talloc tdb tevent ldb'):
52             conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
53
54     if conf.env.standalone_ldb:
55         conf.CHECK_XSLTPROC_MANPAGES()
56
57         # we need this for the ldap backend
58         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
59             conf.env.ENABLE_LDAP_BACKEND = True
60
61     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
62
63     # we don't want any libraries or modules to rely on runtime
64     # resolution of symbols
65     conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
66
67     conf.SAMBA_CONFIG_H()
68
69 def build(bld):
70     bld.RECURSE('lib/tdb')
71     bld.RECURSE('lib/tevent')
72     bld.RECURSE('lib/popt')
73     bld.RECURSE('lib/replace')
74
75     # in Samba4 we build some extra modules, and add extra
76     # capabilities to the ldb cmdline tools
77     s4_build = getattr(bld.env, '_SAMBA_BUILD_', 0) == 4
78
79     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
80                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
81
82     COMMON_SRC = bld.SUBDIR('common',
83                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
84                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c
85                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
86
87     if s4_build:
88         # this is only in the s4 build
89         bld.SAMBA_MODULE('ldb_ildap', 'ldb_ildap/ldb_ildap.c',
90                          init_function='ldb_ildap_init',
91                          module_init_name='ldb_init_module',
92                          deps='talloc cli-ldap CREDENTIALS auth_system_session',
93                          internal_module=False,
94                          subsystem='ldb')
95     else:
96         # this is not included in the s4 build
97         bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
98                          init_function='ldb_ldap_init',
99                          module_init_name='ldb_init_module',
100                          deps='talloc lber ldap',
101                          enabled=bld.env.ENABLE_LDAP_BACKEND,
102                          internal_module=False,
103                          subsystem='ldb')
104
105     # we're not currently linking against the ldap libs, but ldb.pc.in
106     # has @LDAP_LIBS@
107     bld.env.LDAP_LIBS = ''
108
109     if not 'PACKAGE_VERSION' in bld.env:
110         bld.env.PACKAGE_VERSION = VERSION
111         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
112
113     if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
114         bld.SAMBA_LIBRARY('pyldb-util',
115                           deps='ldb',
116                           source='pyldb_util.c',
117                           public_headers='pyldb.h',
118                           vnum=VERSION,
119                           pc_files='pyldb-util.pc',
120                           pyext=True)
121
122     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
123         if Options.is_install:
124             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
125         else:
126             # when we run from the source directory, we want to use
127             # the current modules, not the installed ones
128             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
129
130         if bld.env.standalone_ldb:
131             # do ABI checking on the standalone ldb
132             abi_file = 'ABI/ldb-%s.sigs' % VERSION
133             abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
134             private_library = False
135             vnum = VERSION
136         else:
137             abi_file = None
138             abi_match = None
139             private_library = True
140             vnum = None
141
142         bld.SAMBA_LIBRARY('ldb',
143                           COMMON_SRC + ' ' + LDB_MAP_SRC,
144                           deps='tevent LIBLDB_MAIN',
145                           includes='include',
146                           public_headers='include/ldb.h include/ldb_errors.h '\
147                           'include/ldb_module.h include/ldb_handlers.h',
148                           pc_files='ldb.pc',
149                           vnum=vnum, manpages='man/ldb.3',
150                           abi_file = abi_file,
151                           abi_match = abi_match,
152                           private_library=private_library)
153
154         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
155                          deps='ldb pyldb-util',
156                          realname='ldb.so',
157                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
158
159         bld.SAMBA_MODULE('ldb_paged_results',
160                          'modules/paged_results.c',
161                          init_function='LDB_MODULE(paged_results)',
162                          deps='ldb',
163                          subsystem='ldb')
164
165         bld.SAMBA_MODULE('ldb_asq',
166                          'modules/asq.c',
167                          init_function='LDB_MODULE(asq)',
168                          deps='ldb',
169                          subsystem='ldb')
170
171         bld.SAMBA_MODULE('ldb_server_sort',
172                          'modules/sort.c',
173                          init_function='LDB_MODULE(server_sort)',
174                          deps='ldb',
175                          subsystem='ldb')
176
177         bld.SAMBA_MODULE('ldb_paged_searches',
178                          'modules/paged_searches.c',
179                          init_function='LDB_MODULE(paged_searches)',
180                          enabled = s4_build,
181                          deps='ldb',
182                          subsystem='ldb')
183
184         bld.SAMBA_MODULE('ldb_rdn_name',
185                          'modules/rdn_name.c',
186                          init_function='LDB_MODULE(rdn_name)',
187                          deps='ldb',
188                          subsystem='ldb')
189
190         bld.SAMBA_MODULE('ldb_sample',
191                          'tests/sample_module.c',
192                          init_function='LDB_MODULE(sample)',
193                          deps='ldb',
194                          subsystem='ldb')
195
196         bld.SAMBA_MODULE('ldb_skel',
197                          'modules/skel.c',
198                          init_function='LDB_MODULE(skel)',
199                          deps='ldb',
200                          subsystem='ldb')
201
202         bld.SAMBA_MODULE('ldb_sqlite3',
203                          'sqlite3/ldb_sqlite3.c',
204                          init_function='LDB_BACKEND(sqlite3)',
205                          enabled=False,
206                          deps='ldb',
207                          subsystem='ldb')
208
209         bld.SAMBA_MODULE('ldb_tdb',
210                          bld.SUBDIR('ldb_tdb',
211                                     '''ldb_tdb.c ldb_pack.c ldb_search.c ldb_index.c
212                                     ldb_cache.c ldb_tdb_wrap.c'''),
213                          init_function='LDB_BACKEND(tdb)',
214                          deps='tdb ldb',
215                          subsystem='ldb')
216
217         # have a separate subsystem for common/ldb.c, so it can rebuild
218         # for install with a different -DLDB_MODULESDIR=
219         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
220                             'common/ldb.c',
221                             deps='tevent',
222                             includes='include',
223                             cflags='-DLDB_MODULESDIR=\"%s\" -DLDB_VERSION=\"%s\"' % (modules_dir, VERSION))
224
225     if s4_build:
226         extra_cmdline_deps = ' LDBSAMBA POPT_SAMBA POPT_CREDENTIALS ' \
227                 'cmdline-credentials gensec'
228     else:
229         extra_cmdline_deps = ''
230
231     bld.SAMBA_LIBRARY('ldb-cmdline',
232                       source='tools/ldbutil.c tools/cmdline.c',
233                       deps='ldb dl popt' + extra_cmdline_deps,
234                       private_library=True)
235
236     LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
237     for t in LDB_TOOLS.split():
238         bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
239                          manpages='man/%s.1' % t)
240
241     # ldbtest doesn't get installed
242     bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline',
243                      install=False)
244
245
246 def test(ctx):
247     '''run ldb testsuite'''
248     import Utils, samba_utils
249     cmd = 'tests/test-tdb.sh'
250     ret = samba_utils.RUN_COMMAND(cmd)
251     print("testsuite returned %d" % ret)
252     sys.exit(ret)
253
254 def dist():
255     '''makes a tarball for distribution'''
256     samba_dist.dist()