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