ctdb-recoverd: Make recoverd context available in recovery lock handle
[vlendec/samba-autobuild/.git] / ctdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ctdb'
4
5 import sys, os
6
7 # find the buildtools directory
8 top = '.'
9 while not os.path.exists(top+'/buildtools') and len(top.split('/')) < 5:
10     top = top + '/..'
11 sys.path.insert(0, top + '/buildtools/wafsamba')
12
13 out = 'bin'
14
15 from waflib import Options, Logs, Errors, Context
16 import wafsamba
17 from wafsamba import samba_dist, samba_utils
18 from samba_utils import MODE_644, MODE_744, MODE_755, MODE_777
19
20 if os.path.isfile('./VERSION'):
21     vdir = '.'
22 elif os.path.isfile('../VERSION'):
23     vdir = '..'
24 else:
25     Logs.error("VERSION file not found")
26
27 default_prefix = Options.default_prefix = '/usr/local'
28
29 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
30                         lib/tevent:lib/tevent lib/tdb:lib/tdb
31                         third_party/socket_wrapper:third_party/socket_wrapper
32                         third_party/popt:third_party/popt
33                         lib/util:lib/util lib/tdb_wrap:lib/tdb_wrap
34                         lib/ccan:lib/ccan libcli/util:libcli/util
35                         lib/async_req:lib/async_req
36                         buildtools:buildtools third_party/waf:third_party/waf''')
37
38 manpages_binary = [
39     'ctdb.1',
40     'ctdbd.1',
41     'ltdbtool.1',
42     'ping_pong.1'
43 ]
44
45 manpages_misc = [
46     'ctdb_diagnostics.1',
47     'ctdbd_wrapper.1',
48     'onnode.1',
49     'ctdb.conf.5',
50     'ctdb-script.options.5',
51     'ctdb.sysconfig.5',
52     'ctdb.7',
53     'ctdb-statistics.7',
54     'ctdb-tunables.7',
55 ]
56
57 manpages_etcd = [
58     'ctdb-etcd.7',
59 ]
60
61 manpages_ceph = [
62     'ctdb_mutex_ceph_rados_helper.7',
63 ]
64
65 VERSION = ''
66
67 def get_version():
68     import samba_version
69     env = samba_utils.LOAD_ENVIRONMENT()
70
71     return samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
72
73 def get_version_string():
74     if Context.g_module.VERSION:
75         return Context.g_module.VERSION
76     version = get_version()
77     Context.g_module.VERSION = version.STRING.replace('-', '.')
78     return Context.g_module.VERSION
79
80 def options(opt):
81     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
82
83     opt.RECURSE('lib/replace')
84
85     opt.RECURSE('lib/util')
86
87     opt.RECURSE('lib/talloc')
88     opt.RECURSE('lib/tevent')
89     opt.RECURSE('lib/tdb')
90
91     opt.add_option('--enable-infiniband',
92                    help=("Turn on infiniband support (default=no)"),
93                    action="store_true", dest='ctdb_infiniband', default=False)
94     opt.add_option('--enable-pmda',
95                    help=("Turn on PCP pmda support (default=no)"),
96                    action="store_true", dest='ctdb_pmda', default=False)
97     opt.add_option('--enable-etcd-reclock',
98                    help=("Enable etcd recovery lock helper (default=no)"),
99                    action="store_true", dest='ctdb_etcd_reclock', default=False)
100
101     opt.add_option('--with-libcephfs',
102                    help=("Directory under which libcephfs is installed"),
103                    action="store", dest='libcephfs_dir', default=None)
104     opt.add_option('--enable-ceph-reclock',
105                    help=("Enable Ceph CTDB recovery lock helper (default=no)"),
106                    action="store_true", dest='ctdb_ceph_reclock', default=False)
107
108     opt.add_option('--with-logdir',
109                    help=("Path to log directory"),
110                    action="store", dest='ctdb_logdir', default=None)
111     opt.add_option('--with-socketpath',
112                    help=("path to CTDB daemon socket"),
113                    action="store", dest='ctdb_sockpath', default=None)
114
115
116 def configure(conf):
117     # No need to build python bindings for talloc/tevent/tdb
118     if conf.IN_LAUNCH_DIR():
119         conf.env.standalone_ctdb = True
120         Options.options.disable_python = True
121
122     conf.RECURSE('lib/replace')
123
124     conf.CHECK_HEADERS(headers='''sys/socket.h
125                                   netinet/in.h
126                                   netinet/if_ether.h
127                                   netinet/ip.h
128                                   netinet/ip6.h
129                                   netinet/icmp6.h''',
130                        together=True)
131
132     conf.CHECK_CODE('int s = socket(AF_PACKET, SOCK_RAW, 0);',
133                     define='HAVE_AF_PACKET',
134                     headers='sys/socket.h linux/if_packet.h')
135
136     conf.CHECK_CODE('struct sockaddr_ll sall; sall.sll_family = AF_PACKET;',
137                     define='HAVE_PACKETSOCKET',
138                     headers='sys/socket.h linux/if_packet.h')
139
140     if conf.env.standalone_ctdb:
141         conf.SAMBA_CHECK_PERL(mandatory=True)
142
143         conf.SAMBA_CHECK_PYTHON(mandatory=False, version=(2,5,0))
144         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
145
146     if conf.CHECK_FOR_THIRD_PARTY():
147         conf.RECURSE('third_party/popt')
148         if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
149             conf.RECURSE('third_party/socket_wrapper')
150             conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
151     else:
152         if not conf.CHECK_POPT():
153             raise Errors.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
154         else:
155             conf.define('USING_SYSTEM_POPT', 1)
156         conf.env.SOCKET_WRAPPER_SO_PATH = ''
157
158
159         if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
160             if not conf.CHECK_SOCKET_WRAPPER():
161                 raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
162             else:
163                 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
164                 conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
165
166     conf.RECURSE('lib/util')
167
168     conf.RECURSE('lib/talloc')
169     conf.RECURSE('lib/tevent')
170     conf.RECURSE('lib/tdb')
171
172     conf.CHECK_HEADERS('sched.h')
173     conf.CHECK_HEADERS('procinfo.h')
174     if sys.platform.startswith('aix') and not conf.CHECK_FUNCS('thread_setsched'):
175         Logs.error('Need thread_setsched() on AIX')
176         sys.exit(1)
177     elif not conf.CHECK_FUNCS('sched_setscheduler'):
178         Logs.error('Need sched_setscheduler()')
179         sys.exit(1)
180     conf.CHECK_FUNCS('mlockall')
181
182     if not conf.CHECK_VARIABLE('ETIME', headers='errno.h'):
183         conf.DEFINE('ETIME', 'ETIMEDOUT')
184
185     if sys.platform.startswith('linux'):
186         conf.SET_TARGET_TYPE('pcap', 'EMPTY')
187     else:
188         if not conf.CHECK_HEADERS('pcap.h'):
189             Logs.error('Need libpcap')
190             sys.exit(1)
191         if not conf.CHECK_FUNCS_IN('pcap_open_live', 'pcap', headers='pcap.h'):
192             Logs.error('Need libpcap')
193             sys.exit(1)
194
195     if not conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo',
196                                checklibc=True, headers='execinfo.h'):
197         Logs.error('backtrace support not available')
198
199     have_pmda = False
200     if Options.options.ctdb_pmda:
201         pmda_support = True
202
203         if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
204                                   together=True):
205             pmda_support = False
206         if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
207             pmda_support = False
208         if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
209             pmda_support = False
210         if pmda_support:
211             conf.CHECK_TYPE_IN('__pmID_int', 'pcp/pmapi.h pcp/impl.h')
212             have_pmda = True
213         else:
214             Logs.error("PMDA support not available")
215             sys.exit(1)
216     if have_pmda:
217         Logs.info('Building with PMDA support')
218         conf.define('HAVE_PMDA', 1)
219         conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
220                                              'lib/pcp/pmdas/ctdb')
221
222     have_infiniband = False
223     if Options.options.ctdb_infiniband:
224         ib_support = True
225
226         if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
227             ib_support = False
228         if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
229             ib_support = False
230         if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
231             ib_support = False
232         if ib_support:
233             have_infiniband = True
234         else:
235             Logs.error("Infiniband support not available")
236             sys.exit(1)
237     if have_infiniband:
238         Logs.info('Building with Infiniband support')
239         conf.define('HAVE_INFINIBAND', 1)
240         conf.define('USE_INFINIBAND', 1)
241
242     have_etcd_reclock = False
243     if Options.options.ctdb_etcd_reclock:
244         try:
245             conf.check_python_module('etcd')
246             have_etcd_reclock = True
247         except:
248             Logs.error('etcd support not available')
249             sys.exit(1)
250     if have_etcd_reclock:
251         Logs.info('Building with etcd support')
252     conf.env.etcd_reclock = have_etcd_reclock
253
254     if Options.options.ctdb_ceph_reclock:
255         # Use custom libcephfs library path if provided. XXX The top level build
256         # explicitly sets LIBPATH_CEPH-COMMON when libcephfs_dir isn't provided.
257         if Options.options.libcephfs_dir:
258             conf.env['CPPPATH_RADOS'] = Options.options.libcephfs_dir + '/include'
259             conf.env['LIBPATH_RADOS'] = Options.options.libcephfs_dir + '/lib'
260             conf.env['LIBPATH_CEPH-COMMON'] = conf.env['LIBPATH_RADOS'] + '/ceph'
261
262         if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
263                                         conf.CHECK_LIB('rados', shlib=True)):
264             conf.CHECK_LIB('ceph-common', shlib=True)
265             Logs.info('Building with Ceph librados recovery lock support')
266             conf.define('HAVE_LIBRADOS', 1)
267         else:
268             Logs.error("Missing librados for Ceph recovery lock support")
269             sys.exit(1)
270
271     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
272     conf.env.CTDB_DATADIR = os.path.join(conf.env.EXEC_PREFIX, 'share/ctdb')
273     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
274     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
275     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
276     conf.env.CTDB_HELPER_BINDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb')
277
278     if Options.options.ctdb_logdir:
279         conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
280     else:
281         conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
282
283     if Options.options.ctdb_sockpath:
284         conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
285     else:
286         conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
287                                               'ctdbd.socket')
288     conf.define('CTDB_SOCKET', conf.env.CTDB_SOCKPATH)
289
290     conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
291                        -DLOGDIR=\"%s\"
292                        -DCTDB_DATADIR=\"%s\"
293                        -DCTDB_ETCDIR=\"%s\"
294                        -DCTDB_VARDIR=\"%s\"
295                        -DCTDB_RUNDIR=\"%s\"''' % (
296                     conf.env.CTDB_HELPER_BINDIR,
297                     conf.env.CTDB_LOGDIR,
298                     conf.env.CTDB_DATADIR,
299                     conf.env.CTDB_ETCDIR,
300                     conf.env.CTDB_VARDIR,
301                     conf.env.CTDB_RUNDIR))
302
303     conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.CTDB_DATADIR, 'tests')
304     conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
305
306     # Allow unified compilation and separate compilation of utilities
307     # to find includes
308     if not conf.env.standalone_ctdb:
309         conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
310     else:
311         if Context.g_module.top == '.':
312             # Building from tarball
313             conf.ADD_EXTRA_INCLUDES('#include')
314         else:
315             # Building standalone CTDB from within Samba tree
316             conf.ADD_EXTRA_INCLUDES('#ctdb/include')
317             conf.ADD_EXTRA_INCLUDES('#ctdb')
318         conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
319
320         conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
321         conf.DEFINE('SAMBA_UTIL_CORE_ONLY', 1, add_to_cflags=True)
322         conf.SAMBA_CONFIG_H()
323
324     if 'XSLTPROC_MANPAGES' in conf.env and conf.env['XSLTPROC_MANPAGES']:
325         conf.env.ctdb_generate_manpages = True
326     else:
327         conf.env.ctdb_generate_manpages = False
328
329         Logs.info("xsltproc unavailable, checking for pre-built manpages")
330         conf.env.ctdb_prebuilt_manpages = []
331         manpages = manpages_binary + manpages_misc
332         if conf.env.etcd_reclock:
333             manpages += manpages_etcd
334         if conf.env.HAVE_LIBRADOS:
335             manpages += manpages_ceph
336         for m in manpages:
337             if os.path.exists(os.path.join("doc", m)):
338                 Logs.info("  %s: yes" % (m))
339                 conf.env.ctdb_prebuilt_manpages.append(m)
340             else:
341                 Logs.info("  %s: no" % (m))
342
343 def gen_ctdb_version(task):
344     fp = open(task.outputs[0].bldpath(task.env), 'w')
345     fp.write('/* This file is auto-generated from waf */\n')
346     fp.write('#include "version.h"\n')
347     fp.write('\n')
348     fp.write('#define CTDB_VERSION_STRING "%s"\n' % get_version_string())
349     fp.close()
350
351
352 def build(bld):
353     if bld.env.standalone_ctdb:
354         # enable building of public headers in the build tree
355         bld.env.build_public_headers = 'include/public'
356
357     if bld.env.standalone_ctdb:
358         bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
359
360     t = bld.SAMBA_GENERATOR('ctdb-version-header',
361                             target='include/ctdb_version.h',
362                             rule=gen_ctdb_version,
363                             dep_vars=['VERSION'])
364     t.env.VERSION = get_version_string()
365
366     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
367
368     bld.RECURSE('lib/replace')
369     if bld.CHECK_FOR_THIRD_PARTY():
370         bld.RECURSE('third_party/popt')
371         if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
372             bld.RECURSE('third_party/socket_wrapper')
373
374     bld.RECURSE('lib/tdb_wrap')
375     bld.RECURSE('lib/util')
376     bld.RECURSE('lib/async_req')
377
378     bld.RECURSE('lib/talloc')
379     bld.RECURSE('lib/tevent')
380     bld.RECURSE('lib/tdb')
381
382     if bld.env.standalone_ctdb:
383         # If a combined build is implemented, CTDB will want to
384         # build against samba-util rather than samba-util-core.
385         # Similarly, other Samba subsystems expect samba-util.  So,
386         # for a standalone build, just define a fake samba-util
387         # subsystem that pulls in samba-util-core.
388         bld.SAMBA_SUBSYSTEM('samba-util',
389                             source='',
390                             deps='samba-util-core')
391
392     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
393                         source=bld.SUBDIR('tcp',
394                                           'tcp_connect.c tcp_init.c tcp_io.c'),
395                         includes='include',
396                         deps='replace tdb talloc tevent')
397
398     ib_deps = ''
399     if bld.env.HAVE_INFINIBAND:
400         bld.SAMBA_SUBSYSTEM('ctdb-ib',
401                             source=bld.SUBDIR('ib',
402                                               '''ibwrapper.c ibw_ctdb.c
403                                                  ibw_ctdb_init.c'''),
404                             includes='include',
405                             deps='replace talloc tevent tdb')
406         ib_deps = ' ctdb-ib rdmacm ibverbs'
407
408     bld.SAMBA_SUBSYSTEM('ctdb-system',
409                         source=bld.SUBDIR('common',
410                                           'system_socket.c system.c'),
411                         includes='include',
412                         deps='replace talloc tevent tdb pcap samba-util')
413
414     bld.SAMBA_SUBSYSTEM('ctdb-common',
415                         source=bld.SUBDIR('common',
416                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
417                                              sock_io.c'''),
418                         includes='include',
419                         deps='''replace popt talloc tevent tdb popt ctdb-system
420                                 ctdb-protocol-util''')
421
422     bld.SAMBA_SUBSYSTEM('ctdb-util',
423                         source=bld.SUBDIR('common',
424                                           '''db_hash.c srvid.c reqid.c
425                                              pkt_read.c pkt_write.c comm.c
426                                              logging.c rb_tree.c tunable.c
427                                              pidfile.c run_proc.c
428                                              hash_count.c
429                                              run_event.c event_script.c
430                                              sock_client.c version.c
431                                              cmdline.c path.c conf.c line.c
432                                           '''),
433                         deps='''samba-util sys_rw tevent-util
434                                 replace talloc tevent tdb popt''')
435
436     bld.SAMBA_SUBSYSTEM('ctdb-logging-conf',
437                         source='common/logging_conf.c',
438                         deps='ctdb-util talloc')
439
440     bld.SAMBA_SUBSYSTEM('ctdb-protocol-basic',
441                         source=bld.SUBDIR('protocol', 'protocol_basic.c'),
442                         deps='talloc tdb')
443
444     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
445                         source=bld.SUBDIR('protocol',
446                                           '''protocol_header.c protocol_packet.c
447                                              protocol_types.c
448                                              protocol_call.c
449                                              protocol_message.c
450                                              protocol_control.c
451                                              protocol_keepalive.c
452                                              protocol_tunnel.c
453                                              protocol_client.c
454                                              protocol_debug.c
455                                              protocol_sock.c'''),
456                         includes='include',
457                         deps='ctdb-protocol-basic replace talloc tdb')
458
459     bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
460                         source='protocol/protocol_util.c',
461                         deps='ctdb-util replace talloc tdb')
462
463     bld.SAMBA_SUBSYSTEM('ctdb-client',
464                         source=bld.SUBDIR('client',
465                                           '''client_connect.c client_call.c
466                                              client_message.c client_control.c
467                                              client_message_sync.c
468                                              client_control_sync.c
469                                              client_db.c client_util.c
470                                              client_tunnel.c
471                                           '''),
472                         includes='include',
473                         deps='replace talloc tevent tdb tdb-wrap')
474
475     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
476                         source=bld.SUBDIR('common',
477                                           '''sock_daemon.c'''),
478                         deps='''samba-util ctdb-util ctdb-system tevent-util
479                                 LIBASYNC_REQ replace talloc tevent''')
480
481     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
482                         source=bld.SUBDIR('server',
483                                           '''ipalloc_deterministic.c
484                                              ipalloc_nondeterministic.c
485                                              ipalloc_lcp2.c
486                                              ipalloc_common.c
487                                              ipalloc.c
488                                           '''),
489                         includes='include',
490                         deps='ctdb-protocol-util replace talloc tevent')
491
492     bld.SAMBA_BINARY('ctdb-path',
493                      source='common/path_tool.c',
494                      cflags='-DCTDB_PATH_TOOL',
495                      deps='''ctdb-util samba-util talloc replace popt''',
496                      install_path='${CTDB_HELPER_BINDIR}')
497
498     bld.SAMBA_SUBSYSTEM('ctdb-cluster-conf',
499                         source='cluster/cluster_conf.c',
500                         deps='ctdb-util')
501
502     bld.SAMBA_SUBSYSTEM('ctdb-database-conf',
503                         source='database/database_conf.c',
504                         deps='ctdb-util')
505
506     bld.SAMBA_SUBSYSTEM('ctdb-event-conf',
507                         source='event/event_conf.c',
508                         deps='ctdb-util')
509
510     bld.SAMBA_SUBSYSTEM('ctdb-failover-conf',
511                         source='failover/failover_conf.c',
512                         deps='ctdb-util')
513
514     bld.SAMBA_SUBSYSTEM('ctdb-legacy-conf',
515                         source='server/legacy_conf.c',
516                         deps='ctdb-util')
517
518     bld.SAMBA_BINARY('ctdb-config',
519                      source='common/conf_tool.c',
520                      cflags='-DCTDB_CONF_TOOL',
521                      deps='''ctdb-logging-conf
522                              ctdb-event-conf
523                              ctdb-cluster-conf
524                              ctdb-database-conf
525                              ctdb-failover-conf
526                              ctdb-legacy-conf
527                              ctdb-util samba-util talloc replace popt''',
528                      install_path='${CTDB_HELPER_BINDIR}')
529
530     bld.SAMBA_SUBSYSTEM('ctdb-event-protocol',
531                         source=bld.SUBDIR('event',
532                                           '''event_protocol.c
533                                              event_protocol_util.c
534                                           '''),
535                         deps='ctdb-protocol-basic')
536
537     bld.SAMBA_LIBRARY('ctdb-event-client',
538                       source='event/event_client.c',
539                       deps='ctdb-event-protocol ctdb-util tevent talloc',
540                       private_library=True)
541
542     bld.SAMBA_BINARY('ctdb-eventd',
543                      source=bld.SUBDIR('event',
544                                        '''event_cmd.c
545                                           event_config.c
546                                           event_context.c
547                                           event_daemon.c
548                                           event_request.c
549                                           '''),
550                      deps='''ctdb-event-protocol
551                              ctdb-event-conf ctdb-logging-conf
552                              ctdb-server-util samba-util ctdb-util
553                              talloc tevent replace popt''',
554                      install_path='${CTDB_HELPER_BINDIR}')
555
556     bld.SAMBA_BINARY('ctdb-event',
557                         source='event/event_tool.c',
558                         cflags='-DCTDB_EVENT_TOOL',
559                         deps='''ctdb-event-client ctdb-event-protocol
560                                 ctdb-util samba-util talloc replace''',
561                         install_path='${CTDB_HELPER_BINDIR}')
562
563     bld.SAMBA_BINARY('ctdbd',
564                      source='server/ctdbd.c ' +
565                                bld.SUBDIR('server',
566                                           '''ctdb_daemon.c ctdb_recoverd.c
567                                              ctdb_recover.c ctdb_freeze.c
568                                              ctdb_tunables.c ctdb_monitor.c
569                                              ctdb_server.c ctdb_control.c
570                                              ctdb_call.c ctdb_ltdb_server.c
571                                              ctdb_traverse.c eventscript.c
572                                              ctdb_takeover.c
573                                              ctdb_persistent.c ctdb_keepalive.c
574                                              ctdb_cluster_mutex.c
575                                              ctdb_logging.c
576                                              ctdb_uptime.c
577                                              ctdb_vacuum.c ctdb_banning.c
578                                              ctdb_statistics.c
579                                              ctdb_update_record.c
580                                              ctdb_lock.c ctdb_fork.c
581                                              ctdb_tunnel.c ctdb_client.c
582                                              ctdb_config.c
583                                           '''),
584                      includes='include',
585                      deps='''ctdb-common ctdb-system ctdb-protocol
586                              ctdb-tcp ctdb-util replace sys_rw popt
587                              ctdb-logging-conf
588                              ctdb-cluster-conf
589                              ctdb-database-conf
590                              ctdb-event-conf
591                              ctdb-failover-conf
592                              ctdb-legacy-conf
593                              ctdb-event-protocol
594                              talloc tevent tdb-wrap tdb talloc_report''' +
595                           ib_deps,
596                      install_path='${SBINDIR}',
597                      manpages='ctdbd.1')
598
599     bld.SAMBA_BINARY('ctdb',
600                      source='tools/ctdb.c',
601                      deps='''ctdb-client ctdb-protocol ctdb-protocol-util
602                              ctdb-util ctdb-system samba-util sys_rw popt''',
603                      install_path='${BINDIR}',
604                      manpages='ctdb.1')
605
606     bld.SAMBA_BINARY('ctdb_killtcp',
607                      source='tools/ctdb_killtcp.c',
608                      deps='''ctdb-protocol-util ctdb-util ctdb-system
609                              samba-util replace''',
610                      install_path='${CTDB_HELPER_BINDIR}')
611
612     bld.SAMBA_BINARY('ltdbtool',
613                      source='tools/ltdbtool.c',
614                      includes='include',
615                      deps='tdb',
616                      install_path='${BINDIR}',
617                      manpages='ltdbtool.1')
618
619     bld.SAMBA_BINARY('ctdb_lock_helper',
620                      source='server/ctdb_lock_helper.c',
621                      deps='''samba-util sys_rw ctdb-system tevent-util
622                              talloc tevent tdb''',
623                      includes='include',
624                      install_path='${CTDB_HELPER_BINDIR}')
625
626     bld.SAMBA_BINARY('ctdb_recovery_helper',
627                      source='server/ctdb_recovery_helper.c',
628                      deps='''ctdb-client ctdb-protocol ctdb-util
629                              samba-util sys_rw replace tdb''',
630                      install_path='${CTDB_HELPER_BINDIR}')
631
632     bld.SAMBA_BINARY('ctdb_takeover_helper',
633                      source='server/ctdb_takeover_helper.c',
634                      deps='''ctdb-client ctdb-protocol ctdb-util
635                              samba-util sys_rw replace ctdb-ipalloc popt''',
636                      install_path='${CTDB_HELPER_BINDIR}')
637
638     bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
639                      source='server/ctdb_mutex_fcntl_helper.c',
640                      deps='sys_rw ctdb-system',
641                      includes='include',
642                      install_path='${CTDB_HELPER_BINDIR}')
643
644     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
645                         source='utils/smnotify/smnotify.x',
646                         target='utils/smnotify/smnotify.h',
647                         rule='rpcgen -h ${SRC} > ${TGT}')
648
649     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
650
651     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
652                         source='utils/smnotify/smnotify.x',
653                         target='utils/smnotify/gen_xdr.c',
654                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
655
656     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
657                         source='utils/smnotify/smnotify.x',
658                         target='utils/smnotify/gen_smnotify.c',
659                         rule='rpcgen -l ${SRC} > ${TGT}')
660
661     bld.SAMBA_BINARY('smnotify',
662                      source=bld.SUBDIR('utils/smnotify',
663                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
664                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt tirpc',
665                      includes='utils utils/smnotify',
666                      install_path='${CTDB_HELPER_BINDIR}')
667
668     bld.SAMBA_BINARY('ping_pong',
669                      source='utils/ping_pong/ping_pong.c',
670                      deps='',
671                      install_path='${BINDIR}',
672                      manpages='ping_pong.1')
673
674     if bld.env.HAVE_PMDA:
675         bld.SAMBA_BINARY('pmdactdb',
676                          source='utils/pmda/pmda_ctdb.c',
677                          includes='include',
678                          deps='''ctdb-client ctdb-protocol ctdb-util
679                                  samba-util pcp_pmda pcp''',
680                          install_path='${CTDB_PMDADIR}')
681         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
682                           destname='Install')
683         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
684                           destname='Remove')
685         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
686                           destname='pmns')
687         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
688                           destname='domain.h')
689         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
690                           destname='help')
691         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
692                           destname='README')
693
694     if bld.env.HAVE_LIBRADOS:
695         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
696                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
697                          deps='talloc tevent rados ceph-common',
698                          includes='include',
699                          install_path='${CTDB_HELPER_BINDIR}')
700
701     sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g'  % (bld.env.CTDB_VARDIR)
702     sed_expr2 = 's|/usr/local/etc/ctdb|%s|g'      % (bld.env.CTDB_ETCDIR)
703     sed_expr3 = 's|/usr/local/var/log|%s|g'       % (bld.env.CTDB_LOGDIR)
704     sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g'  % (bld.env.CTDB_RUNDIR)
705     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
706     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
707     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
708     sed_expr8 = 's|/usr/local/share/ctdb|%s|g'    % (bld.env.CTDB_DATADIR)
709     sed_cmdline = '-e "%s" ' * 8 % \
710                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
711                         sed_expr6, sed_expr7, sed_expr8)
712
713     manpages_extra = manpages_misc
714     if bld.env.etcd_reclock:
715         manpages_extra += manpages_etcd
716     if bld.env.HAVE_LIBRADOS:
717         manpages_extra += manpages_ceph
718     for f in manpages_binary + manpages_extra:
719         x = '%s.xml' % (f)
720         bld.SAMBA_GENERATOR(x,
721                             source=os.path.join('doc', x),
722                             target=x,
723                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
724
725     if bld.env.ctdb_generate_manpages:
726         bld.MANPAGES(' '.join(manpages_extra), True)
727     else:
728         for m in bld.env.ctdb_prebuilt_manpages:
729             bld.SAMBA_GENERATOR(m,
730                                 source=os.path.join("doc", m),
731                                 target=m,
732                                 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
733             bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
734
735     bld.SAMBA_GENERATOR('ctdb-onnode',
736                         source='tools/onnode',
737                         target='onnode',
738                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
739     bld.INSTALL_FILES('${BINDIR}', 'onnode',
740                       destname='onnode', chmod=MODE_755)
741
742     bld.SAMBA_GENERATOR('ctdb-diagnostics',
743                         source='tools/ctdb_diagnostics',
744                         target='ctdb_diagnostics',
745                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
746     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
747                       destname='ctdb_diagnostics', chmod=MODE_755)
748
749     if bld.env.etcd_reclock:
750         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
751                             source='utils/etcd/ctdb_etcd_lock',
752                             target='ctdb_etcd_lock',
753                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
754         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
755                           destname='ctdb_etcd_lock', chmod=MODE_744)
756
757     bld.SAMBA_GENERATOR('ctdb-natgw',
758                         source='tools/ctdb_natgw',
759                         target='ctdb_natgw',
760                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
761     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
762                       destname='ctdb_natgw', chmod=MODE_755)
763
764     bld.SAMBA_GENERATOR('ctdb-lvs',
765                         source='tools/ctdb_lvs',
766                         target='ctdb_lvs',
767                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
768     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
769                       destname='ctdb_lvs', chmod=MODE_755)
770
771     bld.SAMBA_GENERATOR('ctdbd-wrapper',
772                         source='config/ctdbd_wrapper',
773                         target='ctdbd_wrapper',
774                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
775     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
776                       destname='ctdbd_wrapper', chmod=MODE_755)
777
778     def SUBDIR_MODE_callback(arg, dirname, fnames):
779         for f in fnames:
780             fl = os.path.join(dirname, f)
781             if os.path.isdir(fl) or os.path.islink(fl):
782                 continue
783             mode = os.lstat(fl).st_mode & MODE_777
784             if arg['trim_path']:
785                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
786             arg['file_list'].append([fl, mode])
787
788     def SUBDIR_MODE(path, trim_path=None):
789         pd = {'trim_path': trim_path, 'file_list': []}
790         for dirname, _subdirs, fnames in os.walk(path):
791             SUBDIR_MODE_callback(pd, dirname, fnames)
792         return pd['file_list']
793
794     event_script_subdirs = [
795         'events/legacy',
796     ]
797
798     etc_subdirs = [
799         'nfs-checks.d'
800     ]
801
802     if bld.env.standalone_ctdb:
803         configdir = 'config'
804     else:
805         configdir = 'ctdb/config'
806
807     for t in event_script_subdirs:
808         bld.INSTALL_DIR(os.path.join(bld.env.CTDB_ETCDIR, t))
809         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
810         for fmode in files:
811             bld.INSTALL_FILES(bld.env.CTDB_DATADIR, 'config/%s' % fmode[0],
812                               destname=fmode[0], chmod=fmode[1])
813
814     for t in etc_subdirs:
815         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
816         for fmode in files:
817             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
818                               destname=fmode[0], chmod=fmode[1])
819
820     # If this is a direct install and there are no event scripts
821     # linked/enabled then enable some standard ones
822     if os.environ.get('DESTDIR') is None:
823         fmt = 'events/legacy/%s.script'
824         required_script = '00.ctdb'
825         required_path = os.path.join(bld.env.CTDB_ETCDIR,
826                                      fmt % (required_script))
827         if not os.path.islink(required_path) and \
828            not os.path.exists(required_path):
829             default_scripts = [ required_script,
830                                 '01.reclock',
831                                 '05.system',
832                                 '10.interface',
833                               ]
834             for t in default_scripts:
835                 tgt = os.path.join(bld.env.CTDB_DATADIR, fmt % (t))
836                 name = os.path.join(bld.env.CTDB_ETCDIR, fmt % (t))
837                 bld.symlink_as(name, tgt)
838
839     bld.SAMBA_GENERATOR('ctdb-functions',
840                         source='config/functions',
841                         target='functions',
842                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
843     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
844
845     etc_scripts = [
846         'ctdb-crash-cleanup.sh',
847         'debug-hung-script.sh',
848         'debug_locks.sh',
849         'nfs-linux-kernel-callout',
850         'notify.sh',
851         'statd-callout'
852     ]
853
854     for t in etc_scripts:
855         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
856                           destname=t, chmod=MODE_755)
857
858     bld.SAMBA_GENERATOR('ctdb-sudoers',
859                         source='config/ctdb.sudoers',
860                         target='ctdb.sudoers',
861                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
862     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
863                       destname='ctdb')
864
865     bld.INSTALL_FILES('${CTDB_ETCDIR}/events/notification',
866                       'config/notification.README',
867                       destname='README')
868
869     bld.INSTALL_DIR(bld.env.CTDB_LOGDIR)
870     bld.INSTALL_DIR(bld.env.CTDB_RUNDIR)
871     bld.INSTALL_DIR(bld.env.CTDB_VARDIR)
872
873     for d in ['volatile', 'persistent', 'state']:
874         bld.INSTALL_DIR(os.path.join(bld.env.CTDB_VARDIR, d))
875
876     bld.SAMBA_BINARY('errcode',
877                      source='tests/src/errcode.c',
878                      deps='replace',
879                      install_path='${CTDB_TEST_LIBEXECDIR}')
880
881     bld.SAMBA_BINARY('sigcode',
882                      source='tests/src/sigcode.c',
883                      deps='replace',
884                      install_path='${CTDB_TEST_LIBEXECDIR}')
885
886     # Unit tests
887     ctdb_unit_tests = [
888         'db_hash_test',
889         'srvid_test',
890         'pkt_read_test',
891         'pkt_write_test',
892         'comm_test',
893         'comm_server_test',
894         'comm_client_test',
895         'pidfile_test',
896         'run_proc_test',
897         'sock_io_test',
898         'hash_count_test',
899         'run_event_test',
900         'cmdline_test',
901         'conf_test',
902         'line_test',
903         'event_script_test',
904     ]
905
906     for target in ctdb_unit_tests:
907         src = 'tests/src/' + target + '.c'
908
909         bld.SAMBA_BINARY(target,
910                          source=src,
911                          deps='''talloc tevent tdb tevent-util popt
912                                  LIBASYNC_REQ samba-util sys_rw''',
913                          install_path='${CTDB_TEST_LIBEXECDIR}')
914
915     bld.SAMBA_BINARY('reqid_test',
916                      source='tests/src/reqid_test.c',
917                      deps='samba-util',
918                      install_path='${CTDB_TEST_LIBEXECDIR}')
919
920     bld.SAMBA_BINARY('rb_test',
921                      source='tests/src/rb_test.c',
922                      deps='samba-util talloc',
923                      install_path='${CTDB_TEST_LIBEXECDIR}')
924
925     bld.SAMBA_BINARY('ctdb_packet_parse',
926                      source='tests/src/ctdb_packet_parse.c',
927                      deps='talloc tevent tdb ctdb-protocol',
928                      install_path='${CTDB_TEST_LIBEXECDIR}')
929
930     bld.SAMBA_BINARY('system_socket_test',
931                      source='tests/src/system_socket_test.c',
932                      deps='talloc ctdb-protocol-util pcap',
933                      install_path='${CTDB_TEST_LIBEXECDIR}')
934
935     bld.SAMBA_BINARY('porting_tests',
936                      source='tests/src/porting_tests.c',
937                      deps='samba-util ctdb-system popt',
938                      install_path='${CTDB_TEST_LIBEXECDIR}')
939
940     bld.SAMBA_BINARY('sock_daemon_test',
941                      source='tests/src/sock_daemon_test.c',
942                      deps='''ctdb-system talloc tevent tevent-util
943                              LIBASYNC_REQ samba-util sys_rw''',
944                      install_path='${CTDB_TEST_LIBEXECDIR}')
945
946     bld.SAMBA_BINARY('ctdb_io_test',
947                      source='tests/src/ctdb_io_test.c',
948                      deps='''talloc tevent tdb samba-util sys_rw''',
949                      install_path='${CTDB_TEST_LIBEXECDIR}')
950
951
952     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-basic',
953                         source=bld.SUBDIR('tests/src',
954                                           'protocol_common_basic.c'),
955                         deps='replace talloc')
956
957     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-common',
958                         source=bld.SUBDIR('tests/src',
959                                           '''protocol_common.c
960                                              protocol_common_ctdb.c
961                                           '''),
962                         includes='include',
963                         deps='ctdb-protocol-tests-basic replace talloc tdb')
964
965     bld.SAMBA_BINARY('protocol_basic_test',
966                      source=bld.SUBDIR('tests/src', 'protocol_basic_test.c'),
967                      deps='ctdb-protocol-tests-basic talloc',
968                      install_path='${CTDB_TEST_LIBEXECDIR}')
969
970     ctdb_protocol_tests = [
971             'protocol_types_test',
972             'protocol_ctdb_test',
973             'protocol_util_test',
974             'protocol_types_compat_test',
975             'protocol_ctdb_compat_test',
976     ]
977
978     for target in ctdb_protocol_tests:
979         src = 'tests/src/' + target + '.c'
980
981         bld.SAMBA_BINARY(target,
982                          source=src,
983                          deps='''ctdb-protocol-tests-common
984                                  samba-util ctdb-util talloc tdb''',
985                          install_path='${CTDB_TEST_LIBEXECDIR}')
986
987     bld.SAMBA_BINARY('event_protocol_test',
988                      source='event/event_protocol_test.c',
989                      deps='''ctdb-protocol-tests-basic
990                              ctdb-protocol-basic talloc''',
991                      install_path='${CTDB_TEST_LIBEXECDIR}')
992
993     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
994                         source=bld.SUBDIR('tests/src',
995                                           'cluster_wait.c test_options.c'),
996                         includes='include',
997                         deps='samba-util replace popt talloc tevent tdb')
998
999     # Test binaries
1000     ctdb_tests = [
1001         'g_lock_loop',
1002         'message_ring',
1003         'fetch_ring',
1004         'fetch_loop',
1005         'fetch_loop_key',
1006         'fetch_readonly',
1007         'fetch_readonly_loop',
1008         'transaction_loop',
1009         'update_record',
1010         'update_record_persistent',
1011         'lock_tdb',
1012         'dummy_client',
1013         'tunnel_test',
1014         'tunnel_cmd',
1015     ]
1016
1017     for target in ctdb_tests:
1018         src = 'tests/src/' + target + '.c'
1019
1020         bld.SAMBA_BINARY(target,
1021                          source=src,
1022                          includes='include',
1023                          deps='''ctdb-client ctdb-protocol ctdb-util
1024                                  samba-util ctdb-tests-common''',
1025                          install_path='${CTDB_TEST_LIBEXECDIR}')
1026
1027     bld.SAMBA_BINARY('ctdb_takeover_tests',
1028                      source='''tests/src/ctdb_takeover_tests.c
1029                                tests/src/ipalloc_read_known_ips.c''',
1030                      deps='''replace popt tdb tevent talloc ctdb-system
1031                              samba-util tdb-wrap talloc_report
1032                              ctdb-ipalloc ctdb-protocol ctdb-util''',
1033                      includes='include',
1034                      install_path='${CTDB_TEST_LIBEXECDIR}')
1035
1036     bld.SAMBA_BINARY('fake_ctdbd',
1037                      source='''tests/src/fake_ctdbd.c
1038                                tests/src/ipalloc_read_known_ips.c''',
1039                      deps='''ctdb-util ctdb-protocol ctdb-protocol-util
1040                              ctdb-system samba-util tevent-util
1041                              LIBASYNC_REQ popt''',
1042                      install_path='${CTDB_TEST_LIBEXECDIR}')
1043
1044     if bld.env.HAVE_INFINIBAND:
1045         bld.SAMBA_BINARY('ibwrapper_test',
1046                          source='ib/ibwrapper_test.c',
1047                          includes='include',
1048                          deps='replace talloc ctdb-common sys_rw' +
1049                               ib_deps,
1050                          install_path='${CTDB_TEST_LIBEXECDIR}')
1051
1052     if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
1053         bld.SAMBA_BINARY('test_mutex_raw',
1054                          source='tests/src/test_mutex_raw.c',
1055                          deps='pthread',
1056                          install_path='${CTDB_TEST_LIBEXECDIR}')
1057
1058     test_subdirs = [
1059         'complex',
1060         'ctdb_eventd',
1061         'cunit',
1062         'etc-ctdb',
1063         'eventd',
1064         'eventscripts',
1065         'onnode',
1066         'shellcheck',
1067         'simple',
1068         'takeover',
1069         'takeover_helper',
1070         'tool'
1071     ]
1072
1073     if bld.env.standalone_ctdb:
1074         testdir = 'tests'
1075     else:
1076         testdir = 'ctdb/tests'
1077
1078     for t in test_subdirs:
1079         files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
1080         for fmode in files:
1081             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
1082                               destname=fmode[0], chmod=fmode[1])
1083
1084     # Install tests/scripts directory without test_wrap
1085     test_scripts = [
1086         'common.sh',
1087         'integration.bash',
1088         'unit.sh'
1089     ]
1090
1091     for t in test_scripts:
1092         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
1093                           os.path.join('tests/scripts', t),
1094                           destname=os.path.join('scripts', t))
1095
1096     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
1097                bld.env.CTDB_TEST_LIBEXECDIR)
1098     bld.SAMBA_GENERATOR('ctdb-test-wrap',
1099                         source='tests/scripts/test_wrap',
1100                         target='test_wrap',
1101                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
1102     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
1103                       destname='test_wrap', chmod=MODE_755)
1104
1105     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
1106                         source='tests/scripts/script_install_paths.sh',
1107                         target='script_install_paths.sh',
1108                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
1109     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
1110                       'script_install_paths.sh',
1111                       destname='script_install_paths.sh', chmod=MODE_644)
1112
1113     sed_expr1 = 's@^\(export %s\)=.*@\\1=%s@' % (
1114                     'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR)
1115     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
1116     bld.SAMBA_GENERATOR('ctdb-test-runner',
1117                         source='tests/run_tests.sh',
1118                         target='ctdb_run_tests.sh',
1119                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
1120                              sed_expr1, sed_expr2))
1121     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
1122                       destname='ctdb_run_tests', chmod=MODE_755)
1123     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
1124                    'ctdb_run_tests')
1125
1126     bld.SAMBA_GENERATOR('ctdb-local-daemons',
1127                         source='tests/local_daemons.sh',
1128                         target='ctdb_local_daemons.sh',
1129                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
1130                              sed_expr1, sed_expr2))
1131     bld.INSTALL_FILES('${BINDIR}', 'ctdb_local_daemons.sh',
1132                       destname='ctdb_local_daemons', chmod=MODE_755)
1133
1134
1135 def testonly(ctx):
1136     cmd = 'tests/run_tests.sh -V tests/var'
1137     ret = samba_utils.RUN_COMMAND(cmd)
1138     if ret != 0:
1139         print('tests exited with exit status %d' % ret)
1140         sys.exit(ret)
1141
1142
1143 def test(ctx):
1144     Options.commands.append('build')
1145     Options.commands.append('testonly')
1146
1147
1148 def autotest(ctx):
1149     env = samba_utils.LOAD_ENVIRONMENT()
1150     cmd = 'tests/run_tests.sh -e -S %s -C' % env.SOCKET_WRAPPER_SO_PATH
1151     ret = samba_utils.RUN_COMMAND(cmd)
1152     if ret != 0:
1153         print('autotest exited with exit status %d' % ret)
1154         sys.exit(ret)
1155
1156
1157 def show_version(ctx):
1158     print(get_version_string())
1159
1160
1161 def manpages(ctx):
1162     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
1163     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
1164     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
1165     CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
1166     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1167     for t in manpages:
1168         cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
1169         ret = samba_utils.RUN_COMMAND(cmd)
1170         if ret != 0:
1171             print('Command %s failed with exit status %d' % (cmd, ret))
1172             sys.exit(ret)
1173
1174         cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
1175         ret = samba_utils.RUN_COMMAND(cmd)
1176         if ret != 0:
1177             print('Command %s failed with exit status %d' % (cmd, ret))
1178             sys.exit(ret)
1179
1180
1181 def distonly(ctx):
1182     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
1183
1184     version = get_version()
1185
1186     distfile = open('.distversion', 'w')
1187     for field in version.vcs_fields:
1188         distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
1189     distfile.close()
1190     samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
1191
1192     t = 'ctdb.spec'
1193     sed_expr1 = 's/@VERSION@/%s/g' % get_version_string()
1194     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
1195     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
1196         sed_expr1, sed_expr2, t)
1197     ret = samba_utils.RUN_COMMAND(cmd)
1198     if ret != 0:
1199         print('Command "%s" failed with exit status %d' % (cmd, ret))
1200         sys.exit(ret)
1201     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
1202
1203     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1204     for t in manpages:
1205         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1206         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1207                               extend=True)
1208
1209     samba_dist.dist()
1210
1211
1212 def dist():
1213     Options.commands.append('manpages')
1214     Options.commands.append('distonly')
1215
1216
1217 def rpmonly(ctx):
1218     opts = os.getenv('RPM_OPTIONS') or ''
1219     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % \
1220           (opts, get_version_string())
1221     ret = samba_utils.RUN_COMMAND(cmd)
1222     if ret != 0:
1223         print('rpmbuild exited with exit status %d' % ret)
1224         sys.exit(ret)
1225
1226
1227 def rpm(ctx):
1228     Options.commands.append('manpages')
1229     Options.commands.append('distonly')
1230     Options.commands.append('rpmonly')
1231
1232
1233 def ctags(ctx):
1234     "build 'tags' file using ctags"
1235     source_root = os.path.dirname(Context.g_module.root_path)
1236     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1237     print("Running: %s" % cmd)
1238     ret = samba_utils.RUN_COMMAND(cmd)
1239     if ret != 0:
1240         print('ctags failed with exit status %d' % ret)
1241         sys.exit(ret)