81d2adcfd3935fe2d76f9894f21dc2e1884b9a43
[samba.git] / source4 / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '0.9.24'
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     if sys.platform != "openbsd4":
66         conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
67
68     conf.SAMBA_CONFIG_H()
69
70 def build(bld):
71     bld.RECURSE('lib/tdb')
72     bld.RECURSE('lib/tevent')
73     bld.RECURSE('lib/popt')
74     bld.RECURSE('lib/replace')
75
76     if bld.env.standalone_ldb:
77         private_library = False
78     else:
79         private_library = True
80
81     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
82                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
83
84     COMMON_SRC = bld.SUBDIR('common',
85                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
86                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c
87                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
88
89     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
90                      init_function='ldb_ldap_init',
91                      module_init_name='ldb_init_module',
92                      deps='talloc lber ldap ldb',
93                      enabled=bld.env.ENABLE_LDAP_BACKEND,
94                      internal_module=False,
95                      subsystem='ldb')
96
97     # we're not currently linking against the ldap libs, but ldb.pc.in
98     # has @LDAP_LIBS@
99     bld.env.LDAP_LIBS = ''
100
101     if not 'PACKAGE_VERSION' in bld.env:
102         bld.env.PACKAGE_VERSION = VERSION
103         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
104
105     if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
106         bld.SAMBA_LIBRARY('pyldb-util',
107                           deps='ldb pytalloc-util',
108                           source='pyldb_util.c',
109                           public_headers='pyldb.h',
110                           vnum=VERSION,
111                           private_library=private_library,
112                           pc_files='pyldb-util.pc',
113                           pyext=True)
114
115     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
116         if Options.is_install:
117             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
118         else:
119             # when we run from the source directory, we want to use
120             # the current modules, not the installed ones
121             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
122
123         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
124
125         bld.SAMBA_LIBRARY('ldb',
126                           COMMON_SRC + ' ' + LDB_MAP_SRC,
127                           deps='tevent LIBLDB_MAIN',
128                           includes='include',
129                           public_headers='include/ldb.h include/ldb_errors.h '\
130                           'include/ldb_module.h include/ldb_handlers.h',
131                           pc_files='ldb.pc',
132                           vnum=VERSION,
133                           private_library=private_library,
134                           manpages='man/ldb.3',
135                           abi_directory = 'ABI',
136                           abi_match = abi_match)
137
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_paged_results_init',
147                          module_init_name='ldb_init_module',
148                          internal_module=False,
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                          internal_module=False,
157                          deps='ldb',
158                          subsystem='ldb')
159
160         bld.SAMBA_MODULE('ldb_server_sort',
161                          'modules/sort.c',
162                          init_function='ldb_server_sort_init',
163                          internal_module=False,
164                          module_init_name='ldb_init_module',
165                          deps='ldb',
166                          subsystem='ldb')
167
168         bld.SAMBA_MODULE('ldb_paged_searches',
169                          'modules/paged_searches.c',
170                          init_function='ldb_paged_searches_init',
171                          internal_module=False,
172                          module_init_name='ldb_init_module',
173                          deps='ldb',
174                          subsystem='ldb')
175
176         bld.SAMBA_MODULE('ldb_rdn_name',
177                          'modules/rdn_name.c',
178                          init_function='ldb_rdn_name_init',
179                          internal_module=False,
180                          module_init_name='ldb_init_module',
181                          deps='ldb',
182                          subsystem='ldb')
183
184         bld.SAMBA_MODULE('ldb_sample',
185                          'tests/sample_module.c',
186                          init_function='ldb_sample_init',
187                          internal_module=False,
188                          module_init_name='ldb_init_module',
189                          deps='ldb',
190                          subsystem='ldb')
191
192         bld.SAMBA_MODULE('ldb_skel',
193                          'modules/skel.c',
194                          init_function='ldb_skel_init',
195                          internal_module=False,
196                          module_init_name='ldb_init_module',
197                          deps='ldb',
198                          subsystem='ldb')
199
200         bld.SAMBA_MODULE('ldb_sqlite3',
201                          'sqlite3/ldb_sqlite3.c',
202                          init_function='ldb_sqlite3_init',
203                          internal_module=False,
204                          module_init_name='ldb_init_module',
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_tdb_init',
214                          module_init_name='ldb_init_module',
215                          internal_module=False,
216                          deps='tdb ldb',
217                          subsystem='ldb')
218
219         # have a separate subsystem for common/ldb.c, so it can rebuild
220         # for install with a different -DLDB_MODULESDIR=
221         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
222                             'common/ldb.c',
223                             deps='tevent',
224                             includes='include',
225                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
226
227         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
228         for t in LDB_TOOLS.split():
229             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
230                              manpages='man/%s.1' % t)
231
232         # ldbtest doesn't get installed
233         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
234                          install=False)
235
236     bld.SAMBA_LIBRARY('ldb-cmdline',
237                       source='tools/ldbutil.c tools/cmdline.c',
238                       deps='ldb dl popt',
239                       private_library=True)
240
241
242 def test(ctx):
243     '''run ldb testsuite'''
244     import Utils, samba_utils, shutil
245     test_prefix = "%s/st" % (Utils.g_module.blddir)
246     shutil.rmtree(test_prefix, ignore_errors=True)
247     os.makedirs(test_prefix)
248     os.putenv('TEST_DATA_PREFIX', test_prefix)
249     cmd = 'tests/test-tdb.sh'
250     ret = samba_utils.RUN_COMMAND(cmd)
251     print("testsuite returned %d" % ret)
252     # FIXME: Run python testsuite
253     sys.exit(ret)
254
255 def dist():
256     '''makes a tarball for distribution'''
257     samba_dist.dist()
258
259 def reconfigure(ctx):
260     '''reconfigure if config scripts have changed'''
261     import samba_utils
262     samba_utils.reconfigure(ctx)