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, Utils
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 default_prefix = 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
33 third_party/socket_wrapper:third_party/socket_wrapper
34 third_party/popt:third_party/popt
35 lib/util:lib/util lib/tdb_wrap:lib/tdb_wrap
36 lib/ccan:lib/ccan libcli/util:libcli/util
37 lib/async_req:lib/async_req
38 buildtools:buildtools third_party/waf:third_party/waf''')
52 'ctdb-script.options.5',
64 'ctdb_mutex_ceph_rados_helper.7',
69 opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
71 opt.RECURSE('lib/replace')
73 opt.RECURSE('lib/util')
75 opt.RECURSE('lib/talloc')
76 opt.RECURSE('lib/tevent')
77 opt.RECURSE('lib/tdb')
79 opt.add_option('--enable-infiniband',
80 help=("Turn on infiniband support (default=no)"),
81 action="store_true", dest='ctdb_infiniband', default=False)
82 opt.add_option('--enable-pmda',
83 help=("Turn on PCP pmda support (default=no)"),
84 action="store_true", dest='ctdb_pmda', default=False)
85 opt.add_option('--enable-etcd-reclock',
86 help=("Enable etcd recovery lock helper (default=no)"),
87 action="store_true", dest='ctdb_etcd_reclock', default=False)
88 opt.add_option('--enable-ceph-reclock',
89 help=("Enable Ceph CTDB recovery lock helper (default=no)"),
90 action="store_true", dest='ctdb_ceph_reclock', default=False)
92 opt.add_option('--with-logdir',
93 help=("Path to log directory"),
94 action="store", dest='ctdb_logdir', default=None)
95 opt.add_option('--with-socketpath',
96 help=("path to CTDB daemon socket"),
97 action="store", dest='ctdb_sockpath', default=None)
102 # No need to build python bindings for talloc/tevent/tdb
103 if conf.IN_LAUNCH_DIR():
104 conf.env.standalone_ctdb = True
105 Options.options.disable_python = True
107 conf.RECURSE('lib/replace')
109 conf.CHECK_HEADERS(headers='''sys/socket.h
117 conf.CHECK_CODE('int s = socket(AF_PACKET, SOCK_RAW, 0);',
118 define='HAVE_AF_PACKET',
119 headers='sys/socket.h linux/if_packet.h')
121 conf.CHECK_CODE('struct sockaddr_ll sall; sall.sll_family = AF_PACKET;',
122 define='HAVE_PACKETSOCKET',
123 headers='sys/socket.h linux/if_packet.h')
125 if conf.env.standalone_ctdb:
126 conf.SAMBA_CHECK_PERL(mandatory=True)
128 conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,5,0))
129 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
131 if conf.CHECK_FOR_THIRD_PARTY():
132 conf.RECURSE('third_party/popt')
133 if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
134 conf.RECURSE('third_party/socket_wrapper')
135 conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
137 if not conf.CHECK_POPT():
138 raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
140 conf.define('USING_SYSTEM_POPT', 1)
141 conf.env.SOCKET_WRAPPER_SO_PATH = ''
144 if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
145 if not conf.CHECK_SOCKET_WRAPPER():
146 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
148 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
149 conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
151 conf.RECURSE('lib/util')
153 conf.RECURSE('lib/talloc')
154 conf.RECURSE('lib/tevent')
155 conf.RECURSE('lib/tdb')
157 conf.CHECK_HEADERS('sched.h')
158 conf.CHECK_HEADERS('procinfo.h')
159 if sys.platform.startswith('aix') and not conf.CHECK_FUNCS('thread_setsched'):
160 Logs.error('Need thread_setsched() on AIX')
162 elif not conf.CHECK_FUNCS('sched_setscheduler'):
163 Logs.error('Need sched_setscheduler()')
165 conf.CHECK_FUNCS('mlockall')
167 if not conf.CHECK_VARIABLE('ETIME', headers='errno.h'):
168 conf.DEFINE('ETIME', 'ETIMEDOUT')
170 if sys.platform.startswith('linux'):
171 conf.SET_TARGET_TYPE('pcap', 'EMPTY')
173 if not conf.CHECK_HEADERS('pcap.h'):
174 Logs.error('Need libpcap')
176 if not conf.CHECK_FUNCS_IN('pcap_open_live', 'pcap', headers='pcap.h'):
177 Logs.error('Need libpcap')
180 if not conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo',
181 checklibc=True, headers='execinfo.h'):
182 Logs.error('backtrace support not available')
185 if Options.options.ctdb_pmda:
188 if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
191 if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
193 if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
196 conf.CHECK_TYPE_IN('__pmID_int', 'pcp/pmapi.h pcp/impl.h')
199 Logs.error("PMDA support not available")
202 Logs.info('Building with PMDA support')
203 conf.define('HAVE_PMDA', 1)
204 conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
205 'lib/pcp/pmdas/ctdb')
207 have_infiniband = False
208 if Options.options.ctdb_infiniband:
211 if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
213 if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
215 if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
218 have_infiniband = True
220 Logs.error("Infiniband support not available")
223 Logs.info('Building with Infiniband support')
224 conf.define('HAVE_INFINIBAND', 1)
225 conf.define('USE_INFINIBAND', 1)
227 have_etcd_reclock = False
228 if Options.options.ctdb_etcd_reclock:
230 conf.check_python_module('etcd')
231 have_etcd_reclock = True
233 Logs.error('etcd support not available')
235 if have_etcd_reclock:
236 Logs.info('Building with etcd support')
237 conf.env.etcd_reclock = have_etcd_reclock
239 if Options.options.ctdb_ceph_reclock:
240 if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
241 conf.CHECK_LIB('rados', shlib=True)):
242 Logs.info('Building with Ceph librados recovery lock support')
243 conf.define('HAVE_LIBRADOS', 1)
245 Logs.error("Missing librados for Ceph recovery lock support")
248 conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
249 conf.env.CTDB_DATADIR = os.path.join(conf.env.EXEC_PREFIX, 'share/ctdb')
250 conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
251 conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
252 conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
253 conf.env.CTDB_HELPER_BINDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb')
255 if Options.options.ctdb_logdir:
256 conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
258 conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
260 if Options.options.ctdb_sockpath:
261 conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
263 conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
265 conf.define('CTDB_SOCKET', conf.env.CTDB_SOCKPATH)
267 conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
269 -DCTDB_DATADIR=\"%s\"
272 -DCTDB_RUNDIR=\"%s\"''' % (
273 conf.env.CTDB_HELPER_BINDIR,
274 conf.env.CTDB_LOGDIR,
275 conf.env.CTDB_DATADIR,
276 conf.env.CTDB_ETCDIR,
277 conf.env.CTDB_VARDIR,
278 conf.env.CTDB_RUNDIR))
280 conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.CTDB_DATADIR, 'tests')
281 conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
283 # Allow unified compilation and separate compilation of utilities
285 if not conf.env.standalone_ctdb:
286 conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
289 # Building from tarball
290 conf.ADD_EXTRA_INCLUDES('#include')
292 # Building standalone CTDB from within Samba tree
293 conf.ADD_EXTRA_INCLUDES('#ctdb/include')
294 conf.ADD_EXTRA_INCLUDES('#ctdb')
295 conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
297 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
298 conf.DEFINE('SAMBA_UTIL_CORE_ONLY', 1, add_to_cflags=True)
299 conf.SAMBA_CONFIG_H()
301 if 'XSLTPROC_MANPAGES' in conf.env and conf.env['XSLTPROC_MANPAGES']:
302 conf.env.ctdb_generate_manpages = True
304 conf.env.ctdb_generate_manpages = False
306 Logs.info("xsltproc unavailable, checking for pre-built manpages")
307 conf.env.ctdb_prebuilt_manpages = []
308 manpages = manpages_binary + manpages_misc
309 if conf.env.etcd_reclock:
310 manpages += manpages_etcd
311 if conf.env.HAVE_LIBRADOS:
312 manpages += manpages_ceph
314 if os.path.exists(os.path.join("doc", m)):
315 Logs.info(" %s: yes" % (m))
316 conf.env.ctdb_prebuilt_manpages.append(m)
318 Logs.info(" %s: no" % (m))
320 def gen_ctdb_version(task):
321 fp = file(task.outputs[0].bldpath(task.env), 'w')
322 fp.write('/* This file is auto-generated from waf */\n')
323 fp.write('#include "version.h"\n')
325 fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
330 if bld.env.standalone_ctdb:
331 # enable building of public headers in the build tree
332 bld.env.build_public_headers = 'include/public'
334 if bld.env.standalone_ctdb:
335 bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
337 t = bld.SAMBA_GENERATOR('ctdb-version-header',
338 target='include/ctdb_version.h',
339 rule=gen_ctdb_version,
340 dep_vars=['VERSION'])
341 t.env.VERSION = VERSION
343 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
345 bld.RECURSE('lib/replace')
346 if bld.CHECK_FOR_THIRD_PARTY():
347 bld.RECURSE('third_party/popt')
348 if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
349 bld.RECURSE('third_party/socket_wrapper')
351 bld.RECURSE('lib/tdb_wrap')
352 bld.RECURSE('lib/util')
353 bld.RECURSE('lib/async_req')
355 bld.RECURSE('lib/talloc')
356 bld.RECURSE('lib/tevent')
357 bld.RECURSE('lib/tdb')
359 if bld.env.standalone_ctdb:
360 # If a combined build is implemented, CTDB will want to
361 # build against samba-util rather than samba-util-core.
362 # Similarly, other Samba subsystems expect samba-util. So,
363 # for a standalone build, just define a fake samba-util
364 # subsystem that pulls in samba-util-core.
365 bld.SAMBA_SUBSYSTEM('samba-util',
367 deps='samba-util-core')
369 bld.SAMBA_SUBSYSTEM('ctdb-tcp',
370 source=bld.SUBDIR('tcp',
371 'tcp_connect.c tcp_init.c tcp_io.c'),
373 deps='replace tdb talloc tevent')
376 if bld.env.HAVE_INFINIBAND:
377 bld.SAMBA_SUBSYSTEM('ctdb-ib',
378 source=bld.SUBDIR('ib',
379 '''ibwrapper.c ibw_ctdb.c
382 deps='replace talloc tevent tdb')
383 ib_deps = ' ctdb-ib rdmacm ibverbs'
385 bld.SAMBA_SUBSYSTEM('ctdb-system',
386 source=bld.SUBDIR('common',
387 'system_socket.c system.c'),
389 deps='replace talloc tevent tdb pcap samba-util')
391 bld.SAMBA_SUBSYSTEM('ctdb-common',
392 source=bld.SUBDIR('common',
393 '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
396 deps='''replace popt talloc tevent tdb popt ctdb-system
397 ctdb-protocol-util''')
399 bld.SAMBA_SUBSYSTEM('ctdb-util',
400 source=bld.SUBDIR('common',
401 '''db_hash.c srvid.c reqid.c
402 pkt_read.c pkt_write.c comm.c
403 logging.c rb_tree.c tunable.c
405 hash_count.c run_event.c
406 sock_client.c version.c
407 cmdline.c path.c conf.c
409 deps='''samba-util sys_rw tevent-util
410 replace talloc tevent tdb popt''')
412 bld.SAMBA_SUBSYSTEM('ctdb-logging-conf',
413 source='common/logging_conf.c',
414 deps='ctdb-util talloc')
416 bld.SAMBA_SUBSYSTEM('ctdb-protocol-basic',
417 source=bld.SUBDIR('protocol', 'protocol_basic.c'),
420 bld.SAMBA_SUBSYSTEM('ctdb-protocol',
421 source=bld.SUBDIR('protocol',
422 '''protocol_header.c protocol_packet.c
433 deps='ctdb-protocol-basic replace talloc tdb')
435 bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
436 source='protocol/protocol_util.c',
437 deps='replace talloc tdb')
439 bld.SAMBA_SUBSYSTEM('ctdb-client',
440 source=bld.SUBDIR('client',
441 '''client_connect.c client_call.c
442 client_message.c client_control.c
443 client_message_sync.c
444 client_control_sync.c
445 client_db.c client_util.c
449 deps='replace talloc tevent tdb tdb-wrap')
451 bld.SAMBA_SUBSYSTEM('ctdb-server-util',
452 source=bld.SUBDIR('common',
453 '''sock_daemon.c'''),
454 deps='''samba-util ctdb-util ctdb-system tevent-util
455 LIBASYNC_REQ replace talloc tevent''')
457 bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
458 source=bld.SUBDIR('server',
459 '''ipalloc_deterministic.c
460 ipalloc_nondeterministic.c
466 deps='ctdb-protocol-util replace talloc tevent')
468 bld.SAMBA_BINARY('ctdb-path',
469 source='common/path_tool.c',
470 cflags='-DCTDB_PATH_TOOL',
471 deps='''ctdb-util samba-util talloc replace popt''',
472 install_path='${CTDB_HELPER_BINDIR}')
474 bld.SAMBA_SUBSYSTEM('ctdb-cluster-conf',
475 source='cluster/cluster_conf.c',
478 bld.SAMBA_SUBSYSTEM('ctdb-database-conf',
479 source='database/database_conf.c',
482 bld.SAMBA_SUBSYSTEM('ctdb-event-conf',
483 source='event/event_conf.c',
486 bld.SAMBA_SUBSYSTEM('ctdb-legacy-conf',
487 source='server/legacy_conf.c',
490 bld.SAMBA_BINARY('ctdb-config',
491 source='common/conf_tool.c',
492 cflags='-DCTDB_CONF_TOOL',
493 deps='''ctdb-logging-conf
498 ctdb-util samba-util talloc replace popt''',
499 install_path='${CTDB_HELPER_BINDIR}')
501 bld.SAMBA_SUBSYSTEM('ctdb-event-protocol',
502 source=bld.SUBDIR('event',
504 event_protocol_util.c
506 deps='ctdb-protocol-basic')
508 bld.SAMBA_LIBRARY('ctdb-event-client',
509 source='event/event_client.c',
510 deps='ctdb-event-protocol ctdb-util tevent talloc',
511 private_library=True)
513 bld.SAMBA_BINARY('ctdb-eventd',
514 source=bld.SUBDIR('event',
521 deps='''ctdb-event-protocol
522 ctdb-event-conf ctdb-logging-conf
523 ctdb-server-util samba-util ctdb-util
524 talloc tevent replace popt''',
525 install_path='${CTDB_HELPER_BINDIR}')
527 bld.SAMBA_BINARY('ctdb-event',
528 source='event/event_tool.c',
529 cflags='-DCTDB_EVENT_TOOL',
530 deps='''ctdb-event-client ctdb-event-protocol
531 ctdb-util samba-util talloc replace''',
532 install_path='${CTDB_HELPER_BINDIR}')
534 bld.SAMBA_BINARY('ctdbd',
535 source='server/ctdbd.c ' +
537 '''ctdb_daemon.c ctdb_recoverd.c
538 ctdb_recover.c ctdb_freeze.c
539 ctdb_tunables.c ctdb_monitor.c
540 ctdb_server.c ctdb_control.c
541 ctdb_call.c ctdb_ltdb_server.c
542 ctdb_traverse.c eventscript.c
544 ctdb_persistent.c ctdb_keepalive.c
548 ctdb_vacuum.c ctdb_banning.c
551 ctdb_lock.c ctdb_fork.c
552 ctdb_tunnel.c ctdb_client.c
556 deps='''ctdb-common ctdb-system ctdb-protocol
557 ctdb-tcp ctdb-util replace sys_rw popt
564 talloc tevent tdb-wrap tdb talloc_report''' +
566 install_path='${SBINDIR}',
569 bld.SAMBA_BINARY('ctdb',
570 source='tools/ctdb.c',
571 deps='''ctdb-client ctdb-protocol ctdb-protocol-util
572 ctdb-util ctdb-system samba-util sys_rw popt''',
573 install_path='${BINDIR}',
576 bld.SAMBA_BINARY('ctdb_killtcp',
577 source='tools/ctdb_killtcp.c',
578 deps='''ctdb-protocol-util ctdb-util ctdb-system
579 samba-util replace''',
580 install_path='${CTDB_HELPER_BINDIR}')
582 bld.SAMBA_BINARY('ltdbtool',
583 source='tools/ltdbtool.c',
586 install_path='${BINDIR}',
587 manpages='ltdbtool.1')
589 bld.SAMBA_BINARY('ctdb_lock_helper',
590 source='server/ctdb_lock_helper.c',
591 deps='''samba-util sys_rw ctdb-system tevent-util
592 talloc tevent tdb''',
594 install_path='${CTDB_HELPER_BINDIR}')
596 bld.SAMBA_BINARY('ctdb_recovery_helper',
597 source='server/ctdb_recovery_helper.c',
598 deps='''ctdb-client ctdb-protocol ctdb-util
599 samba-util sys_rw replace tdb''',
600 install_path='${CTDB_HELPER_BINDIR}')
602 bld.SAMBA_BINARY('ctdb_takeover_helper',
603 source='server/ctdb_takeover_helper.c',
604 deps='''ctdb-client ctdb-protocol ctdb-util
605 samba-util sys_rw replace ctdb-ipalloc popt''',
606 install_path='${CTDB_HELPER_BINDIR}')
608 bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
609 source='server/ctdb_mutex_fcntl_helper.c',
610 deps='sys_rw ctdb-system',
612 install_path='${CTDB_HELPER_BINDIR}')
614 bld.SAMBA_GENERATOR('ctdb-smnotify-h',
615 source='utils/smnotify/smnotify.x',
616 target='utils/smnotify/smnotify.h',
617 rule='rpcgen -h ${SRC} > ${TGT}')
619 xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
621 bld.SAMBA_GENERATOR('ctdb-smnotify-x',
622 source='utils/smnotify/smnotify.x',
623 target='utils/smnotify/gen_xdr.c',
624 rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
626 bld.SAMBA_GENERATOR('ctdb-smnotify-c',
627 source='utils/smnotify/smnotify.x',
628 target='utils/smnotify/gen_smnotify.c',
629 rule='rpcgen -l ${SRC} > ${TGT}')
631 bld.SAMBA_BINARY('smnotify',
632 source=bld.SUBDIR('utils/smnotify',
633 'smnotify.c gen_smnotify.c gen_xdr.c'),
634 deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt tirpc',
635 includes='utils utils/smnotify',
636 install_path='${CTDB_HELPER_BINDIR}')
638 bld.SAMBA_BINARY('ping_pong',
639 source='utils/ping_pong/ping_pong.c',
641 install_path='${BINDIR}',
642 manpages='ping_pong.1')
644 if bld.env.HAVE_PMDA:
645 bld.SAMBA_BINARY('pmdactdb',
646 source='utils/pmda/pmda_ctdb.c',
648 deps='''ctdb-client ctdb-protocol ctdb-util
649 samba-util pcp_pmda pcp''',
650 install_path='${CTDB_PMDADIR}')
651 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
653 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
655 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
657 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
659 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
661 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
664 if bld.env.HAVE_LIBRADOS:
665 bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
666 source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
667 deps='talloc tevent rados',
669 install_path='${CTDB_HELPER_BINDIR}')
671 sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g' % (bld.env.CTDB_VARDIR)
672 sed_expr2 = 's|/usr/local/etc/ctdb|%s|g' % (bld.env.CTDB_ETCDIR)
673 sed_expr3 = 's|/usr/local/var/log|%s|g' % (bld.env.CTDB_LOGDIR)
674 sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g' % (bld.env.CTDB_RUNDIR)
675 sed_expr5 = 's|/usr/local/sbin|%s|g' % (bld.env.SBINDIR)
676 sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g' % (bld.env.CTDB_HELPER_BINDIR)
677 sed_expr7 = 's|/usr/local/bin|%s|g' % (bld.env.BINDIR)
678 sed_expr8 = 's|/usr/local/share/ctdb|%s|g' % (bld.env.CTDB_DATADIR)
679 sed_cmdline = '-e "%s" ' * 8 % \
680 (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
681 sed_expr6, sed_expr7, sed_expr8)
683 manpages_extra = manpages_misc
684 if bld.env.etcd_reclock:
685 manpages_extra += manpages_etcd
686 if bld.env.HAVE_LIBRADOS:
687 manpages_extra += manpages_ceph
688 for f in manpages_binary + manpages_extra:
690 bld.SAMBA_GENERATOR(x,
691 source=os.path.join('doc', x),
693 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
695 if bld.env.ctdb_generate_manpages:
696 bld.MANPAGES(' '.join(manpages_extra), True)
698 for m in bld.env.ctdb_prebuilt_manpages:
699 bld.SAMBA_GENERATOR(m,
700 source=os.path.join("doc", m),
702 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
703 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
705 bld.SAMBA_GENERATOR('ctdb-onnode',
706 source='tools/onnode',
708 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
709 bld.INSTALL_FILES('${BINDIR}', 'onnode',
710 destname='onnode', chmod=0755)
712 bld.SAMBA_GENERATOR('ctdb-diagnostics',
713 source='tools/ctdb_diagnostics',
714 target='ctdb_diagnostics',
715 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
716 bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
717 destname='ctdb_diagnostics', chmod=0755)
719 if bld.env.etcd_reclock:
720 bld.SAMBA_GENERATOR('ctdb-etcd-lock',
721 source='utils/etcd/ctdb_etcd_lock',
722 target='ctdb_etcd_lock',
723 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
724 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
725 destname='ctdb_etcd_lock', chmod=0744)
727 bld.SAMBA_GENERATOR('ctdb-natgw',
728 source='tools/ctdb_natgw',
730 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
731 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
732 destname='ctdb_natgw', chmod=0755)
734 bld.SAMBA_GENERATOR('ctdb-lvs',
735 source='tools/ctdb_lvs',
737 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
738 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
739 destname='ctdb_lvs', chmod=0755)
741 bld.SAMBA_GENERATOR('ctdbd-wrapper',
742 source='config/ctdbd_wrapper',
743 target='ctdbd_wrapper',
744 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
745 bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
746 destname='ctdbd_wrapper', chmod=0755)
748 def SUBDIR_MODE_callback(arg, dirname, fnames):
750 fl = os.path.join(dirname, f)
751 if os.path.isdir(fl) or os.path.islink(fl):
753 mode = os.lstat(fl).st_mode & 0777
755 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
756 arg['file_list'].append([fl, mode])
758 def SUBDIR_MODE(path, trim_path=None):
759 pd = {'trim_path': trim_path, 'file_list': []}
760 os.path.walk(path, SUBDIR_MODE_callback, pd)
761 return pd['file_list']
763 event_script_subdirs = [
771 if bld.env.standalone_ctdb:
774 configdir = 'ctdb/config'
776 for t in event_script_subdirs:
777 bld.INSTALL_DIR(os.path.join(bld.env.CTDB_ETCDIR, t))
778 files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
780 bld.INSTALL_FILES(bld.env.CTDB_DATADIR, 'config/%s' % fmode[0],
781 destname=fmode[0], chmod=fmode[1])
783 for t in etc_subdirs:
784 files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
786 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
787 destname=fmode[0], chmod=fmode[1])
789 # If this is a direct install and there are no event scripts
790 # linked/enabled then enable some standard ones
791 if os.environ.get('DESTDIR') is None:
792 fmt = 'events/legacy/%s.script'
793 required_script = '00.ctdb'
794 required_path = os.path.join(bld.env.CTDB_ETCDIR,
795 fmt % (required_script))
796 if not os.path.islink(required_path) and \
797 not os.path.exists(required_path):
798 default_scripts = [ required_script,
803 for t in default_scripts:
804 tgt = os.path.join(bld.env.CTDB_DATADIR, fmt % (t))
805 name = os.path.join(bld.env.CTDB_ETCDIR, fmt % (t))
806 bld.symlink_as(name, tgt)
808 bld.SAMBA_GENERATOR('ctdb-functions',
809 source='config/functions',
811 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
812 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
815 'ctdb-crash-cleanup.sh',
816 'debug-hung-script.sh',
818 'nfs-linux-kernel-callout',
823 for t in etc_scripts:
824 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
825 destname=t, chmod=0755)
827 bld.SAMBA_GENERATOR('ctdb-sudoers',
828 source='config/ctdb.sudoers',
829 target='ctdb.sudoers',
830 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
831 bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
834 bld.INSTALL_FILES('${CTDB_ETCDIR}/events/notification',
835 'config/notification.README',
838 bld.install_dir(bld.env.CTDB_LOGDIR)
839 bld.install_dir(bld.env.CTDB_RUNDIR)
840 bld.install_dir(bld.env.CTDB_VARDIR)
842 for d in ['volatile', 'persistent', 'state']:
843 bld.install_dir(os.path.join(bld.env.CTDB_VARDIR, d))
845 bld.SAMBA_BINARY('errcode',
846 source='tests/src/errcode.c',
848 install_path='${CTDB_TEST_LIBEXECDIR}')
868 for target in ctdb_unit_tests:
869 src = 'tests/src/' + target + '.c'
871 bld.SAMBA_BINARY(target,
873 deps='''talloc tevent tdb tevent-util popt
874 LIBASYNC_REQ samba-util sys_rw''',
875 install_path='${CTDB_TEST_LIBEXECDIR}')
877 bld.SAMBA_BINARY('reqid_test',
878 source='tests/src/reqid_test.c',
880 install_path='${CTDB_TEST_LIBEXECDIR}')
882 bld.SAMBA_BINARY('rb_test',
883 source='tests/src/rb_test.c',
884 deps='samba-util talloc',
885 install_path='${CTDB_TEST_LIBEXECDIR}')
887 bld.SAMBA_BINARY('ctdb_packet_parse',
888 source='tests/src/ctdb_packet_parse.c',
889 deps='talloc tevent tdb ctdb-protocol',
890 install_path='${CTDB_TEST_LIBEXECDIR}')
892 bld.SAMBA_BINARY('porting_tests',
893 source='tests/src/porting_tests.c',
894 deps='samba-util ctdb-system popt',
895 install_path='${CTDB_TEST_LIBEXECDIR}')
897 bld.SAMBA_BINARY('sock_daemon_test',
898 source='tests/src/sock_daemon_test.c',
899 deps='''ctdb-system talloc tevent tevent-util
900 LIBASYNC_REQ samba-util sys_rw''',
901 install_path='${CTDB_TEST_LIBEXECDIR}')
903 bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-basic',
904 source=bld.SUBDIR('tests/src',
905 'protocol_common_basic.c'),
906 deps='replace talloc')
908 bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-common',
909 source=bld.SUBDIR('tests/src',
911 protocol_common_ctdb.c
914 deps='ctdb-protocol-tests-basic replace talloc tdb')
916 bld.SAMBA_BINARY('protocol_basic_test',
917 source=bld.SUBDIR('tests/src', 'protocol_basic_test.c'),
918 deps='ctdb-protocol-tests-basic talloc',
919 install_path='${CTDB_TEST_LIBEXECDIR}')
921 ctdb_protocol_tests = [
922 'protocol_types_test',
923 'protocol_ctdb_test',
924 'protocol_util_test',
925 'protocol_types_compat_test',
926 'protocol_ctdb_compat_test',
929 for target in ctdb_protocol_tests:
930 src = 'tests/src/' + target + '.c'
932 bld.SAMBA_BINARY(target,
934 deps='''ctdb-protocol-tests-common
935 samba-util talloc tdb''',
936 install_path='${CTDB_TEST_LIBEXECDIR}')
938 bld.SAMBA_BINARY('event_protocol_test',
939 source='event/event_protocol_test.c',
940 deps='''ctdb-protocol-tests-basic
941 ctdb-protocol-basic talloc''',
942 install_path='${CTDB_TEST_LIBEXECDIR}')
944 bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
945 source=bld.SUBDIR('tests/src',
946 'cluster_wait.c test_options.c'),
948 deps='samba-util replace popt talloc tevent tdb')
958 'fetch_readonly_loop',
961 'update_record_persistent',
968 for target in ctdb_tests:
969 src = 'tests/src/' + target + '.c'
971 bld.SAMBA_BINARY(target,
974 deps='''ctdb-client ctdb-protocol ctdb-util
975 samba-util ctdb-tests-common''',
976 install_path='${CTDB_TEST_LIBEXECDIR}')
978 bld.SAMBA_BINARY('ctdb_takeover_tests',
979 source='''tests/src/ctdb_takeover_tests.c
980 tests/src/ipalloc_read_known_ips.c''',
981 deps='''replace popt tdb tevent talloc ctdb-system
982 samba-util tdb-wrap talloc_report
983 ctdb-ipalloc ctdb-protocol ctdb-util''',
985 install_path='${CTDB_TEST_LIBEXECDIR}')
987 bld.SAMBA_BINARY('fake_ctdbd',
988 source='''tests/src/fake_ctdbd.c
989 tests/src/ipalloc_read_known_ips.c''',
990 deps='''ctdb-util ctdb-protocol ctdb-protocol-util
991 ctdb-system samba-util tevent-util
992 LIBASYNC_REQ popt''',
993 install_path='${CTDB_TEST_LIBEXECDIR}')
995 if bld.env.HAVE_INFINIBAND:
996 bld.SAMBA_BINARY('ibwrapper_test',
997 source='ib/ibwrapper_test.c',
999 deps='replace talloc ctdb-common sys_rw' +
1001 install_path='${CTDB_TEST_LIBEXECDIR}')
1003 if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
1004 bld.SAMBA_BINARY('test_mutex_raw',
1005 source='tests/src/test_mutex_raw.c',
1007 install_path='${CTDB_TEST_LIBEXECDIR}')
1023 if bld.env.standalone_ctdb:
1026 testdir = 'ctdb/tests'
1028 for t in test_subdirs:
1029 files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
1031 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
1032 destname=fmode[0], chmod=fmode[1])
1034 # Install tests/scripts directory without test_wrap
1041 for t in test_scripts:
1042 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
1043 os.path.join('tests/scripts', t),
1044 destname=os.path.join('scripts', t))
1046 sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
1047 bld.env.CTDB_TEST_LIBEXECDIR)
1048 bld.SAMBA_GENERATOR('ctdb-test-wrap',
1049 source='tests/scripts/test_wrap',
1051 rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
1052 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
1053 destname='test_wrap', chmod=0755)
1055 bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
1056 source='tests/scripts/script_install_paths.sh',
1057 target='script_install_paths.sh',
1058 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
1059 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
1060 'script_install_paths.sh',
1061 destname='script_install_paths.sh', chmod=0644)
1063 sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
1064 'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
1065 'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
1066 sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
1067 bld.SAMBA_GENERATOR('ctdb-test-runner',
1068 source='tests/run_tests.sh',
1069 target='ctdb_run_tests.sh',
1070 rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
1071 sed_expr1, sed_expr2))
1072 bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
1073 destname='ctdb_run_tests', chmod=0755)
1074 bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
1079 cmd = 'tests/run_tests.sh -V tests/var'
1080 ret = samba_utils.RUN_COMMAND(cmd)
1082 print('tests exited with exit status %d' % ret)
1088 Scripting.commands.append('build')
1089 Scripting.commands.append('testonly')
1093 env = samba_utils.LOAD_ENVIRONMENT()
1094 cmd = 'tests/run_tests.sh -e -S %s -C' % env.SOCKET_WRAPPER_SO_PATH
1095 ret = samba_utils.RUN_COMMAND(cmd)
1097 print('autotest exited with exit status %d' % ret)
1101 def show_version(ctx):
1106 BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
1107 MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
1108 HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
1109 CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
1110 manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1112 cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
1113 ret = samba_utils.RUN_COMMAND(cmd)
1115 print('Command %s failed with exit status %d' % (cmd, ret))
1118 cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
1119 ret = samba_utils.RUN_COMMAND(cmd)
1121 print('Command %s failed with exit status %d' % (cmd, ret))
1126 samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
1128 distfile = file('.distversion', 'w')
1129 for field in version.vcs_fields:
1130 distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
1132 samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
1135 sed_expr1 = 's/@VERSION@/%s/g' % VERSION
1136 sed_expr2 = 's/@RELEASE@/%s/g' % '1'
1137 cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
1138 sed_expr1, sed_expr2, t)
1139 ret = samba_utils.RUN_COMMAND(cmd)
1141 print('Command "%s" failed with exit status %d' % (cmd, ret))
1143 samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
1145 manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1147 samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1148 samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1156 Scripting.commands.append('manpages')
1157 Scripting.commands.append('distonly')
1161 opts = os.getenv('RPM_OPTIONS') or ''
1162 cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
1163 ret = samba_utils.RUN_COMMAND(cmd)
1165 print('rpmbuild exited with exit status %d' % ret)
1171 Scripting.commands.append('manpages')
1172 Scripting.commands.append('distonly')
1173 Scripting.commands.append('rpmonly')
1177 "build 'tags' file using ctags"
1179 source_root = os.path.dirname(Utils.g_module.root_path)
1180 cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1181 print("Running: %s" % cmd)
1182 ret = samba_utils.RUN_COMMAND(cmd)
1184 print('ctags failed with exit status %d' % ret)