third_party/popt: Initial support for popt.
[sfrench/samba-autobuild/.git] / lib / ldb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ldb'
4 VERSION = '1.1.17'
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('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
19                         lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
20                         third_party/popt:third_party/popt
21                         buildtools:buildtools''')
22
23
24 def set_options(opt):
25     opt.BUILTIN_DEFAULT('replace')
26     opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
27     opt.RECURSE('lib/tdb')
28     opt.RECURSE('lib/tevent')
29     opt.RECURSE('lib/replace')
30     opt.tool_options('python') # options for disabling pyc or pyo compilation
31
32 def configure(conf):
33     conf.RECURSE('lib/tdb')
34     conf.RECURSE('lib/tevent')
35
36     if conf.CHECK_FOR_THIRD_PARTY():
37         conf.RECURSE('third_party/popt')
38     else:
39         if not conf.CHECK_POPT():
40             raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
41         else:
42             conf.define('USING_SYSTEM_POPT', 1)
43
44     conf.RECURSE('lib/replace')
45     conf.find_program('python', var='PYTHON')
46     conf.find_program('xsltproc', var='XSLTPROC')
47     conf.check_tool('python')
48     conf.check_python_version((2,4,2))
49     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
50
51     # where does the default LIBDIR end up? in conf.env somewhere?
52     #
53     conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
54
55     conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
56
57     if not conf.env.standalone_ldb:
58         if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
59                                      onlyif='talloc tdb tevent',
60                                      implied_deps='replace talloc tdb tevent'):
61             conf.define('USING_SYSTEM_LDB', 1)
62         if conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
63                                      onlyif='talloc tdb tevent ldb',
64                                      implied_deps='replace talloc tdb tevent ldb'):
65             conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
66
67     if conf.env.standalone_ldb:
68         conf.CHECK_XSLTPROC_MANPAGES()
69
70         # we need this for the ldap backend
71         if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
72             conf.env.ENABLE_LDAP_BACKEND = True
73
74         # we don't want any libraries or modules to rely on runtime
75         # resolution of symbols
76         if not sys.platform.startswith("openbsd"):
77             conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
78
79     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
80
81     conf.SAMBA_CONFIG_H()
82
83     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
84
85 def build(bld):
86     bld.RECURSE('lib/tevent')
87
88     if os.path.exists('third_party'):
89         bld.RECURSE('third_party/popt')
90
91     bld.RECURSE('lib/replace')
92     bld.RECURSE('lib/tdb')
93
94     if bld.env.standalone_ldb:
95         private_library = False
96     else:
97         private_library = True
98
99     LDB_MAP_SRC = bld.SUBDIR('ldb_map',
100                              'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
101
102     COMMON_SRC = bld.SUBDIR('common',
103                             '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
104                             ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
105                             ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
106
107     bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
108                      init_function='ldb_ldap_init',
109                      module_init_name='ldb_init_module',
110                      deps='talloc lber ldap ldb',
111                      enabled=bld.env.ENABLE_LDAP_BACKEND,
112                      internal_module=False,
113                      subsystem='ldb')
114
115     # we're not currently linking against the ldap libs, but ldb.pc.in
116     # has @LDAP_LIBS@
117     bld.env.LDAP_LIBS = ''
118
119     if not 'PACKAGE_VERSION' in bld.env:
120         bld.env.PACKAGE_VERSION = VERSION
121         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
122
123     if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
124         bld.SAMBA_LIBRARY('pyldb-util',
125                           deps='ldb',
126                           source='pyldb_util.c',
127                           public_headers='pyldb.h',
128                           public_headers_install=not private_library,
129                           vnum=VERSION,
130                           private_library=private_library,
131                           pc_files='pyldb-util.pc',
132                           pyembed=True,
133                           abi_directory='ABI',
134                           abi_match='pyldb_*')
135
136     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
137         if Options.is_install:
138             modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
139         else:
140             # when we run from the source directory, we want to use
141             # the current modules, not the installed ones
142             modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
143
144         abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
145
146         bld.SAMBA_LIBRARY('ldb',
147                           COMMON_SRC + ' ' + LDB_MAP_SRC,
148                           deps='tevent LIBLDB_MAIN replace',
149                           includes='include',
150                           public_headers='include/ldb.h include/ldb_errors.h '\
151                           'include/ldb_module.h include/ldb_handlers.h',
152                           public_headers_install=not private_library,
153                           pc_files='ldb.pc',
154                           vnum=VERSION,
155                           private_library=private_library,
156                           allow_warnings=True,
157                           manpages='man/ldb.3',
158                           abi_directory='ABI',
159                           abi_match = abi_match)
160
161         # generate a include/ldb_version.h
162         t = bld.SAMBA_GENERATOR('ldb_version.h',
163                                 rule='echo "#define LDB_VERSION \\"${LDB_VERSION}\\"" > ${TGT}',
164                                 target='include/ldb_version.h',
165                                 public_headers='include/ldb_version.h',
166                                 public_headers_install=not private_library)
167         t.env.LDB_VERSION = VERSION
168         bld.add_manual_dependency(bld.path.find_or_declare('include/ldb_version.h'), VERSION)
169
170
171
172         bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
173                          deps='ldb pyldb-util',
174                          realname='ldb.so',
175                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
176
177         bld.SAMBA_MODULE('ldb_paged_results',
178                          'modules/paged_results.c',
179                          init_function='ldb_paged_results_init',
180                          module_init_name='ldb_init_module',
181                          internal_module=False,
182                          deps='ldb',
183                          subsystem='ldb')
184
185         bld.SAMBA_MODULE('ldb_asq',
186                          'modules/asq.c',
187                          init_function='ldb_asq_init',
188                          module_init_name='ldb_init_module',
189                          internal_module=False,
190                          deps='ldb',
191                          subsystem='ldb')
192
193         bld.SAMBA_MODULE('ldb_server_sort',
194                          'modules/sort.c',
195                          init_function='ldb_server_sort_init',
196                          internal_module=False,
197                          module_init_name='ldb_init_module',
198                          deps='ldb',
199                          subsystem='ldb')
200
201         bld.SAMBA_MODULE('ldb_paged_searches',
202                          'modules/paged_searches.c',
203                          init_function='ldb_paged_searches_init',
204                          internal_module=False,
205                          module_init_name='ldb_init_module',
206                          deps='ldb',
207                          subsystem='ldb')
208
209         bld.SAMBA_MODULE('ldb_rdn_name',
210                          'modules/rdn_name.c',
211                          init_function='ldb_rdn_name_init',
212                          internal_module=False,
213                          module_init_name='ldb_init_module',
214                          deps='ldb',
215                          subsystem='ldb')
216
217         bld.SAMBA_MODULE('ldb_sample',
218                          'tests/sample_module.c',
219                          init_function='ldb_sample_init',
220                          internal_module=False,
221                          allow_warnings=True,
222                          module_init_name='ldb_init_module',
223                          deps='ldb',
224                          subsystem='ldb')
225
226         bld.SAMBA_MODULE('ldb_skel',
227                          'modules/skel.c',
228                          init_function='ldb_skel_init',
229                          internal_module=False,
230                          module_init_name='ldb_init_module',
231                          deps='ldb',
232                          subsystem='ldb')
233
234         bld.SAMBA_MODULE('ldb_sqlite3',
235                          'sqlite3/ldb_sqlite3.c',
236                          init_function='ldb_sqlite3_init',
237                          internal_module=False,
238                          module_init_name='ldb_init_module',
239                          enabled=False,
240                          deps='ldb',
241                          subsystem='ldb')
242
243         bld.SAMBA_MODULE('ldb_tdb',
244                          bld.SUBDIR('ldb_tdb',
245                                     '''ldb_tdb.c ldb_search.c ldb_index.c
246                                     ldb_cache.c ldb_tdb_wrap.c'''),
247                          init_function='ldb_tdb_init',
248                          module_init_name='ldb_init_module',
249                          internal_module=False,
250                          deps='tdb ldb',
251                          subsystem='ldb')
252
253         # have a separate subsystem for common/ldb.c, so it can rebuild
254         # for install with a different -DLDB_MODULESDIR=
255         bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
256                             'common/ldb.c',
257                             deps='tevent tdb',
258                             includes='include',
259                             allow_warnings=True,
260                             cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
261
262         LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
263         for t in LDB_TOOLS.split():
264             bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
265                              manpages='man/%s.1' % t)
266
267         # ldbtest doesn't get installed
268         bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
269                          install=False)
270
271         # ldbdump doesn't get installed
272         bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
273                          install=False)
274
275         bld.SAMBA_LIBRARY('ldb-cmdline',
276                           source='tools/ldbutil.c tools/cmdline.c',
277                           deps='ldb dl popt',
278                           private_library=True)
279
280
281 def test(ctx):
282     '''run ldb testsuite'''
283     import Utils, samba_utils, shutil
284     test_prefix = "%s/st" % (Utils.g_module.blddir)
285     shutil.rmtree(test_prefix, ignore_errors=True)
286     os.makedirs(test_prefix)
287     os.environ['TEST_DATA_PREFIX'] = test_prefix
288     cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
289     ret = samba_utils.RUN_COMMAND(cmd)
290     print("testsuite returned %d" % ret)
291     # FIXME: Run python testsuite
292     sys.exit(ret)
293
294 def dist():
295     '''makes a tarball for distribution'''
296     samba_dist.dist()
297
298 def reconfigure(ctx):
299     '''reconfigure if config scripts have changed'''
300     import samba_utils
301     samba_utils.reconfigure(ctx)