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