9 # find the buildtools directory
11 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
12 srcdir = srcdir + '/..'
13 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
15 import wafsamba, samba_dist, Options, Logs
16 import samba_utils, samba_version
18 env = samba_utils.LOAD_ENVIRONMENT()
19 if os.path.isfile('./VERSION'):
21 elif os.path.isfile('../VERSION'):
24 Logs.error("VERSION file not found")
26 version = samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
27 VERSION = version.STRING.replace('-', '.')
29 Options.default_prefix = '/usr/local'
31 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
32 lib/tevent:lib/tevent lib/tdb:lib/tdb lib/popt:lib/popt
33 lib/socket_wrapper:lib/socket_wrapper
34 buildtools:buildtools''')
37 opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
38 opt.RECURSE('lib/replace')
39 opt.RECURSE('lib/talloc')
40 opt.RECURSE('lib/tevent')
41 opt.RECURSE('lib/tdb')
43 opt.add_option('--enable-infiniband',
44 help=("Turn on infiniband support (default=no)"),
45 action="store_true", dest='ctdb_infiniband', default=False)
46 opt.add_option('--enable-pmda',
47 help=("Turn on PCP pmda support (default=no)"),
48 action="store_true", dest='ctdb_pmda', default=False)
50 opt.add_option('--with-logdir',
51 help=("Path to log directory"),
52 action="store", dest='ctdb_logdir', default=None)
53 opt.add_option('--with-socketpath',
54 help=("path to CTDB daemon socket"),
55 action="store_true", dest='ctdb_sockpath', default=False)
59 # CTDB relies on nested event loops
60 conf.env.TEVENT_DEPRECATED = 1
62 # No need to build python bindings for talloc/tevent/tdb
63 if conf.IN_LAUNCH_DIR():
64 Options.options.disable_python = True
66 conf.RECURSE('lib/replace')
67 conf.RECURSE('lib/popt')
68 conf.RECURSE('lib/talloc')
69 conf.RECURSE('lib/tevent')
70 conf.RECURSE('lib/tdb')
71 conf.RECURSE('lib/socket_wrapper')
74 if Options.options.ctdb_pmda:
77 if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
80 if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
82 if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
87 Logs.error("PMDA support not available")
89 Logs.info('Building with PMDA support')
90 conf.define('HAVE_PMDA', 1)
91 conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
94 have_infiniband = False
95 if Options.options.ctdb_infiniband:
98 if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
100 if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
102 if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
105 have_infiniband = True
107 Logs.error("Infiniband support not available")
109 Logs.info('Building with Infiniband support')
110 conf.define('HAVE_INFINIBAND', 1)
111 conf.define('USE_INFINIBAND', 1)
113 conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
114 conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
115 conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
116 conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
118 machine = os.uname()[4]
119 if machine in ['x86_64', 'ppc64', 'powerpc64']:
120 conf.env.LIBDIR = conf.env.LIBDIR + '64'
122 if Options.options.ctdb_logdir:
123 conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
125 conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
127 if Options.options.ctdb_sockpath:
128 conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
130 conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
133 conf.ADD_CFLAGS('''-DBINDIR=\"%s\"
138 -DCTDB_RUNDIR=\"%s\"''' % (
139 conf.env.CTDB_BINDIR,
140 conf.env.CTDB_LOGDIR,
141 conf.env.CTDB_SOCKPATH,
142 conf.env.CTDB_ETCDIR,
143 conf.env.CTDB_VARDIR,
144 conf.env.CTDB_RUNDIR))
146 conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
148 conf.env.CTDB_TEST_LIBDIR = os.path.join(conf.env.LIBDIR, 'ctdb-tests')
150 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
151 conf.SAMBA_CONFIG_H()
154 bld.RECURSE('lib/replace')
155 bld.RECURSE('lib/popt')
156 bld.RECURSE('lib/talloc')
157 bld.RECURSE('lib/tevent')
158 bld.RECURSE('lib/tdb')
159 bld.RECURSE('lib/socket_wrapper')
161 bld.SAMBA_GENERATOR('ctdb-version-header',
162 target='include/ctdb_version.h',
163 rule='../packaging/mkversion.sh ${TGT} %s' % (VERSION),
166 bld.SAMBA_SUBSYSTEM('ctdb-util',
167 source=bld.SUBDIR('lib/util',
168 'util.c util_file.c util_time.c'),
169 includes='include include/internal',
170 deps='replace talloc tevent tdb')
172 bld.SAMBA_SUBSYSTEM('ctdb-util-misc',
173 source=bld.SUBDIR('lib/util',
174 '''db_wrap.c debug.c fault.c
175 idtree.c signal.c strlist.c
177 includes='include include/internal lib/util',
178 deps='replace talloc tevent tdb')
180 bld.SAMBA_SUBSYSTEM('ctdb-tcp',
181 source=bld.SUBDIR('tcp',
182 'tcp_connect.c tcp_init.c tcp_io.c'),
183 includes='include include/internal',
184 deps='replace tdb talloc tevent')
187 if bld.env.HAVE_INFINIBAND:
188 bld.SAMBA_SUBSYSTEM('ctdb-ib',
189 source=bld.SUBDIR('ib',
190 '''ibwrapper.c ibw_ctdb.c
192 includes='include include/internal',
194 ib_deps = ' ctdb-ib rdmacm ibverbs'
196 bld.SAMBA_SUBSYSTEM('ctdb-common',
197 source=bld.SUBDIR('common',
198 '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
199 ctdb_message.c cmdline.c rb_tree.c
200 system_common.c ctdb_fork.c'''),
201 includes='include include/internal common . lib/util',
202 deps='replace popt talloc tevent tdb')
204 bld.SAMBA_SUBSYSTEM('ctdb-common-util',
205 source=bld.SUBDIR('common',
206 'system_util.c ctdb_logging.c'),
207 includes='include include/internal',
208 deps='replace tevent tdb')
210 if sys.platform == 'linux2':
211 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
212 elif sys.platform == 'aix':
213 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
214 elif sys.platform == 'freebsd':
215 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
216 elif sys.platform == 'kfreebsd':
217 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
218 elif sys.platform == 'gnu':
219 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
221 Logs.error("Platform %s not supported" % sys.platform)
223 bld.SAMBA_SUBSYSTEM('ctdb-system',
224 source=CTDB_SYSTEM_SRC,
225 includes='include include/internal',
226 deps='replace talloc tevent tdb')
228 bld.SAMBA_SUBSYSTEM('ctdb-client',
229 source=bld.SUBDIR('client', 'ctdb_client.c'),
230 includes='include include/internal lib/util',
231 public_headers='include/ctdb_client.h',
232 deps='replace popt talloc tevent tdb')
234 bld.SAMBA_SUBSYSTEM('ctdb-server',
235 source='server/ctdbd.c ' +
237 '''ctdb_daemon.c ctdb_recoverd.c
238 ctdb_recover.c ctdb_freeze.c
239 ctdb_tunables.c ctdb_monitor.c
240 ctdb_server.c ctdb_control.c
241 ctdb_call.c ctdb_ltdb_server.c
242 ctdb_traverse.c eventscript.c
243 ctdb_takeover.c ctdb_serverids.c
244 ctdb_persistent.c ctdb_keepalive.c
245 ctdb_logging.c ctdb_uptime.c
246 ctdb_vacuum.c ctdb_banning.c
250 includes='include include/internal lib/util',
251 public_headers='''include/ctdb.h
252 include/ctdb_private.h
253 include/ctdb_protocol.h
254 include/ctdb_typesafe_cb.h''',
255 deps='replace popt talloc tevent tdb')
257 bld.SAMBA_BINARY('bin/ctdbd',
259 deps='''ctdb-server ctdb-client ctdb-common
260 ctdb-common-util ctdb-system ctdb-tcp
261 ctdb-util ctdb-util-misc''' +
263 install_path='${SBINDIR}',
264 manpages='doc/ctdbd.1')
266 bld.SAMBA_BINARY('bin/ctdb',
267 source='tools/ctdb.c tools/ctdb_vacuum.c',
268 deps='''ctdb-client ctdb-common ctdb-common-util
269 ctdb-system ctdb-util ctdb-util-misc''',
270 install_path='${BINDIR}',
271 manpages='doc/ctdb.1')
273 bld.SAMBA_BINARY('bin/ltdbtool',
274 source='tools/ltdbtool.c',
277 install_path='${BINDIR}',
278 manpages='doc/ltdbtool.1')
280 bld.SAMBA_BINARY('bin/ctdb_lock_helper',
281 source='server/ctdb_lock_helper.c',
282 deps='ctdb-util ctdb-util-misc ctdb-common-util talloc tdb',
283 install_path='${BINDIR}')
285 bld.SAMBA_BINARY('bin/ctdb_event_helper',
286 source='server/ctdb_event_helper.c',
287 includes='include include/internal',
288 deps='ctdb-util ctdb-util-misc ctdb-common-util replace tdb',
289 install_path='${BINDIR}')
291 bld.SAMBA_GENERATOR('ctdb-smnotify-h',
292 source='utils/smnotify/smnotify.x',
293 target='utils/smnotify/smnotify.h',
294 rule='rpcgen -h ${SRC} > ${TGT}')
296 bld.SAMBA_GENERATOR('ctdb-smnotify-x',
297 source='utils/smnotify/smnotify.x',
298 target='utils/smnotify/gen_xdr.c',
299 rule='rpcgen -c ${SRC} > ${TGT}')
301 bld.SAMBA_GENERATOR('ctdb-smnotify-c',
302 source='utils/smnotify/smnotify.x',
303 target='utils/smnotify/gen_smnotify.c',
304 rule='rpcgen -l ${SRC} > ${TGT}')
306 bld.SAMBA_BINARY('bin/smnotify',
307 source=bld.SUBDIR('utils/smnotify',
308 'smnotify.c gen_smnotify.c gen_xdr.c'),
309 deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
310 includes='utils utils/smnotify',
311 install_path='${BINDIR}')
313 bld.SAMBA_BINARY('bin/ping_pong',
314 source='utils/ping_pong/ping_pong.c',
316 install_path='${BINDIR}',
317 manpages='doc/ping_pong.1')
319 if bld.env.HAVE_PMDA:
320 bld.SAMBA_BINARY('bin/pmdactdb',
321 source='utils/pmda/pmda_ctdb.c',
322 includes='include include/internal',
323 deps='''ctdb-client ctdb-common ctdb-system
324 ctdb-util-misc ctdb-util pcp_pmda pcp''',
325 install_path='${CTDB_PMDADIR}')
326 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
328 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
330 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
332 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
334 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
336 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
339 bld.MANPAGES('''doc/onnode.1 doc/ctdbd_wrapper.1 doc/ctdbd.conf.5
340 doc/ctdb.7 doc/ctdb-tunables.7''', True)
342 bld.INSTALL_FILES('${BINDIR}', 'tools/onnode',
343 destname='onnode', chmod=0755)
344 bld.INSTALL_FILES('${BINDIR}', 'tools/ctdb_diagnostics',
345 destname='ctdb_diagnostics', chmod=0755)
346 bld.INSTALL_FILES('${SBINDIR}', 'config/ctdbd_wrapper',
347 destname='ctdbd_wrapper', chmod=0755)
349 def SUBDIR_MODE_callback(arg, dirname, fnames):
351 fl = os.path.join(dirname, f)
352 if os.path.isdir(fl) or os.path.islink(fl):
354 mode = os.lstat(fl).st_mode & 0777
356 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
357 arg['file_list'].append([fl, mode])
359 def SUBDIR_MODE(path, trim_path=None):
360 pd = {'trim_path': trim_path, 'file_list': []}
361 os.path.walk(path, SUBDIR_MODE_callback, pd)
362 return pd['file_list']
369 for t in etc_subdirs:
370 files = SUBDIR_MODE('config/%s' % t, trim_path='config')
372 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
373 destname=fmode[0], chmod=fmode[1])
375 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/functions',
376 destname='functions')
379 'ctdb-crash-cleanup.sh',
380 'debug-hung-script.sh',
387 for t in etc_scripts:
388 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/' + t,
389 destname=t, chmod=0755)
391 bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'config/ctdb.sudoers',
394 bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
397 bld.install_dir(bld.env.CTDB_LOGDIR)
398 bld.install_dir(bld.env.CTDB_RUNDIR)
399 bld.install_dir(bld.env.CTDB_VARDIR)
401 sed_expr = 's/@PACKAGE_VERSION@/%s/g' % VERSION
402 bld.SAMBA_GENERATOR('ctdb-pc',
405 rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
406 bld.INSTALL_FILES('${LIBDIR}/pkgconfig', 'ctdb.pc')
414 'ctdb_fetch_readonly_once',
415 'ctdb_fetch_readonly_loop',
416 'ctdb_trackingdb_test',
417 'ctdb_update_record',
418 'ctdb_update_record_persistent',
423 'ctdb_porting_tests',
430 src = 'tests/src/' + t + '.c'
432 bld.SAMBA_BINARY(target,
434 deps='''ctdb-client ctdb-common ctdb-common-util
435 ctdb-system ctdb-util ctdb-util-misc''',
436 install_path='${CTDB_TEST_LIBDIR}')
438 bld.SAMBA_BINARY('bin/ctdb_takeover_tests',
439 source='tests/src/ctdb_takeover_tests.c',
440 deps='replace popt tdb tevent talloc ctdb-system' +
442 includes='../include ../include/internal lib/util',
443 install_path='${CTDB_TEST_LIBDIR}')
445 bld.SAMBA_BINARY('bin/ctdb_functest',
446 source='tests/src/ctdb_functest.c',
447 deps='replace tdb tevent talloc popt ctdb-system',
448 includes='../include ../include/internal lib/util',
449 install_path='${CTDB_TEST_LIBDIR}')
451 bld.SAMBA_BINARY('bin/ctdb_stubtest',
452 source='tests/src/ctdb_test.c',
453 deps='replace tdb tevent talloc popt ctdb-system',
454 includes='../include ../include/internal lib/util',
455 install_path='${CTDB_TEST_LIBDIR}')
457 if bld.env.HAVE_INFINIBAND:
458 bld.SAMBA_BINARY('bin/ibwrapper_test',
459 source='ib/ibwrapper_test.c',
460 includes='include include/internal',
461 deps='''replace talloc ctdb-client ctdb-common
462 ctdb-system ctdb-util-misc ctdb-util''' +
464 install_path='${CTDB_TEST_LIBDIR}')
476 for t in test_subdirs:
477 files = SUBDIR_MODE('tests/%s' % t, trim_path='tests')
479 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
480 destname=fmode[0], chmod=fmode[1])
482 # Install tests/scripts directory without test_wrap
489 for t in test_scripts:
490 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
491 os.path.join('tests/scripts', t),
492 destname=os.path.join('scripts', t))
494 sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
495 bld.env.CTDB_TEST_LIBDIR)
496 bld.SAMBA_GENERATOR('ctdb-test-wrap',
497 source='tests/scripts/test_wrap',
499 rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
500 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
501 destname='test_wrap', chmod=0755)
503 sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
504 bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBDIR)
505 sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
506 bld.SAMBA_GENERATOR('ctdb-test-runner',
507 source='tests/run_tests.sh',
508 target='ctdb_run_tests.sh',
509 rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
510 sed_expr1, sed_expr2))
511 bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
512 destname='ctdb_run_tests', chmod=0755)
513 bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
516 test_eventscript_links = [
522 test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
523 'eventscripts/etc-ctdb')
524 for t in test_eventscript_links:
525 bld.symlink_as(os.path.join(test_link_dir, t),
526 os.path.join(bld.env.CTDB_ETCDIR, t))
530 cmd = 'tests/run_tests.sh -V tests/var'
531 ret = samba_utils.RUN_COMMAND(cmd)
533 print('tests exited with exit status %d' % ret)
538 Scripting.commands.append('build')
539 Scripting.commands.append('testonly')
542 cmd = 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
543 ret = samba_utils.RUN_COMMAND(cmd)
545 print('autotest exited with exit status %d' % ret)
548 def show_version(ctx):
552 samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
554 t = 'include/ctdb_version.h'
555 cmd = 'packaging/mkversion.sh %s %s' % (t, VERSION)
556 ret = samba_utils.RUN_COMMAND(cmd)
558 print('Command "%s" failed with exit status %d' % (cmd, ret))
560 samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
563 sed_expr1 = 's/@VERSION@/%s/g' % VERSION
564 sed_expr2 = 's/@RELEASE@/%s/g' % '1'
565 cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
566 sed_expr1, sed_expr2, t)
567 ret = samba_utils.RUN_COMMAND(cmd)
569 print('Command "%s" failed with exit status %d' % (cmd, ret))
571 samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
584 ret = samba_utils.RUN_COMMAND(cmd)
586 print('Command "%s" failed with exit status %d' % (cmd, ret))
589 samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
590 samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
596 cmd = 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
597 ret = samba_utils.RUN_COMMAND(cmd)
599 print('rpmbuild exited with exit status %d' % ret)
604 Scripting.commands.append('dist')
605 Scripting.commands.append('rpmonly')
608 "build 'tags' file using ctags"
610 source_root = os.path.dirname(Utils.g_module.root_path)
611 cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
612 print("Running: %s" % cmd)
613 ret = samba_utils.RUN_COMMAND(cmd)
615 print('ctags failed with exit status %d' % ret)