s4-ldb: make pyldb_util a private library
[abartlet/samba.git/.git] / source4 / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '0.9.16'
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.BUNDLED_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
50     if conf.env.standalone_ldb:
51         conf.CHECK_XSLTPROC_MANPAGES()
52
53         # we need this for the ldap backend
54         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
55             conf.env.ENABLE_LDAP_BACKEND = True
56
57     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
58
59     conf.SAMBA_CONFIG_H()
60
61 def build(bld):
62     bld.RECURSE('lib/tdb')
63     bld.RECURSE('lib/tevent')
64     bld.RECURSE('lib/popt')
65     bld.RECURSE('lib/replace')
66
67     # in Samba4 we build some extra modules, and add extra
68     # capabilities to the ldb cmdline tools
69     s4_build = getattr(bld.env, '_SAMBA_BUILD_', 0) == 4
70
71     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
72                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
73
74     COMMON_SRC = bld.SUBDIR('common',
75                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
76                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c
77                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
78
79     if s4_build:
80         # this is only in the s4 build
81         bld.SAMBA_MODULE('ldb_ildap', 'ldb_ildap/ldb_ildap.c',
82                          init_function='LDB_BACKEND(ldapi),LDB_BACKEND(ldaps),LDB_BACKEND(ldap)',
83                          deps='talloc LIBCLI_LDAP CREDENTIALS auth_system_session',
84                          aliases='ldb_ldaps ldb_ldapi ldb_ldap',
85                          internal_module=False,
86                          subsystem='ldb')
87     else:
88         # this is not included in the s4 build
89         bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
90                          init_function='LDB_BACKEND(ldapi),LDB_BACKEND(ldaps),LDB_BACKEND(ldap)',
91                          deps='talloc lber ldap',
92                          enabled=bld.env.ENABLE_LDAP_BACKEND,
93                          internal_module=False,
94                          subsystem='ldb')
95
96     # we're not currently linking against the ldap libs, but ldb.pc.in
97     # has @LDAP_LIBS@
98     bld.env.LDAP_LIBS = ''
99
100     if not 'PACKAGE_VERSION' in bld.env:
101         bld.env.PACKAGE_VERSION = VERSION
102         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
103
104
105     bld.SAMBA_LIBRARY('pyldb_util',
106                       deps='ldb',
107                       source='pyldb_util.c',
108                       pyext=True,
109                       private_library=True)
110
111     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
112         if Options.is_install:
113             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
114         else:
115             # when we run from the source directory, we want to use
116             # the current modules, not the installed ones
117             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
118
119         if bld.env.standalone_ldb:
120             # do ABI checking on the standalone ldb
121             abi_file = 'ABI/ldb-%s.sigs' % VERSION
122             abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
123         else:
124             abi_file = None
125             abi_match = None
126
127         bld.SAMBA_LIBRARY('ldb',
128                           COMMON_SRC + ' ' + LDB_MAP_SRC,
129                           deps='tevent LIBLDB_MAIN',
130                           includes='include',
131                           public_headers='include/ldb.h include/ldb_errors.h '\
132                           'include/ldb_module.h include/ldb_handlers.h',
133                           pc_files='ldb.pc',
134                           vnum=VERSION, manpages='man/ldb.3',
135                           abi_file = abi_file,
136                           abi_match = abi_match,
137                           private_library=not bld.env.standalone_ldb)
138
139         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
140                          deps='ldb pyldb_util',
141                          realname='ldb.so',
142                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
143
144         bld.SAMBA_MODULE('ldb_paged_results',
145                          'modules/paged_results.c',
146                          init_function='LDB_MODULE(paged_results)',
147                          subsystem='ldb')
148
149         bld.SAMBA_MODULE('ldb_asq',
150                          'modules/asq.c',
151                          init_function='LDB_MODULE(asq)',
152                          subsystem='ldb')
153
154         bld.SAMBA_MODULE('ldb_server_sort',
155                          'modules/sort.c',
156                          init_function='LDB_MODULE(server_sort)',
157                          subsystem='ldb')
158
159         bld.SAMBA_MODULE('ldb_paged_searches',
160                          'modules/paged_searches.c',
161                          init_function='LDB_MODULE(paged_searches)',
162                          enabled = s4_build,
163                          subsystem='ldb')
164
165         bld.SAMBA_MODULE('ldb_rdn_name',
166                          'modules/rdn_name.c',
167                          init_function='LDB_MODULE(rdn_name)',
168                          subsystem='ldb')
169
170         bld.SAMBA_MODULE('ldb_sample',
171                          'tests/sample_module.c',
172                          init_function='LDB_MODULE(sample)',
173                          subsystem='ldb')
174
175         bld.SAMBA_MODULE('ldb_skel',
176                          'modules/skel.c',
177                          init_function='LDB_MODULE(skel)',
178                          subsystem='ldb')
179
180         bld.SAMBA_MODULE('ldb_sqlite3',
181                          'sqlite3/ldb_sqlite3.c',
182                          init_function='LDB_BACKEND(sqlite3)',
183                          enabled=False,
184                          subsystem='ldb')
185
186         bld.SAMBA_MODULE('ldb_tdb',
187                          bld.SUBDIR('ldb_tdb',
188                                     '''ldb_tdb.c ldb_pack.c ldb_search.c ldb_index.c
189                                     ldb_cache.c ldb_tdb_wrap.c'''),
190                          init_function='LDB_BACKEND(tdb)',
191                          deps='tdb',
192                          subsystem='ldb')
193
194         # have a separate subsystem for common/ldb.c, so it can rebuild
195         # for install with a different -DLDB_MODULESDIR=
196         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
197                             'common/ldb.c',
198                             deps='tevent',
199                             includes='include',
200                             cflags='-DLDB_MODULESDIR=\"%s\"' % modules_dir)
201
202     if s4_build:
203         extra_cmdline_deps = ' LDBSAMBA POPT_SAMBA POPT_CREDENTIALS ' \
204                 'LIBCMDLINE_CREDENTIALS gensec'
205     else:
206         extra_cmdline_deps = ''
207
208     bld.SAMBA_SUBSYSTEM('LIBLDB_CMDLINE',
209                         'tools/ldbutil.c tools/cmdline.c',
210                         'ldb dl popt' + extra_cmdline_deps)
211
212     LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
213     for t in LDB_TOOLS.split():
214         bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='LIBLDB_CMDLINE',
215                          manpages='man/%s.1' % t)
216
217     # ldbtest doesn't get installed
218     bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='LIBLDB_CMDLINE',
219                      install=False)
220
221
222 def test(ctx):
223     '''run ldb testsuite'''
224     import Utils, samba_utils
225     cmd = 'tests/test-tdb.sh'
226     ret = samba_utils.RUN_COMMAND(cmd)
227     print("testsuite returned %d" % ret)
228     sys.exit(ret)
229
230 def dist():
231     '''makes a tarball for distribution'''
232     samba_dist.dist()