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