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