WHATSNEW: Fix release date.
[Samba.git] / ctdb / wscript
blobad53bb92b60c67dff1b74b98514b8dd0814d6313
1 #!/usr/bin/env python
3 APPNAME = 'ctdb'
5 blddir = 'bin'
7 import sys, os
9 # find the buildtools directory
10 srcdir = '.'
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'):
20 vdir = '.'
21 elif os.path.isfile('../VERSION'):
22 vdir = '..'
23 else:
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 lib/socket_wrapper:lib/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''')
40 manpages_binary = [
41 'ctdb.1',
42 'ctdbd.1',
43 'ltdbtool.1',
44 'ping_pong.1'
47 manpages_misc = [
48 'ctdb_diagnostics.1',
49 'ctdbd_wrapper.1',
50 'onnode.1',
51 'ctdbd.conf.5',
52 'ctdb.7',
53 'ctdb-statistics.7',
54 'ctdb-tunables.7',
57 manpages_etcd = [
58 'ctdb-etcd.7',
61 manpages_ceph = [
62 'ctdb_mutex_ceph_rados_helper.7',
66 def set_options(opt):
67 opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
69 opt.RECURSE('lib/replace')
71 opt.RECURSE('lib/util')
73 opt.RECURSE('lib/talloc')
74 opt.RECURSE('lib/tevent')
75 opt.RECURSE('lib/tdb')
77 opt.add_option('--enable-infiniband',
78 help=("Turn on infiniband support (default=no)"),
79 action="store_true", dest='ctdb_infiniband', default=False)
80 opt.add_option('--enable-pmda',
81 help=("Turn on PCP pmda support (default=no)"),
82 action="store_true", dest='ctdb_pmda', default=False)
83 opt.add_option('--enable-etcd-reclock',
84 help=("Enable etcd recovery lock helper (default=no)"),
85 action="store_true", dest='ctdb_etcd_reclock', default=False)
86 opt.add_option('--enable-ceph-reclock',
87 help=("Enable Ceph CTDB recovery lock helper (default=no)"),
88 action="store_true", dest='ctdb_ceph_reclock', default=False)
90 opt.add_option('--with-logdir',
91 help=("Path to log directory"),
92 action="store", dest='ctdb_logdir', default=None)
93 opt.add_option('--with-socketpath',
94 help=("path to CTDB daemon socket"),
95 action="store", dest='ctdb_sockpath', default=None)
98 def configure(conf):
100 # No need to build python bindings for talloc/tevent/tdb
101 if conf.IN_LAUNCH_DIR():
102 conf.env.standalone_ctdb = True
103 Options.options.disable_python = True
105 conf.RECURSE('lib/replace')
107 if conf.env.standalone_ctdb:
108 conf.SAMBA_CHECK_PERL(mandatory=True)
110 conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,5,0))
111 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
113 if conf.CHECK_FOR_THIRD_PARTY():
114 conf.RECURSE('third_party/popt')
115 else:
116 if not conf.CHECK_POPT():
117 raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
118 else:
119 conf.define('USING_SYSTEM_POPT', 1)
121 conf.RECURSE('lib/util')
123 conf.RECURSE('lib/talloc')
124 conf.RECURSE('lib/tevent')
125 conf.RECURSE('lib/tdb')
126 if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
127 conf.RECURSE('lib/socket_wrapper')
128 conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
130 conf.CHECK_HEADERS('sched.h')
131 conf.CHECK_HEADERS('procinfo.h')
132 if sys.platform.startswith('aix') and not conf.CHECK_FUNCS('thread_setsched'):
133 Logs.error('Need thread_setsched() on AIX')
134 sys.exit(1)
135 elif not conf.CHECK_FUNCS('sched_setscheduler'):
136 Logs.error('Need sched_setscheduler()')
137 sys.exit(1)
138 conf.CHECK_FUNCS('mlockall')
140 if not conf.CHECK_VARIABLE('ETIME', headers='errno.h'):
141 conf.DEFINE('ETIME', 'ETIMEDOUT')
143 if sys.platform.startswith('linux'):
144 conf.SET_TARGET_TYPE('pcap', 'EMPTY')
145 else:
146 if not conf.CHECK_HEADERS('pcap.h'):
147 Logs.error('Need libpcap')
148 sys.exit(1)
149 if not conf.CHECK_FUNCS_IN('pcap_open_live', 'pcap', headers='pcap.h'):
150 Logs.error('Need libpcap')
151 sys.exit(1)
153 if not conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo',
154 checklibc=True, headers='execinfo.h'):
155 Logs.error('backtrace support not available')
157 have_pmda = False
158 if Options.options.ctdb_pmda:
159 pmda_support = True
161 if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
162 together=True):
163 pmda_support = False
164 if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
165 pmda_support = False
166 if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
167 pmda_support = False
168 if pmda_support:
169 have_pmda = True
170 else:
171 Logs.error("PMDA support not available")
172 sys.exit(1)
173 if have_pmda:
174 Logs.info('Building with PMDA support')
175 conf.define('HAVE_PMDA', 1)
176 conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
177 'lib/pcp/pmdas/ctdb')
179 have_infiniband = False
180 if Options.options.ctdb_infiniband:
181 ib_support = True
183 if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
184 ib_support = False
185 if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
186 ib_support = False
187 if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
188 ib_support = False
189 if ib_support:
190 have_infiniband = True
191 else:
192 Logs.error("Infiniband support not available")
193 sys.exit(1)
194 if have_infiniband:
195 Logs.info('Building with Infiniband support')
196 conf.define('HAVE_INFINIBAND', 1)
197 conf.define('USE_INFINIBAND', 1)
199 have_etcd_reclock = False
200 if Options.options.ctdb_etcd_reclock:
201 try:
202 conf.check_python_module('etcd')
203 have_etcd_reclock = True
204 except:
205 Logs.error('etcd support not available')
206 sys.exit(1)
207 if have_etcd_reclock:
208 Logs.info('Building with etcd support')
209 conf.env.etcd_reclock = have_etcd_reclock
211 if Options.options.ctdb_ceph_reclock:
212 if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
213 conf.CHECK_LIB('rados', shlib=True)):
214 Logs.info('Building with Ceph librados recovery lock support')
215 conf.define('HAVE_LIBRADOS', 1)
216 else:
217 Logs.error("Missing librados for Ceph recovery lock support")
218 sys.exit(1)
220 conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
221 conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
222 conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
223 conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
224 conf.env.CTDB_HELPER_BINDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb')
226 if Options.options.ctdb_logdir:
227 conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
228 else:
229 conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
231 if Options.options.ctdb_sockpath:
232 conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
233 else:
234 conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
235 'ctdbd.socket')
236 conf.define('CTDB_SOCKET', conf.env.CTDB_SOCKPATH)
238 conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
239 -DLOGDIR=\"%s\"
240 -DCTDB_ETCDIR=\"%s\"
241 -DCTDB_VARDIR=\"%s\"
242 -DCTDB_RUNDIR=\"%s\"''' % (
243 conf.env.CTDB_HELPER_BINDIR,
244 conf.env.CTDB_LOGDIR,
245 conf.env.CTDB_ETCDIR,
246 conf.env.CTDB_VARDIR,
247 conf.env.CTDB_RUNDIR))
249 conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
250 'share/ctdb/tests')
251 conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
253 # Allow unified compilation and separate compilation of utilities
254 # to find includes
255 if not conf.env.standalone_ctdb:
256 conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
257 else:
258 if srcdir == '.':
259 # Building from tarball
260 conf.ADD_EXTRA_INCLUDES('#include')
261 else:
262 # Building standalone CTDB from within Samba tree
263 conf.ADD_EXTRA_INCLUDES('#ctdb/include')
264 conf.ADD_EXTRA_INCLUDES('#ctdb')
265 conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
267 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
268 conf.DEFINE('SAMBA_UTIL_CORE_ONLY', 1, add_to_cflags=True)
269 conf.SAMBA_CONFIG_H()
271 if 'XSLTPROC_MANPAGES' in conf.env and conf.env['XSLTPROC_MANPAGES']:
272 conf.env.ctdb_generate_manpages = True
273 else:
274 conf.env.ctdb_generate_manpages = False
276 Logs.info("xsltproc unavailable, checking for pre-built manpages")
277 conf.env.ctdb_prebuilt_manpages = []
278 manpages = manpages_binary + manpages_misc
279 if conf.env.etcd_reclock:
280 manpages += manpages_etcd
281 if conf.env.HAVE_LIBRADOS:
282 manpages += manpages_ceph
283 for m in manpages:
284 if os.path.exists(os.path.join("doc", m)):
285 Logs.info(" %s: yes" % (m))
286 conf.env.ctdb_prebuilt_manpages.append(m)
287 else:
288 Logs.info(" %s: no" % (m))
290 def gen_ctdb_version(task):
291 fp = file(task.outputs[0].bldpath(task.env), 'w')
292 fp.write('/* This file is auto-generated from waf */\n')
293 fp.write('#include "version.h"\n')
294 fp.write('\n')
295 fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
296 fp.close()
299 def build(bld):
300 if bld.env.standalone_ctdb:
301 # enable building of public headers in the build tree
302 bld.env.build_public_headers = 'include/public'
304 if bld.env.standalone_ctdb:
305 bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
307 t = bld.SAMBA_GENERATOR('ctdb-version-header',
308 target='include/ctdb_version.h',
309 rule=gen_ctdb_version,
310 dep_vars=['VERSION'])
311 t.env.VERSION = VERSION
313 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
315 bld.RECURSE('lib/replace')
316 if bld.CHECK_FOR_THIRD_PARTY():
317 bld.RECURSE('third_party/popt')
319 bld.RECURSE('lib/tdb_wrap')
320 bld.RECURSE('lib/util')
321 bld.RECURSE('lib/async_req')
323 bld.RECURSE('lib/talloc')
324 bld.RECURSE('lib/tevent')
325 bld.RECURSE('lib/tdb')
326 if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
327 bld.RECURSE('lib/socket_wrapper')
329 if bld.env.standalone_ctdb:
330 # If a combined build is implemented, CTDB will want to
331 # build against samba-util rather than samba-util-core.
332 # Similarly, other Samba subsystems expect samba-util. So,
333 # for a standalone build, just define a fake samba-util
334 # subsystem that pulls in samba-util-core.
335 bld.SAMBA_SUBSYSTEM('samba-util',
336 source='',
337 deps='samba-util-core')
339 bld.SAMBA_SUBSYSTEM('ctdb-tcp',
340 source=bld.SUBDIR('tcp',
341 'tcp_connect.c tcp_init.c tcp_io.c'),
342 includes='include',
343 deps='replace tdb talloc tevent')
345 ib_deps = ''
346 if bld.env.HAVE_INFINIBAND:
347 bld.SAMBA_SUBSYSTEM('ctdb-ib',
348 source=bld.SUBDIR('ib',
349 '''ibwrapper.c ibw_ctdb.c
350 ibw_ctdb_init.c'''),
351 includes='include',
352 deps='replace talloc tevent tdb')
353 ib_deps = ' ctdb-ib rdmacm ibverbs'
355 if sys.platform.startswith('linux'):
356 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
357 elif sys.platform.startswith('aix'):
358 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
359 elif sys.platform.startswith('freebsd'):
360 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
361 elif sys.platform.startswith('gnukfreebsd'):
362 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
363 elif sys.platform == 'gnu':
364 CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
365 else:
366 Logs.error("Platform %s not supported" % sys.platform)
368 bld.SAMBA_SUBSYSTEM('ctdb-system',
369 source=bld.SUBDIR('common',
370 'system_common.c system_util.c') +
371 CTDB_SYSTEM_SRC,
372 includes='include',
373 deps='replace talloc tevent tdb pcap samba-util')
375 bld.SAMBA_SUBSYSTEM('ctdb-common',
376 source=bld.SUBDIR('common',
377 '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
378 sock_io.c'''),
379 includes='include',
380 deps='replace popt talloc tevent tdb popt ctdb-system')
382 bld.SAMBA_SUBSYSTEM('ctdb-util',
383 source=bld.SUBDIR('common',
384 '''db_hash.c srvid.c reqid.c
385 pkt_read.c pkt_write.c comm.c
386 logging.c rb_tree.c tunable.c
387 pidfile.c run_proc.c
388 hash_count.c run_event.c'''),
389 deps='''samba-util sys_rw tevent-util
390 replace talloc tevent tdb''')
392 bld.SAMBA_SUBSYSTEM('ctdb-protocol',
393 source=bld.SUBDIR('protocol',
394 '''protocol_header.c protocol_packet.c
395 protocol_types.c protocol_call.c
396 protocol_message.c
397 protocol_control.c
398 protocol_client.c
399 protocol_debug.c
400 protocol_util.c
401 protocol_event.c'''),
402 includes='include',
403 deps='replace talloc tdb')
405 bld.SAMBA_SUBSYSTEM('ctdb-client',
406 source=bld.SUBDIR('client', 'ctdb_client.c'),
407 includes='include',
408 deps='''replace popt talloc tevent tdb
409 samba-util tdb-wrap ctdb-util''')
411 bld.SAMBA_SUBSYSTEM('ctdb-client2',
412 source=bld.SUBDIR('client',
413 '''client_connect.c client_call.c
414 client_message.c client_control.c
415 client_message_sync.c
416 client_control_sync.c
417 client_db.c client_util.c
418 client_event.c
419 '''),
420 includes='include',
421 deps='replace talloc tevent tdb tdb-wrap')
423 bld.SAMBA_SUBSYSTEM('ctdb-server-util',
424 source=bld.SUBDIR('common',
425 '''sock_daemon.c'''),
426 deps='''samba-util ctdb-util tevent-util
427 replace talloc tevent''')
429 bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
430 source=bld.SUBDIR('server',
431 '''ipalloc_deterministic.c
432 ipalloc_nondeterministic.c
433 ipalloc_lcp2.c
434 ipalloc_common.c
435 ipalloc.c
436 '''),
437 includes='include',
438 deps='ctdb-protocol replace talloc tevent')
440 bld.SAMBA_BINARY('ctdbd',
441 source='server/ctdbd.c ' +
442 bld.SUBDIR('server',
443 '''ctdb_daemon.c ctdb_recoverd.c
444 ctdb_recover.c ctdb_freeze.c
445 ctdb_tunables.c ctdb_monitor.c
446 ctdb_server.c ctdb_control.c
447 ctdb_call.c ctdb_ltdb_server.c
448 ctdb_traverse.c eventscript.c
449 ctdb_takeover.c
450 ctdb_persistent.c ctdb_keepalive.c
451 ctdb_cluster_mutex.c
452 ctdb_logging.c
453 ctdb_uptime.c
454 ctdb_vacuum.c ctdb_banning.c
455 ctdb_statistics.c
456 ctdb_update_record.c
457 ctdb_lock.c ctdb_fork.c'''),
458 includes='include',
459 deps='''ctdb-ipalloc ctdb-client ctdb-common ctdb-system
460 ctdb-tcp ctdb-util replace sys_rw popt
461 talloc tevent tdb talloc_report''' +
462 ib_deps,
463 install_path='${SBINDIR}',
464 manpages='ctdbd.1')
466 bld.SAMBA_BINARY('ctdb',
467 source='tools/ctdb.c',
468 deps='''ctdb-client2 ctdb-protocol ctdb-util ctdb-system
469 samba-util sys_rw popt''',
470 install_path='${BINDIR}',
471 manpages='ctdb.1')
473 bld.SAMBA_BINARY('ctdb_killtcp',
474 source='tools/ctdb_killtcp.c',
475 deps='''ctdb-protocol ctdb-util ctdb-system
476 samba-util replace''',
477 install_path='${CTDB_HELPER_BINDIR}')
479 bld.SAMBA_BINARY('ctdb_event',
480 source='tools/ctdb_event.c',
481 deps='''ctdb-client2 ctdb-protocol ctdb-util ctdb-system
482 samba-util replace''',
483 install_path='${CTDB_HELPER_BINDIR}')
485 bld.SAMBA_BINARY('ltdbtool',
486 source='tools/ltdbtool.c',
487 includes='include',
488 deps='tdb',
489 install_path='${BINDIR}',
490 manpages='ltdbtool.1')
492 bld.SAMBA_BINARY('ctdb_eventd',
493 source='server/ctdb_eventd.c',
494 deps='''ctdb-server-util ctdb-protocol ctdb-util
495 samba-util LIBASYNC_REQ replace popt''',
496 install_path='${CTDB_HELPER_BINDIR}')
498 bld.SAMBA_BINARY('ctdb_lock_helper',
499 source='server/ctdb_lock_helper.c',
500 deps='''samba-util sys_rw ctdb-system tevent-util
501 talloc tevent tdb''',
502 includes='include',
503 install_path='${CTDB_HELPER_BINDIR}')
505 bld.SAMBA_BINARY('ctdb_recovery_helper',
506 source='server/ctdb_recovery_helper.c',
507 deps='''ctdb-client2 ctdb-protocol ctdb-util
508 samba-util sys_rw replace tdb''',
509 install_path='${CTDB_HELPER_BINDIR}')
511 bld.SAMBA_BINARY('ctdb_takeover_helper',
512 source='server/ctdb_takeover_helper.c',
513 deps='''ctdb-client2 ctdb-protocol ctdb-util
514 samba-util sys_rw replace ctdb-ipalloc popt''',
515 install_path='${CTDB_HELPER_BINDIR}')
517 bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
518 source='server/ctdb_mutex_fcntl_helper.c',
519 deps='sys_rw ctdb-system',
520 includes='include',
521 install_path='${CTDB_HELPER_BINDIR}')
523 bld.SAMBA_GENERATOR('ctdb-smnotify-h',
524 source='utils/smnotify/smnotify.x',
525 target='utils/smnotify/smnotify.h',
526 rule='rpcgen -h ${SRC} > ${TGT}')
528 xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
530 bld.SAMBA_GENERATOR('ctdb-smnotify-x',
531 source='utils/smnotify/smnotify.x',
532 target='utils/smnotify/gen_xdr.c',
533 rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
535 bld.SAMBA_GENERATOR('ctdb-smnotify-c',
536 source='utils/smnotify/smnotify.x',
537 target='utils/smnotify/gen_smnotify.c',
538 rule='rpcgen -l ${SRC} > ${TGT}')
540 bld.SAMBA_BINARY('smnotify',
541 source=bld.SUBDIR('utils/smnotify',
542 'smnotify.c gen_smnotify.c gen_xdr.c'),
543 deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt tirpc',
544 includes='utils utils/smnotify',
545 install_path='${CTDB_HELPER_BINDIR}')
547 bld.SAMBA_BINARY('ping_pong',
548 source='utils/ping_pong/ping_pong.c',
549 deps='',
550 install_path='${BINDIR}',
551 manpages='ping_pong.1')
553 if bld.env.HAVE_PMDA:
554 bld.SAMBA_BINARY('pmdactdb',
555 source='utils/pmda/pmda_ctdb.c',
556 includes='include',
557 deps='''ctdb-client2 ctdb-protocol ctdb-util
558 samba-util pcp_pmda pcp''',
559 install_path='${CTDB_PMDADIR}')
560 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
561 destname='Install')
562 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
563 destname='Remove')
564 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
565 destname='pmns')
566 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
567 destname='domain.h')
568 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
569 destname='help')
570 bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
571 destname='README')
573 if bld.env.HAVE_LIBRADOS:
574 bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
575 source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
576 deps='talloc tevent rados',
577 includes='include',
578 install_path='${CTDB_HELPER_BINDIR}')
580 sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g' % (bld.env.CTDB_VARDIR)
581 sed_expr2 = 's|/usr/local/etc/ctdb|%s|g' % (bld.env.CTDB_ETCDIR)
582 sed_expr3 = 's|/usr/local/var/log|%s|g' % (bld.env.CTDB_LOGDIR)
583 sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g' % (bld.env.CTDB_RUNDIR)
584 sed_expr5 = 's|/usr/local/sbin|%s|g' % (bld.env.SBINDIR)
585 sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g' % (bld.env.CTDB_HELPER_BINDIR)
586 sed_expr7 = 's|/usr/local/bin|%s|g' % (bld.env.BINDIR)
587 sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
588 (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
589 sed_expr6, sed_expr7)
591 manpages_extra = manpages_misc
592 if bld.env.etcd_reclock:
593 manpages_extra += manpages_etcd
594 if bld.env.HAVE_LIBRADOS:
595 manpages_extra += manpages_ceph
596 for f in manpages_binary + manpages_extra:
597 x = '%s.xml' % (f)
598 bld.SAMBA_GENERATOR(x,
599 source=os.path.join('doc', x),
600 target=x,
601 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
603 if bld.env.ctdb_generate_manpages:
604 bld.MANPAGES(' '.join(manpages_extra), True)
605 else:
606 for m in bld.env.ctdb_prebuilt_manpages:
607 bld.SAMBA_GENERATOR(m,
608 source=os.path.join("doc", m),
609 target=m,
610 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
611 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
613 bld.SAMBA_GENERATOR('ctdb-onnode',
614 source='tools/onnode',
615 target='onnode',
616 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
617 bld.INSTALL_FILES('${BINDIR}', 'onnode',
618 destname='onnode', chmod=0755)
620 bld.SAMBA_GENERATOR('ctdb-diagnostics',
621 source='tools/ctdb_diagnostics',
622 target='ctdb_diagnostics',
623 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
624 bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
625 destname='ctdb_diagnostics', chmod=0755)
627 if bld.env.etcd_reclock:
628 bld.SAMBA_GENERATOR('ctdb-etcd-lock',
629 source='utils/etcd/ctdb_etcd_lock',
630 target='ctdb_etcd_lock',
631 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
632 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
633 destname='ctdb_etcd_lock', chmod=0744)
635 bld.SAMBA_GENERATOR('ctdb-natgw',
636 source='tools/ctdb_natgw',
637 target='ctdb_natgw',
638 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
639 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
640 destname='ctdb_natgw', chmod=0755)
642 bld.SAMBA_GENERATOR('ctdb-lvs',
643 source='tools/ctdb_lvs',
644 target='ctdb_lvs',
645 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
646 bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
647 destname='ctdb_lvs', chmod=0755)
649 bld.SAMBA_GENERATOR('ctdbd-wrapper',
650 source='config/ctdbd_wrapper',
651 target='ctdbd_wrapper',
652 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
653 bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
654 destname='ctdbd_wrapper', chmod=0755)
656 def SUBDIR_MODE_callback(arg, dirname, fnames):
657 for f in fnames:
658 fl = os.path.join(dirname, f)
659 if os.path.isdir(fl) or os.path.islink(fl):
660 continue
661 mode = os.lstat(fl).st_mode & 0777
662 if arg['trim_path']:
663 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
664 arg['file_list'].append([fl, mode])
666 def SUBDIR_MODE(path, trim_path=None):
667 pd = {'trim_path': trim_path, 'file_list': []}
668 os.path.walk(path, SUBDIR_MODE_callback, pd)
669 return pd['file_list']
671 etc_subdirs = [
672 'events.d',
673 'nfs-checks.d'
676 if bld.env.standalone_ctdb:
677 configdir = 'config'
678 else:
679 configdir = 'ctdb/config'
681 for t in etc_subdirs:
682 files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
683 for fmode in files:
684 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
685 destname=fmode[0], chmod=fmode[1])
687 bld.SAMBA_GENERATOR('ctdb-functions',
688 source='config/functions',
689 target='functions',
690 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
691 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
693 etc_scripts = [
694 'ctdb-crash-cleanup.sh',
695 'debug-hung-script.sh',
696 'debug_locks.sh',
697 'gcore_trace.sh',
698 'nfs-linux-kernel-callout',
699 'notify.sh',
700 'statd-callout'
703 for t in etc_scripts:
704 bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
705 destname=t, chmod=0755)
707 bld.SAMBA_GENERATOR('ctdb-sudoers',
708 source='config/ctdb.sudoers',
709 target='ctdb.sudoers',
710 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
711 bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
712 destname='ctdb')
714 bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
715 destname='README')
717 bld.install_dir(bld.env.CTDB_LOGDIR)
718 bld.install_dir(bld.env.CTDB_RUNDIR)
719 bld.install_dir(bld.env.CTDB_VARDIR)
721 # Unit tests
722 ctdb_unit_tests = [
723 'db_hash_test',
724 'srvid_test',
725 'pkt_read_test',
726 'pkt_write_test',
727 'comm_test',
728 'comm_server_test',
729 'comm_client_test',
730 'protocol_types_test',
731 'protocol_client_test',
732 'pidfile_test',
733 'run_proc_test',
734 'sock_daemon_test',
735 'sock_io_test',
736 'hash_count_test',
737 'run_event_test',
740 for target in ctdb_unit_tests:
741 src = 'tests/src/' + target + '.c'
743 bld.SAMBA_BINARY(target,
744 source=src,
745 deps='''talloc tevent tdb tevent-util
746 LIBASYNC_REQ samba-util sys_rw''',
747 install_path='${CTDB_TEST_LIBEXECDIR}')
749 bld.SAMBA_BINARY('reqid_test',
750 source='tests/src/reqid_test.c',
751 deps='samba-util',
752 install_path='${CTDB_TEST_LIBEXECDIR}')
754 bld.SAMBA_BINARY('rb_test',
755 source='tests/src/rb_test.c',
756 deps='samba-util talloc',
757 install_path='${CTDB_TEST_LIBEXECDIR}')
759 bld.SAMBA_BINARY('ctdb_packet_parse',
760 source='tests/src/ctdb_packet_parse.c',
761 deps='talloc tevent tdb ctdb-protocol',
762 install_path='${CTDB_TEST_LIBEXECDIR}')
764 bld.SAMBA_BINARY('porting_tests',
765 source='tests/src/porting_tests.c',
766 deps='samba-util ctdb-system popt',
767 install_path='${CTDB_TEST_LIBEXECDIR}')
770 bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
771 source=bld.SUBDIR('tests/src',
772 'cluster_wait.c test_options.c'),
773 includes='include',
774 deps='replace popt talloc tevent tdb')
776 bld.SAMBA_BINARY('protocol_util_test',
777 source='tests/src/protocol_util_test.c',
778 deps='talloc ctdb-protocol samba-util',
779 install_path='${CTDB_TEST_LIBEXECDIR}')
781 # Test binaries
782 ctdb_tests = [
783 'g_lock_loop',
784 'message_ring',
785 'fetch_ring',
786 'fetch_loop',
787 'fetch_loop_key',
788 'fetch_readonly',
789 'fetch_readonly_loop',
790 'transaction_loop',
791 'update_record',
792 'update_record_persistent',
793 'lock_tdb',
794 'dummy_client'
797 for target in ctdb_tests:
798 src = 'tests/src/' + target + '.c'
800 bld.SAMBA_BINARY(target,
801 source=src,
802 includes='include',
803 deps='''ctdb-client2 ctdb-protocol ctdb-util
804 samba-util ctdb-tests-common''',
805 install_path='${CTDB_TEST_LIBEXECDIR}')
807 bld.SAMBA_BINARY('ctdb_takeover_tests',
808 source='''tests/src/ctdb_takeover_tests.c
809 tests/src/ipalloc_read_known_ips.c''',
810 deps='''replace popt tdb tevent talloc ctdb-system
811 samba-util tdb-wrap talloc_report
812 ctdb-ipalloc ctdb-protocol ctdb-util''',
813 includes='include',
814 install_path='${CTDB_TEST_LIBEXECDIR}')
816 bld.SAMBA_BINARY('fake_ctdbd',
817 source='''tests/src/fake_ctdbd.c
818 tests/src/ipalloc_read_known_ips.c''',
819 deps='''ctdb-util ctdb-protocol ctdb-system
820 samba-util tevent-util LIBASYNC_REQ popt''',
821 install_path='${CTDB_TEST_LIBEXECDIR}')
823 if bld.env.HAVE_INFINIBAND:
824 bld.SAMBA_BINARY('ibwrapper_test',
825 source='ib/ibwrapper_test.c',
826 includes='include',
827 deps='replace talloc ctdb-client ctdb-common sys_rw' +
828 ib_deps,
829 install_path='${CTDB_TEST_LIBEXECDIR}')
831 if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
832 bld.SAMBA_BINARY('test_mutex_raw',
833 source='tests/src/test_mutex_raw.c',
834 deps='pthread',
835 install_path='${CTDB_TEST_LIBEXECDIR}')
837 test_subdirs = [
838 'complex',
839 'cunit',
840 'eventd',
841 'events.d',
842 'eventscripts',
843 'onnode',
844 'shellcheck',
845 'simple',
846 'takeover',
847 'takeover_helper',
848 'tool'
851 if bld.env.standalone_ctdb:
852 testdir = 'tests'
853 else:
854 testdir = 'ctdb/tests'
856 for t in test_subdirs:
857 files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
858 for fmode in files:
859 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
860 destname=fmode[0], chmod=fmode[1])
862 # Install tests/scripts directory without test_wrap
863 test_scripts = [
864 'common.sh',
865 'integration.bash',
866 'unit.sh'
869 for t in test_scripts:
870 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
871 os.path.join('tests/scripts', t),
872 destname=os.path.join('scripts', t))
874 sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
875 bld.env.CTDB_TEST_LIBEXECDIR)
876 bld.SAMBA_GENERATOR('ctdb-test-wrap',
877 source='tests/scripts/test_wrap',
878 target='test_wrap',
879 rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
880 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
881 destname='test_wrap', chmod=0755)
883 bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
884 source='tests/scripts/script_install_paths.sh',
885 target='script_install_paths.sh',
886 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
887 bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
888 'script_install_paths.sh',
889 destname='script_install_paths.sh', chmod=0644)
891 sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
892 bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBEXECDIR)
893 sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
894 bld.SAMBA_GENERATOR('ctdb-test-runner',
895 source='tests/run_tests.sh',
896 target='ctdb_run_tests.sh',
897 rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
898 sed_expr1, sed_expr2))
899 bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
900 destname='ctdb_run_tests', chmod=0755)
901 bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
902 'ctdb_run_tests')
904 test_eventscript_links = [
905 'events.d',
906 'functions',
907 'nfs-checks.d',
908 'nfs-linux-kernel-callout',
909 'statd-callout'
912 test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
913 'eventscripts/etc-ctdb')
914 for t in test_eventscript_links:
915 bld.symlink_as(os.path.join(test_link_dir, t),
916 os.path.join(bld.env.CTDB_ETCDIR, t))
918 # Tests that use onnode need to overwrite link to in-tree
919 # functions file when installed
920 bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'onnode/functions'),
921 os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
922 bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/functions'),
923 os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
925 # Need a link to nodes file because $CTDB_BASE is overridden
926 bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/nodes'),
927 os.path.join(bld.env.CTDB_ETCDIR, 'nodes'))
930 def testonly(ctx):
931 cmd = 'tests/run_tests.sh -V tests/var'
932 ret = samba_utils.RUN_COMMAND(cmd)
933 if ret != 0:
934 print('tests exited with exit status %d' % ret)
935 sys.exit(ret)
938 def test(ctx):
939 import Scripting
940 Scripting.commands.append('build')
941 Scripting.commands.append('testonly')
944 def autotest(ctx):
945 env = samba_utils.LOAD_ENVIRONMENT()
946 ld = 'LD_PRELOAD=%s' % env.SOCKET_WRAPPER_SO_PATH
947 cmd = '%s tests/run_tests.sh -e -S -C' % ld
948 ret = samba_utils.RUN_COMMAND(cmd)
949 if ret != 0:
950 print('autotest exited with exit status %d' % ret)
951 sys.exit(ret)
954 def show_version(ctx):
955 print VERSION
958 def manpages(ctx):
959 BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
960 MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
961 HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
962 CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
963 manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
964 for t in manpages:
965 cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
966 ret = samba_utils.RUN_COMMAND(cmd)
967 if ret != 0:
968 print('Command %s failed with exit status %d' % (cmd, ret))
969 sys.exit(ret)
971 cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
972 ret = samba_utils.RUN_COMMAND(cmd)
973 if ret != 0:
974 print('Command %s failed with exit status %d' % (cmd, ret))
975 sys.exit(ret)
978 def distonly(ctx):
979 samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
981 distfile = file('.distversion', 'w')
982 for field in version.vcs_fields:
983 distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
984 distfile.close()
985 samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
987 t = 'ctdb.spec'
988 sed_expr1 = 's/@VERSION@/%s/g' % VERSION
989 sed_expr2 = 's/@RELEASE@/%s/g' % '1'
990 cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
991 sed_expr1, sed_expr2, t)
992 ret = samba_utils.RUN_COMMAND(cmd)
993 if ret != 0:
994 print('Command "%s" failed with exit status %d' % (cmd, ret))
995 sys.exit(ret)
996 samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
998 manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
999 for t in manpages:
1000 samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1001 samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1002 extend=True)
1004 samba_dist.dist()
1007 def dist():
1008 import Scripting
1009 Scripting.commands.append('manpages')
1010 Scripting.commands.append('distonly')
1013 def rpmonly(ctx):
1014 opts = os.getenv('RPM_OPTIONS') or ''
1015 cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
1016 ret = samba_utils.RUN_COMMAND(cmd)
1017 if ret != 0:
1018 print('rpmbuild exited with exit status %d' % ret)
1019 sys.exit(ret)
1022 def rpm(ctx):
1023 import Scripting
1024 Scripting.commands.append('manpages')
1025 Scripting.commands.append('distonly')
1026 Scripting.commands.append('rpmonly')
1029 def ctags(ctx):
1030 "build 'tags' file using ctags"
1031 import Utils
1032 source_root = os.path.dirname(Utils.g_module.root_path)
1033 cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1034 print("Running: %s" % cmd)
1035 ret = samba_utils.RUN_COMMAND(cmd)
1036 if ret != 0:
1037 print('ctags failed with exit status %d' % ret)
1038 sys.exit(ret)