a0b92d57d60633fee18bd44f2681168f28303801
[metze/samba/wip.git] / source4 / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.0.2'
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('HAVE_CONFIG_H', 1, add_to_cflags=True)
60
61     # we don't want any libraries or modules to rely on runtime
62     # resolution of symbols
63     if sys.platform != "openbsd4":
64         conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
65
66     conf.SAMBA_CONFIG_H()
67
68 def build(bld):
69     bld.RECURSE('lib/tdb')
70     bld.RECURSE('lib/tevent')
71     bld.RECURSE('lib/popt')
72     bld.RECURSE('lib/replace')
73
74     if bld.env.standalone_ldb:
75         private_library = False
76     else:
77         private_library = True
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     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
88                      init_function='ldb_ldap_init',
89                      module_init_name='ldb_init_module',
90                      deps='talloc lber ldap ldb',
91                      enabled=bld.env.ENABLE_LDAP_BACKEND,
92                      internal_module=False,
93                      subsystem='ldb')
94
95     # we're not currently linking against the ldap libs, but ldb.pc.in
96     # has @LDAP_LIBS@
97     bld.env.LDAP_LIBS = ''
98
99     if not 'PACKAGE_VERSION' in bld.env:
100         bld.env.PACKAGE_VERSION = VERSION
101         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
102
103     if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
104         bld.SAMBA_LIBRARY('pyldb-util',
105                           deps='ldb pytalloc-util',
106                           source='pyldb_util.c',
107                           public_headers='pyldb.h',
108                           vnum=VERSION,
109                           private_library=private_library,
110                           pc_files='pyldb-util.pc',
111                           pyext=True)
112
113     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
114         if Options.is_install:
115             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
116         else:
117             # when we run from the source directory, we want to use
118             # the current modules, not the installed ones
119             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
120
121         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
122
123         bld.SAMBA_LIBRARY('ldb',
124                           COMMON_SRC + ' ' + LDB_MAP_SRC,
125                           deps='tevent LIBLDB_MAIN',
126                           includes='include',
127                           public_headers='include/ldb.h include/ldb_errors.h '\
128                           'include/ldb_module.h include/ldb_handlers.h',
129                           pc_files='ldb.pc',
130                           vnum=VERSION,
131                           private_library=private_library,
132                           manpages='man/ldb.3',
133                           abi_directory = 'ABI',
134                           abi_match = abi_match)
135
136         # generate a include/ldb_version.h
137         t = bld.SAMBA_GENERATOR('ldb_version.h',
138                                 rule='echo "#define LDB_VERSION \\"${LDB_VERSION}\\"" > ${TGT}',
139                                 target='include/ldb_version.h',
140                                 public_headers='include/ldb_version.h')
141         t.env.LDB_VERSION = VERSION
142         bld.add_manual_dependency(bld.path.find_or_declare('include/ldb_version.h'), VERSION)
143
144
145
146         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
147                          deps='ldb pyldb-util',
148                          realname='ldb.so',
149                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
150
151         bld.SAMBA_MODULE('ldb_paged_results',
152                          'modules/paged_results.c',
153                          init_function='ldb_paged_results_init',
154                          module_init_name='ldb_init_module',
155                          internal_module=False,
156                          deps='ldb',
157                          subsystem='ldb')
158
159         bld.SAMBA_MODULE('ldb_asq',
160                          'modules/asq.c',
161                          init_function='ldb_asq_init',
162                          module_init_name='ldb_init_module',
163                          internal_module=False,
164                          deps='ldb',
165                          subsystem='ldb')
166
167         bld.SAMBA_MODULE('ldb_server_sort',
168                          'modules/sort.c',
169                          init_function='ldb_server_sort_init',
170                          internal_module=False,
171                          module_init_name='ldb_init_module',
172                          deps='ldb',
173                          subsystem='ldb')
174
175         bld.SAMBA_MODULE('ldb_paged_searches',
176                          'modules/paged_searches.c',
177                          init_function='ldb_paged_searches_init',
178                          internal_module=False,
179                          module_init_name='ldb_init_module',
180                          deps='ldb',
181                          subsystem='ldb')
182
183         bld.SAMBA_MODULE('ldb_rdn_name',
184                          'modules/rdn_name.c',
185                          init_function='ldb_rdn_name_init',
186                          internal_module=False,
187                          module_init_name='ldb_init_module',
188                          deps='ldb',
189                          subsystem='ldb')
190
191         bld.SAMBA_MODULE('ldb_sample',
192                          'tests/sample_module.c',
193                          init_function='ldb_sample_init',
194                          internal_module=False,
195                          module_init_name='ldb_init_module',
196                          deps='ldb',
197                          subsystem='ldb')
198
199         bld.SAMBA_MODULE('ldb_skel',
200                          'modules/skel.c',
201                          init_function='ldb_skel_init',
202                          internal_module=False,
203                          module_init_name='ldb_init_module',
204                          deps='ldb',
205                          subsystem='ldb')
206
207         bld.SAMBA_MODULE('ldb_sqlite3',
208                          'sqlite3/ldb_sqlite3.c',
209                          init_function='ldb_sqlite3_init',
210                          internal_module=False,
211                          module_init_name='ldb_init_module',
212                          enabled=False,
213                          deps='ldb',
214                          subsystem='ldb')
215
216         bld.SAMBA_MODULE('ldb_tdb',
217                          bld.SUBDIR('ldb_tdb',
218                                     '''ldb_tdb.c ldb_pack.c ldb_search.c ldb_index.c
219                                     ldb_cache.c ldb_tdb_wrap.c'''),
220                          init_function='ldb_tdb_init',
221                          module_init_name='ldb_init_module',
222                          internal_module=False,
223                          deps='tdb ldb',
224                          subsystem='ldb')
225
226         # have a separate subsystem for common/ldb.c, so it can rebuild
227         # for install with a different -DLDB_MODULESDIR=
228         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
229                             'common/ldb.c',
230                             deps='tevent',
231                             includes='include',
232                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
233
234         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
235         for t in LDB_TOOLS.split():
236             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
237                              manpages='man/%s.1' % t)
238
239         # ldbtest doesn't get installed
240         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
241                          install=False)
242
243     bld.SAMBA_LIBRARY('ldb-cmdline',
244                       source='tools/ldbutil.c tools/cmdline.c',
245                       deps='ldb dl popt',
246                       private_library=True)
247
248
249 def test(ctx):
250     '''run ldb testsuite'''
251     import Utils, samba_utils, shutil
252     test_prefix = "%s/st" % (Utils.g_module.blddir)
253     shutil.rmtree(test_prefix, ignore_errors=True)
254     os.makedirs(test_prefix)
255     os.putenv('TEST_DATA_PREFIX', test_prefix)
256     cmd = 'tests/test-tdb.sh'
257     ret = samba_utils.RUN_COMMAND(cmd)
258     print("testsuite returned %d" % ret)
259     # FIXME: Run python testsuite
260     sys.exit(ret)
261
262 def dist():
263     '''makes a tarball for distribution'''
264     samba_dist.dist()
265
266 def reconfigure(ctx):
267     '''reconfigure if config scripts have changed'''
268     import samba_utils
269     samba_utils.reconfigure(ctx)