s3:include: remove typedef user_struct
[Samba/gebeck_regimport.git] / lib / tdb2 / wscript
blob63d27fecc8c170ab0d6f2acae794b0c6304224ad
1 #!/usr/bin/env python
3 APPNAME = 'tdb'
4 VERSION = '2.0.0'
6 blddir = 'bin'
8 import sys, os
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')
16 import wafsamba, samba_dist, Options, Logs, glob
18 samba_dist.DIST_DIRS('lib/tdb2:. lib/replace:lib/replace lib/ccan:lib/ccan buildtools:buildtools')
20 def set_options(opt):
21 opt.BUILTIN_DEFAULT('replace,ccan')
22 opt.PRIVATE_EXTENSION_DEFAULT('tdb2', noextension='tdb2')
23 opt.RECURSE('lib/replace')
24 opt.add_option('--enable-tdb2',
25 help=("Use tdb2 API instead of tdb1 [True]"),
26 action="store_true", dest='BUILD_TDB2', default=True)
27 opt.add_option('--disable-tdb2',
28 help=("Use old tdb1 API instead of tdb2"),
29 action="store_false", dest='BUILD_TDB2')
30 opt.add_option('--valgrind',
31 help=("use valgrind on tests programs"),
32 action="store_true", dest='VALGRIND', default=False)
33 opt.add_option('--valgrind-log',
34 help=("where to put the valgrind log"),
35 action="store", dest='VALGRINDLOG', default=None)
36 if opt.IN_LAUNCH_DIR():
37 opt.add_option('--disable-python',
38 help=("disable the pytdb module"),
39 action="store_true", dest='disable_python', default=False)
41 def configure(conf):
42 if Options.options.BUILD_TDB2:
43 conf.DEFINE('BUILD_TDB2', 1)
44 conf.RECURSE('lib/replace')
45 conf.RECURSE('lib/ccan')
47 conf.env.standalone_tdb2 = conf.IN_LAUNCH_DIR()
48 conf.env.disable_python = getattr(Options.options, 'disable_python', False)
50 if not conf.env.standalone_tdb2:
51 if conf.CHECK_BUNDLED_SYSTEM('tdb', minversion=VERSION,
52 implied_deps='replace'):
53 conf.define('USING_SYSTEM_TDB2', 1)
54 if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
55 conf.define('USING_SYSTEM_PYTDB', 1)
57 if not conf.env.disable_python:
58 # also disable if we don't have the python libs installed
59 conf.find_program('python', var='PYTHON')
60 conf.check_tool('python')
61 conf.check_python_version((2,4,2))
62 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
63 if not conf.env.HAVE_PYTHON_H:
64 Logs.warn('Disabling pytdb as python devel libs not found')
65 conf.env.disable_python = True
67 # This make #include <ccan/...> work.
68 conf.ADD_EXTRA_INCLUDES('''#lib''')
70 conf.SAMBA_CONFIG_H()
72 # Seems like env can't contain sets?
73 conf.env.tdb2_test = {}
74 conf.env.tdb2_test['run'] = glob.glob('test/run*.c')
75 conf.env.tdb2_test['api'] = glob.glob('test/api*.c')
76 conf.env.tdb2_test['runhelper'] = glob.glob('test/helprun*.c')
77 conf.env.tdb2_test['apihelper'] = glob.glob('test/helpapi*.c')
78 conf.env.tdb2_test['helper'] = list(set(glob.glob('test/*.c'))
79 - set(conf.env.tdb2_test['run'])
80 - set(conf.env.tdb2_test['api'])
81 - set(conf.env.tdb2_test['runhelper'])
82 - set(conf.env.tdb2_test['apihelper']))
84 def build(bld):
85 if bld.env.BUILD_TDB2:
86 bld.RECURSE('lib/replace')
87 bld.RECURSE('lib/ccan')
89 if bld.env.standalone_tdb2:
90 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
91 private_library = False
92 else:
93 private_library = True
95 SRC = '''check.c free.c hash.c io.c lock.c open.c
96 summary.c tdb.c transaction.c traverse.c
97 tdb1_check.c tdb1_freelist.c tdb1_hash.c
98 tdb1_io.c tdb1_lock.c tdb1_open.c
99 tdb1_summary.c tdb1_tdb.c tdb1_transaction.c
100 tdb1_traverse.c'''
102 if not bld.CONFIG_SET('USING_SYSTEM_TDB2'):
103 bld.SAMBA_LIBRARY('tdb',
104 SRC,
105 deps='replace ccan',
106 includes='.',
107 abi_directory='ABI',
108 abi_match='tdb_* tdb1_incompatible_hash',
109 hide_symbols=True,
110 vnum=VERSION,
111 public_headers='tdb2.h',
112 public_headers_install=not private_library,
113 pc_files='tdb.pc',
114 private_library=private_library)
116 bld.SAMBA_BINARY('tdbtorture',
117 'tools/tdb2torture.c',
118 deps='tdb',
119 install=False)
121 bld.SAMBA_BINARY('tdbtool',
122 'tools/tdb2tool.c',
123 deps='tdb')
125 bld.SAMBA_BINARY('tdbdump',
126 'tools/tdb2dump.c',
127 deps='tdb')
129 bld.SAMBA_BINARY('tdbrestore',
130 'tools/tdb2restore.c',
131 deps='tdb')
133 bld.SAMBA_BINARY('tdbbackup',
134 'tools/tdb2backup.c',
135 deps='tdb')
137 # FIXME: We need CCAN for some API tests, but waf thinks it's
138 # already available via tdb. It is, but not publicly.
139 # Workaround is to build a private, non-hiding version.
140 bld.SAMBA_SUBSYSTEM('tdb-testing',
141 SRC,
142 deps='replace ccan',
143 includes='.')
145 bld.SAMBA_SUBSYSTEM('tdb2-test-helpers',
146 bld.env.tdb2_test['helper'], deps='replace')
147 bld.SAMBA_SUBSYSTEM('tdb2-run-helpers',
148 bld.env.tdb2_test['runhelper'], deps='replace')
149 bld.SAMBA_SUBSYSTEM('tdb2-api-helpers',
150 bld.env.tdb2_test['apihelper'], deps='replace tdb-testing')
152 for f in bld.env.tdb2_test['run']:
153 base = os.path.splitext(os.path.basename(f))[0]
154 bld.SAMBA_BINARY('tdb2-' + base, f,
155 deps='ccan replace tdb2-test-helpers tdb2-run-helpers',
156 install=False)
158 for f in bld.env.tdb2_test['api']:
159 base = os.path.splitext(os.path.basename(f))[0]
160 bld.SAMBA_BINARY('tdb2-' + base, f,
161 deps='ccan replace tdb2-test-helpers tdb2-api-helpers',
162 install=False)
164 if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
165 bld.SAMBA_PYTHON('pytdb',
166 source='pytdb.c',
167 deps='tdb',
168 enabled=not bld.env.disable_python,
169 realname='tdb.so',
170 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
172 def testonly(ctx):
173 '''run tdb2 testsuite'''
174 import Utils, samba_utils, shutil
175 ecode = 0;
177 env = samba_utils.LOAD_ENVIRONMENT()
179 if env.BUILD_TDB2 and env.standalone_tdb2:
180 # FIXME: This is horrible :(
181 test_prefix = "%s/st" % (Utils.g_module.blddir)
182 shutil.rmtree(test_prefix, ignore_errors=True)
183 os.makedirs(test_prefix)
185 # Create scratch directory for tests.
186 testdir = os.path.join(test_prefix, 'tdb2-tests')
187 samba_utils.mkdir_p(testdir)
188 # Symlink back to source dir so it can find tests in test/
189 link = os.path.join(testdir, 'test')
190 if not os.path.exists(link):
191 os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
193 if Options.options.VALGRIND:
194 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
195 if Options.options.VALGRINDLOG is not None:
196 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
198 for f in env.tdb2_test['run'] + env.tdb2_test['api']:
199 name = "tdb2-" + os.path.splitext(os.path.basename(f))[0]
200 cmd = "cd " + testdir + " && $VALGRIND " + os.path.abspath(os.path.join(Utils.g_module.blddir, name)) + " > test-output 2>&1"
201 print("..." + f)
202 ret = samba_utils.RUN_COMMAND(cmd)
203 if ret != 0:
204 print("%s (%s) failed:" % (name, f))
205 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
206 ecode = ret;
207 break;
209 sys.exit(ecode)
211 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
212 # This forces it
213 def test(ctx):
214 import Scripting
215 Scripting.commands.append('build')
216 Scripting.commands.append('testonly')
218 def dist():
219 '''makes a tarball for distribution'''
220 samba_dist.dist()
222 def reconfigure(ctx):
223 '''reconfigure if config scripts have changed'''
224 import samba_utils
225 samba_utils.reconfigure(ctx)