Don't build ldb tools when there is a system provided ldb.
[abartlet/samba.git/.git] / source4 / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '0.9.19'
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     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
41
42     if not conf.env.standalone_ldb:
43         if conf.CHECK_BUNDLED_SYSTEM('ldb', minversion=VERSION,
44                                      onlyif='talloc tdb tevent',
45                                      implied_deps='replace talloc tdb tevent'):
46             conf.define('USING_SYSTEM_LDB', 1)
47         if conf.CHECK_BUNDLED_SYSTEM('pyldb-util', minversion=VERSION,
48                                      onlyif='talloc tdb tevent ldb',
49                                      implied_deps='replace talloc tdb tevent ldb'):
50             conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
51
52     if conf.env.standalone_ldb:
53         conf.CHECK_XSLTPROC_MANPAGES()
54
55         # we need this for the ldap backend
56         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
57             conf.env.ENABLE_LDAP_BACKEND = True
58
59     conf.DEFINE('LDB_VERSION', VERSION, quote=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     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
76                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
77
78     COMMON_SRC = bld.SUBDIR('common',
79                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
80                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c
81                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
82
83     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
84                      init_function='ldb_ldap_init',
85                      module_init_name='ldb_init_module',
86                      deps='talloc lber ldap ldb',
87                      enabled=bld.env.ENABLE_LDAP_BACKEND,
88                      internal_module=False,
89                      subsystem='ldb')
90
91     # we're not currently linking against the ldap libs, but ldb.pc.in
92     # has @LDAP_LIBS@
93     bld.env.LDAP_LIBS = ''
94
95     if not 'PACKAGE_VERSION' in bld.env:
96         bld.env.PACKAGE_VERSION = VERSION
97         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
98
99     if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
100         bld.SAMBA_LIBRARY('pyldb-util',
101                           deps='ldb',
102                           source='pyldb_util.c',
103                           public_headers='pyldb.h',
104                           vnum=VERSION,
105                           pc_files='pyldb-util.pc',
106                           pyext=True)
107
108     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
109         if Options.is_install:
110             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
111         else:
112             # when we run from the source directory, we want to use
113             # the current modules, not the installed ones
114             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
115
116         abi_file = 'ABI/ldb-%s.sigs' % VERSION
117         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
118
119         bld.SAMBA_LIBRARY('ldb',
120                           COMMON_SRC + ' ' + LDB_MAP_SRC,
121                           deps='tevent LIBLDB_MAIN',
122                           includes='include',
123                           public_headers='include/ldb.h include/ldb_errors.h '\
124                           'include/ldb_module.h include/ldb_handlers.h',
125                           pc_files='ldb.pc',
126                           vnum=VERSION,
127                           manpages='man/ldb.3',
128                           abi_file = abi_file,
129                          abi_match = abi_match)
130
131
132         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
133                          deps='ldb pyldb-util',
134                          realname='ldb.so',
135                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
136
137         bld.SAMBA_MODULE('ldb_paged_results',
138                          'modules/paged_results.c',
139                          init_function='ldb_paged_results_init',
140                          module_init_name='ldb_init_module',
141                          deps='ldb',
142                          subsystem='ldb')
143
144         bld.SAMBA_MODULE('ldb_asq',
145                          'modules/asq.c',
146                          init_function='ldb_asq_init',
147                          module_init_name='ldb_init_module',
148                          deps='ldb',
149                          subsystem='ldb')
150
151         bld.SAMBA_MODULE('ldb_server_sort',
152                          'modules/sort.c',
153                          init_function='ldb_server_sort_init',
154                          module_init_name='ldb_init_module',
155                          deps='ldb',
156                          subsystem='ldb')
157
158         bld.SAMBA_MODULE('ldb_paged_searches',
159                          'modules/paged_searches.c',
160                          init_function='ldb_paged_searches_init',
161                          module_init_name='ldb_init_module',
162                          deps='ldb',
163                          subsystem='ldb')
164
165         bld.SAMBA_MODULE('ldb_rdn_name',
166                          'modules/rdn_name.c',
167                          init_function='ldb_rdn_name_init',
168                          module_init_name='ldb_init_module',
169                          deps='ldb',
170                          subsystem='ldb')
171
172         bld.SAMBA_MODULE('ldb_sample',
173                          'tests/sample_module.c',
174                          init_function='ldb_sample_init',
175                          module_init_name='ldb_init_module',
176                          deps='ldb',
177                          subsystem='ldb')
178
179         bld.SAMBA_MODULE('ldb_skel',
180                          'modules/skel.c',
181                          init_function='ldb_skel_init',
182                          module_init_name='ldb_init_module',
183                          deps='ldb',
184                          subsystem='ldb')
185
186         bld.SAMBA_MODULE('ldb_sqlite3',
187                          'sqlite3/ldb_sqlite3.c',
188                          init_function='ldb_sqlite3_init',
189                          module_init_name='ldb_init_module',
190                          enabled=False,
191                          deps='ldb',
192                          subsystem='ldb')
193
194         bld.SAMBA_MODULE('ldb_tdb',
195                          bld.SUBDIR('ldb_tdb',
196                                     '''ldb_tdb.c ldb_pack.c ldb_search.c ldb_index.c
197                                     ldb_cache.c ldb_tdb_wrap.c'''),
198                          init_function='ldb_tdb_init',
199                          module_init_name='ldb_init_module',
200                          deps='tdb ldb',
201                          subsystem='ldb')
202
203         # have a separate subsystem for common/ldb.c, so it can rebuild
204         # for install with a different -DLDB_MODULESDIR=
205         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
206                             'common/ldb.c',
207                             deps='tevent',
208                             includes='include',
209                             cflags='-DLDB_MODULESDIR=\"%s\"' % modules_dir)
210
211         bld.SAMBA_LIBRARY('ldb-cmdline',
212                           source='tools/ldbutil.c tools/cmdline.c',
213                           deps='ldb dl popt',
214                           private_library=True)
215
216         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
217         for t in LDB_TOOLS.split():
218             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
219                              manpages='man/%s.1' % t)
220
221         # ldbtest doesn't get installed
222         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
223                          install=False)
224
225
226 def test(ctx):
227     '''run ldb testsuite'''
228     import Utils, samba_utils
229     cmd = 'tests/test-tdb.sh'
230     ret = samba_utils.RUN_COMMAND(cmd)
231     print("testsuite returned %d" % ret)
232     sys.exit(ret)
233
234 def dist():
235     '''makes a tarball for distribution'''
236     samba_dist.dist()
237
238 def reconfigure(ctx):
239     '''reconfigure if config scripts have changed'''
240     import samba_utils
241     samba_utils.reconfigure(ctx)