ctdb-tests: Add errno matching utility
[samba.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 run_event.c
406                                              sock_client.c version.c
407                                              cmdline.c path.c conf.c
408                                           '''),
409                         deps='''samba-util sys_rw tevent-util
410                                 replace talloc tevent tdb popt''')
411
412     bld.SAMBA_SUBSYSTEM('ctdb-logging-conf',
413                         source='common/logging_conf.c',
414                         deps='ctdb-util talloc')
415
416     bld.SAMBA_SUBSYSTEM('ctdb-protocol-basic',
417                         source=bld.SUBDIR('protocol', 'protocol_basic.c'),
418                         deps='talloc tdb')
419
420     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
421                         source=bld.SUBDIR('protocol',
422                                           '''protocol_header.c protocol_packet.c
423                                              protocol_types.c
424                                              protocol_call.c
425                                              protocol_message.c
426                                              protocol_control.c
427                                              protocol_keepalive.c
428                                              protocol_tunnel.c
429                                              protocol_client.c
430                                              protocol_debug.c
431                                              protocol_sock.c'''),
432                         includes='include',
433                         deps='ctdb-protocol-basic replace talloc tdb')
434
435     bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
436                         source='protocol/protocol_util.c',
437                         deps='replace talloc tdb')
438
439     bld.SAMBA_SUBSYSTEM('ctdb-client',
440                         source=bld.SUBDIR('client',
441                                           '''client_connect.c client_call.c
442                                              client_message.c client_control.c
443                                              client_message_sync.c
444                                              client_control_sync.c
445                                              client_db.c client_util.c
446                                              client_tunnel.c
447                                           '''),
448                         includes='include',
449                         deps='replace talloc tevent tdb tdb-wrap')
450
451     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
452                         source=bld.SUBDIR('common',
453                                           '''sock_daemon.c'''),
454                         deps='''samba-util ctdb-util ctdb-system tevent-util
455                                 LIBASYNC_REQ replace talloc tevent''')
456
457     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
458                         source=bld.SUBDIR('server',
459                                           '''ipalloc_deterministic.c
460                                              ipalloc_nondeterministic.c
461                                              ipalloc_lcp2.c
462                                              ipalloc_common.c
463                                              ipalloc.c
464                                           '''),
465                         includes='include',
466                         deps='ctdb-protocol-util replace talloc tevent')
467
468     bld.SAMBA_BINARY('ctdb-path',
469                      source='common/path_tool.c',
470                      cflags='-DCTDB_PATH_TOOL',
471                      deps='''ctdb-util samba-util talloc replace popt''',
472                      install_path='${CTDB_HELPER_BINDIR}')
473
474     bld.SAMBA_SUBSYSTEM('ctdb-cluster-conf',
475                         source='cluster/cluster_conf.c',
476                         deps='ctdb-util')
477
478     bld.SAMBA_SUBSYSTEM('ctdb-database-conf',
479                         source='database/database_conf.c',
480                         deps='ctdb-util')
481
482     bld.SAMBA_SUBSYSTEM('ctdb-event-conf',
483                         source='event/event_conf.c',
484                         deps='ctdb-util')
485
486     bld.SAMBA_SUBSYSTEM('ctdb-legacy-conf',
487                         source='server/legacy_conf.c',
488                         deps='ctdb-util')
489
490     bld.SAMBA_BINARY('ctdb-config',
491                      source='common/conf_tool.c',
492                      cflags='-DCTDB_CONF_TOOL',
493                      deps='''ctdb-logging-conf
494                              ctdb-event-conf
495                              ctdb-cluster-conf
496                              ctdb-database-conf
497                              ctdb-legacy-conf
498                              ctdb-util samba-util talloc replace popt''',
499                      install_path='${CTDB_HELPER_BINDIR}')
500
501     bld.SAMBA_SUBSYSTEM('ctdb-event-protocol',
502                         source=bld.SUBDIR('event',
503                                           '''event_protocol.c
504                                              event_protocol_util.c
505                                           '''),
506                         deps='ctdb-protocol-basic')
507
508     bld.SAMBA_LIBRARY('ctdb-event-client',
509                       source='event/event_client.c',
510                       deps='ctdb-event-protocol ctdb-util tevent talloc',
511                       private_library=True)
512
513     bld.SAMBA_BINARY('ctdb-eventd',
514                      source=bld.SUBDIR('event',
515                                        '''event_cmd.c
516                                           event_config.c
517                                           event_context.c
518                                           event_daemon.c
519                                           event_request.c
520                                           '''),
521                      deps='''ctdb-event-protocol
522                              ctdb-event-conf ctdb-logging-conf
523                              ctdb-server-util samba-util ctdb-util
524                              talloc tevent replace popt''',
525                      install_path='${CTDB_HELPER_BINDIR}')
526
527     bld.SAMBA_BINARY('ctdb-event',
528                         source='event/event_tool.c',
529                         cflags='-DCTDB_EVENT_TOOL',
530                         deps='''ctdb-event-client ctdb-event-protocol
531                                 ctdb-util samba-util talloc replace''',
532                         install_path='${CTDB_HELPER_BINDIR}')
533
534     bld.SAMBA_BINARY('ctdbd',
535                      source='server/ctdbd.c ' +
536                                bld.SUBDIR('server',
537                                           '''ctdb_daemon.c ctdb_recoverd.c
538                                              ctdb_recover.c ctdb_freeze.c
539                                              ctdb_tunables.c ctdb_monitor.c
540                                              ctdb_server.c ctdb_control.c
541                                              ctdb_call.c ctdb_ltdb_server.c
542                                              ctdb_traverse.c eventscript.c
543                                              ctdb_takeover.c
544                                              ctdb_persistent.c ctdb_keepalive.c
545                                              ctdb_cluster_mutex.c
546                                              ctdb_logging.c
547                                              ctdb_uptime.c
548                                              ctdb_vacuum.c ctdb_banning.c
549                                              ctdb_statistics.c
550                                              ctdb_update_record.c
551                                              ctdb_lock.c ctdb_fork.c
552                                              ctdb_tunnel.c ctdb_client.c
553                                              ctdb_config.c
554                                           '''),
555                      includes='include',
556                      deps='''ctdb-common ctdb-system ctdb-protocol
557                              ctdb-tcp ctdb-util replace sys_rw popt
558                              ctdb-logging-conf
559                              ctdb-cluster-conf
560                              ctdb-database-conf
561                              ctdb-event-conf
562                              ctdb-legacy-conf
563                              ctdb-event-protocol
564                              talloc tevent tdb-wrap tdb talloc_report''' +
565                           ib_deps,
566                      install_path='${SBINDIR}',
567                      manpages='ctdbd.1')
568
569     bld.SAMBA_BINARY('ctdb',
570                      source='tools/ctdb.c',
571                      deps='''ctdb-client ctdb-protocol ctdb-protocol-util
572                              ctdb-util ctdb-system samba-util sys_rw popt''',
573                      install_path='${BINDIR}',
574                      manpages='ctdb.1')
575
576     bld.SAMBA_BINARY('ctdb_killtcp',
577                      source='tools/ctdb_killtcp.c',
578                      deps='''ctdb-protocol-util ctdb-util ctdb-system
579                              samba-util replace''',
580                      install_path='${CTDB_HELPER_BINDIR}')
581
582     bld.SAMBA_BINARY('ltdbtool',
583                      source='tools/ltdbtool.c',
584                      includes='include',
585                      deps='tdb',
586                      install_path='${BINDIR}',
587                      manpages='ltdbtool.1')
588
589     bld.SAMBA_BINARY('ctdb_lock_helper',
590                      source='server/ctdb_lock_helper.c',
591                      deps='''samba-util sys_rw ctdb-system tevent-util
592                              talloc tevent tdb''',
593                      includes='include',
594                      install_path='${CTDB_HELPER_BINDIR}')
595
596     bld.SAMBA_BINARY('ctdb_recovery_helper',
597                      source='server/ctdb_recovery_helper.c',
598                      deps='''ctdb-client ctdb-protocol ctdb-util
599                              samba-util sys_rw replace tdb''',
600                      install_path='${CTDB_HELPER_BINDIR}')
601
602     bld.SAMBA_BINARY('ctdb_takeover_helper',
603                      source='server/ctdb_takeover_helper.c',
604                      deps='''ctdb-client ctdb-protocol ctdb-util
605                              samba-util sys_rw replace ctdb-ipalloc popt''',
606                      install_path='${CTDB_HELPER_BINDIR}')
607
608     bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
609                      source='server/ctdb_mutex_fcntl_helper.c',
610                      deps='sys_rw ctdb-system',
611                      includes='include',
612                      install_path='${CTDB_HELPER_BINDIR}')
613
614     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
615                         source='utils/smnotify/smnotify.x',
616                         target='utils/smnotify/smnotify.h',
617                         rule='rpcgen -h ${SRC} > ${TGT}')
618
619     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
620
621     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
622                         source='utils/smnotify/smnotify.x',
623                         target='utils/smnotify/gen_xdr.c',
624                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
625
626     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
627                         source='utils/smnotify/smnotify.x',
628                         target='utils/smnotify/gen_smnotify.c',
629                         rule='rpcgen -l ${SRC} > ${TGT}')
630
631     bld.SAMBA_BINARY('smnotify',
632                      source=bld.SUBDIR('utils/smnotify',
633                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
634                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt tirpc',
635                      includes='utils utils/smnotify',
636                      install_path='${CTDB_HELPER_BINDIR}')
637
638     bld.SAMBA_BINARY('ping_pong',
639                      source='utils/ping_pong/ping_pong.c',
640                      deps='',
641                      install_path='${BINDIR}',
642                      manpages='ping_pong.1')
643
644     if bld.env.HAVE_PMDA:
645         bld.SAMBA_BINARY('pmdactdb',
646                          source='utils/pmda/pmda_ctdb.c',
647                          includes='include',
648                          deps='''ctdb-client ctdb-protocol ctdb-util
649                                  samba-util pcp_pmda pcp''',
650                          install_path='${CTDB_PMDADIR}')
651         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
652                           destname='Install')
653         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
654                           destname='Remove')
655         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
656                           destname='pmns')
657         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
658                           destname='domain.h')
659         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
660                           destname='help')
661         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
662                           destname='README')
663
664     if bld.env.HAVE_LIBRADOS:
665         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
666                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
667                          deps='talloc tevent rados',
668                          includes='include',
669                          install_path='${CTDB_HELPER_BINDIR}')
670
671     sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g'  % (bld.env.CTDB_VARDIR)
672     sed_expr2 = 's|/usr/local/etc/ctdb|%s|g'      % (bld.env.CTDB_ETCDIR)
673     sed_expr3 = 's|/usr/local/var/log|%s|g'       % (bld.env.CTDB_LOGDIR)
674     sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g'  % (bld.env.CTDB_RUNDIR)
675     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
676     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
677     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
678     sed_expr8 = 's|/usr/local/share/ctdb|%s|g'    % (bld.env.CTDB_DATADIR)
679     sed_cmdline = '-e "%s" ' * 8 % \
680                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
681                         sed_expr6, sed_expr7, sed_expr8)
682
683     manpages_extra = manpages_misc
684     if bld.env.etcd_reclock:
685         manpages_extra += manpages_etcd
686     if bld.env.HAVE_LIBRADOS:
687         manpages_extra += manpages_ceph
688     for f in manpages_binary + manpages_extra:
689         x = '%s.xml' % (f)
690         bld.SAMBA_GENERATOR(x,
691                             source=os.path.join('doc', x),
692                             target=x,
693                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
694
695     if bld.env.ctdb_generate_manpages:
696         bld.MANPAGES(' '.join(manpages_extra), True)
697     else:
698         for m in bld.env.ctdb_prebuilt_manpages:
699             bld.SAMBA_GENERATOR(m,
700                                 source=os.path.join("doc", m),
701                                 target=m,
702                                 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
703             bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
704
705     bld.SAMBA_GENERATOR('ctdb-onnode',
706                         source='tools/onnode',
707                         target='onnode',
708                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
709     bld.INSTALL_FILES('${BINDIR}', 'onnode',
710                       destname='onnode', chmod=0755)
711
712     bld.SAMBA_GENERATOR('ctdb-diagnostics',
713                         source='tools/ctdb_diagnostics',
714                         target='ctdb_diagnostics',
715                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
716     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
717                       destname='ctdb_diagnostics', chmod=0755)
718
719     if bld.env.etcd_reclock:
720         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
721                             source='utils/etcd/ctdb_etcd_lock',
722                             target='ctdb_etcd_lock',
723                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
724         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
725                           destname='ctdb_etcd_lock', chmod=0744)
726
727     bld.SAMBA_GENERATOR('ctdb-natgw',
728                         source='tools/ctdb_natgw',
729                         target='ctdb_natgw',
730                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
731     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
732                       destname='ctdb_natgw', chmod=0755)
733
734     bld.SAMBA_GENERATOR('ctdb-lvs',
735                         source='tools/ctdb_lvs',
736                         target='ctdb_lvs',
737                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
738     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
739                       destname='ctdb_lvs', chmod=0755)
740
741     bld.SAMBA_GENERATOR('ctdbd-wrapper',
742                         source='config/ctdbd_wrapper',
743                         target='ctdbd_wrapper',
744                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
745     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
746                       destname='ctdbd_wrapper', chmod=0755)
747
748     def SUBDIR_MODE_callback(arg, dirname, fnames):
749         for f in fnames:
750             fl = os.path.join(dirname, f)
751             if os.path.isdir(fl) or os.path.islink(fl):
752                 continue
753             mode = os.lstat(fl).st_mode & 0777
754             if arg['trim_path']:
755                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
756             arg['file_list'].append([fl, mode])
757
758     def SUBDIR_MODE(path, trim_path=None):
759         pd = {'trim_path': trim_path, 'file_list': []}
760         os.path.walk(path, SUBDIR_MODE_callback, pd)
761         return pd['file_list']
762
763     event_script_subdirs = [
764         'events/legacy',
765     ]
766
767     etc_subdirs = [
768         'nfs-checks.d'
769     ]
770
771     if bld.env.standalone_ctdb:
772         configdir = 'config'
773     else:
774         configdir = 'ctdb/config'
775
776     for t in event_script_subdirs:
777         bld.INSTALL_DIR(os.path.join(bld.env.CTDB_ETCDIR, t))
778         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
779         for fmode in files:
780             bld.INSTALL_FILES(bld.env.CTDB_DATADIR, 'config/%s' % fmode[0],
781                               destname=fmode[0], chmod=fmode[1])
782
783     for t in etc_subdirs:
784         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
785         for fmode in files:
786             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
787                               destname=fmode[0], chmod=fmode[1])
788
789     # If this is a direct install and there are no event scripts
790     # linked/enabled then enable some standard ones
791     if os.environ.get('DESTDIR') is None:
792         fmt = 'events/legacy/%s.script'
793         required_script = '00.ctdb'
794         required_path = os.path.join(bld.env.CTDB_ETCDIR,
795                                      fmt % (required_script))
796         if not os.path.islink(required_path) and \
797            not os.path.exists(required_path):
798             default_scripts = [ required_script,
799                                 '01.reclock',
800                                 '05.system',
801                                 '10.interface',
802                               ]
803             for t in default_scripts:
804                 tgt = os.path.join(bld.env.CTDB_DATADIR, fmt % (t))
805                 name = os.path.join(bld.env.CTDB_ETCDIR, fmt % (t))
806                 bld.symlink_as(name, tgt)
807
808     bld.SAMBA_GENERATOR('ctdb-functions',
809                         source='config/functions',
810                         target='functions',
811                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
812     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
813
814     etc_scripts = [
815         'ctdb-crash-cleanup.sh',
816         'debug-hung-script.sh',
817         'debug_locks.sh',
818         'nfs-linux-kernel-callout',
819         'notify.sh',
820         'statd-callout'
821     ]
822
823     for t in etc_scripts:
824         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
825                           destname=t, chmod=0755)
826
827     bld.SAMBA_GENERATOR('ctdb-sudoers',
828                         source='config/ctdb.sudoers',
829                         target='ctdb.sudoers',
830                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
831     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
832                       destname='ctdb')
833
834     bld.INSTALL_FILES('${CTDB_ETCDIR}/events/notification',
835                       'config/notification.README',
836                       destname='README')
837
838     bld.install_dir(bld.env.CTDB_LOGDIR)
839     bld.install_dir(bld.env.CTDB_RUNDIR)
840     bld.install_dir(bld.env.CTDB_VARDIR)
841
842     for d in ['volatile', 'persistent', 'state']:
843         bld.install_dir(os.path.join(bld.env.CTDB_VARDIR, d))
844
845     bld.SAMBA_BINARY('errcode',
846                      source='tests/src/errcode.c',
847                      deps='replace',
848                      install_path='${CTDB_TEST_LIBEXECDIR}')
849
850     # Unit tests
851     ctdb_unit_tests = [
852         'db_hash_test',
853         'srvid_test',
854         'pkt_read_test',
855         'pkt_write_test',
856         'comm_test',
857         'comm_server_test',
858         'comm_client_test',
859         'pidfile_test',
860         'run_proc_test',
861         'sock_io_test',
862         'hash_count_test',
863         'run_event_test',
864         'cmdline_test',
865         'conf_test',
866     ]
867
868     for target in ctdb_unit_tests:
869         src = 'tests/src/' + target + '.c'
870
871         bld.SAMBA_BINARY(target,
872                          source=src,
873                          deps='''talloc tevent tdb tevent-util popt
874                                  LIBASYNC_REQ samba-util sys_rw''',
875                          install_path='${CTDB_TEST_LIBEXECDIR}')
876
877     bld.SAMBA_BINARY('reqid_test',
878                      source='tests/src/reqid_test.c',
879                      deps='samba-util',
880                      install_path='${CTDB_TEST_LIBEXECDIR}')
881
882     bld.SAMBA_BINARY('rb_test',
883                      source='tests/src/rb_test.c',
884                      deps='samba-util talloc',
885                      install_path='${CTDB_TEST_LIBEXECDIR}')
886
887     bld.SAMBA_BINARY('ctdb_packet_parse',
888                      source='tests/src/ctdb_packet_parse.c',
889                      deps='talloc tevent tdb ctdb-protocol',
890                      install_path='${CTDB_TEST_LIBEXECDIR}')
891
892     bld.SAMBA_BINARY('porting_tests',
893                      source='tests/src/porting_tests.c',
894                      deps='samba-util ctdb-system popt',
895                      install_path='${CTDB_TEST_LIBEXECDIR}')
896
897     bld.SAMBA_BINARY('sock_daemon_test',
898                      source='tests/src/sock_daemon_test.c',
899                      deps='''ctdb-system talloc tevent tevent-util
900                              LIBASYNC_REQ samba-util sys_rw''',
901                      install_path='${CTDB_TEST_LIBEXECDIR}')
902
903     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-basic',
904                         source=bld.SUBDIR('tests/src',
905                                           'protocol_common_basic.c'),
906                         deps='replace talloc')
907
908     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-common',
909                         source=bld.SUBDIR('tests/src',
910                                           '''protocol_common.c
911                                              protocol_common_ctdb.c
912                                           '''),
913                         includes='include',
914                         deps='ctdb-protocol-tests-basic replace talloc tdb')
915
916     bld.SAMBA_BINARY('protocol_basic_test',
917                      source=bld.SUBDIR('tests/src', 'protocol_basic_test.c'),
918                      deps='ctdb-protocol-tests-basic talloc',
919                      install_path='${CTDB_TEST_LIBEXECDIR}')
920
921     ctdb_protocol_tests = [
922             'protocol_types_test',
923             'protocol_ctdb_test',
924             'protocol_util_test',
925             'protocol_types_compat_test',
926             'protocol_ctdb_compat_test',
927     ]
928
929     for target in ctdb_protocol_tests:
930         src = 'tests/src/' + target + '.c'
931
932         bld.SAMBA_BINARY(target,
933                          source=src,
934                          deps='''ctdb-protocol-tests-common
935                                  samba-util talloc tdb''',
936                          install_path='${CTDB_TEST_LIBEXECDIR}')
937
938     bld.SAMBA_BINARY('event_protocol_test',
939                      source='event/event_protocol_test.c',
940                      deps='''ctdb-protocol-tests-basic
941                              ctdb-protocol-basic talloc''',
942                      install_path='${CTDB_TEST_LIBEXECDIR}')
943
944     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
945                         source=bld.SUBDIR('tests/src',
946                                           'cluster_wait.c test_options.c'),
947                         includes='include',
948                         deps='samba-util replace popt talloc tevent tdb')
949
950     # Test binaries
951     ctdb_tests = [
952         'g_lock_loop',
953         'message_ring',
954         'fetch_ring',
955         'fetch_loop',
956         'fetch_loop_key',
957         'fetch_readonly',
958         'fetch_readonly_loop',
959         'transaction_loop',
960         'update_record',
961         'update_record_persistent',
962         'lock_tdb',
963         'dummy_client',
964         'tunnel_test',
965         'tunnel_cmd',
966     ]
967
968     for target in ctdb_tests:
969         src = 'tests/src/' + target + '.c'
970
971         bld.SAMBA_BINARY(target,
972                          source=src,
973                          includes='include',
974                          deps='''ctdb-client ctdb-protocol ctdb-util
975                                  samba-util ctdb-tests-common''',
976                          install_path='${CTDB_TEST_LIBEXECDIR}')
977
978     bld.SAMBA_BINARY('ctdb_takeover_tests',
979                      source='''tests/src/ctdb_takeover_tests.c
980                                tests/src/ipalloc_read_known_ips.c''',
981                      deps='''replace popt tdb tevent talloc ctdb-system
982                              samba-util tdb-wrap talloc_report
983                              ctdb-ipalloc ctdb-protocol ctdb-util''',
984                      includes='include',
985                      install_path='${CTDB_TEST_LIBEXECDIR}')
986
987     bld.SAMBA_BINARY('fake_ctdbd',
988                      source='''tests/src/fake_ctdbd.c
989                                tests/src/ipalloc_read_known_ips.c''',
990                      deps='''ctdb-util ctdb-protocol ctdb-protocol-util
991                              ctdb-system samba-util tevent-util
992                              LIBASYNC_REQ popt''',
993                      install_path='${CTDB_TEST_LIBEXECDIR}')
994
995     if bld.env.HAVE_INFINIBAND:
996         bld.SAMBA_BINARY('ibwrapper_test',
997                          source='ib/ibwrapper_test.c',
998                          includes='include',
999                          deps='replace talloc ctdb-common sys_rw' +
1000                               ib_deps,
1001                          install_path='${CTDB_TEST_LIBEXECDIR}')
1002
1003     if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
1004         bld.SAMBA_BINARY('test_mutex_raw',
1005                          source='tests/src/test_mutex_raw.c',
1006                          deps='pthread',
1007                          install_path='${CTDB_TEST_LIBEXECDIR}')
1008
1009     test_subdirs = [
1010         'complex',
1011         'ctdb_eventd',
1012         'cunit',
1013         'eventd',
1014         'eventscripts',
1015         'onnode',
1016         'shellcheck',
1017         'simple',
1018         'takeover',
1019         'takeover_helper',
1020         'tool'
1021     ]
1022
1023     if bld.env.standalone_ctdb:
1024         testdir = 'tests'
1025     else:
1026         testdir = 'ctdb/tests'
1027
1028     for t in test_subdirs:
1029         files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
1030         for fmode in files:
1031             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
1032                               destname=fmode[0], chmod=fmode[1])
1033
1034     # Install tests/scripts directory without test_wrap
1035     test_scripts = [
1036         'common.sh',
1037         'integration.bash',
1038         'unit.sh'
1039     ]
1040
1041     for t in test_scripts:
1042         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
1043                           os.path.join('tests/scripts', t),
1044                           destname=os.path.join('scripts', t))
1045
1046     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
1047                bld.env.CTDB_TEST_LIBEXECDIR)
1048     bld.SAMBA_GENERATOR('ctdb-test-wrap',
1049                         source='tests/scripts/test_wrap',
1050                         target='test_wrap',
1051                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
1052     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
1053                       destname='test_wrap', chmod=0755)
1054
1055     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
1056                         source='tests/scripts/script_install_paths.sh',
1057                         target='script_install_paths.sh',
1058                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
1059     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
1060                       'script_install_paths.sh',
1061                       destname='script_install_paths.sh', chmod=0644)
1062
1063     sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
1064                     'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
1065                     'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
1066     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
1067     bld.SAMBA_GENERATOR('ctdb-test-runner',
1068                         source='tests/run_tests.sh',
1069                         target='ctdb_run_tests.sh',
1070                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
1071                              sed_expr1, sed_expr2))
1072     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
1073                       destname='ctdb_run_tests', chmod=0755)
1074     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
1075                    'ctdb_run_tests')
1076
1077
1078 def testonly(ctx):
1079     cmd = 'tests/run_tests.sh -V tests/var'
1080     ret = samba_utils.RUN_COMMAND(cmd)
1081     if ret != 0:
1082         print('tests exited with exit status %d' % ret)
1083         sys.exit(ret)
1084
1085
1086 def test(ctx):
1087     import Scripting
1088     Scripting.commands.append('build')
1089     Scripting.commands.append('testonly')
1090
1091
1092 def autotest(ctx):
1093     env = samba_utils.LOAD_ENVIRONMENT()
1094     cmd = 'tests/run_tests.sh -e -S %s -C' % env.SOCKET_WRAPPER_SO_PATH
1095     ret = samba_utils.RUN_COMMAND(cmd)
1096     if ret != 0:
1097         print('autotest exited with exit status %d' % ret)
1098         sys.exit(ret)
1099
1100
1101 def show_version(ctx):
1102     print VERSION
1103
1104
1105 def manpages(ctx):
1106     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
1107     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
1108     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
1109     CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
1110     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1111     for t in manpages:
1112         cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
1113         ret = samba_utils.RUN_COMMAND(cmd)
1114         if ret != 0:
1115             print('Command %s failed with exit status %d' % (cmd, ret))
1116             sys.exit(ret)
1117
1118         cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
1119         ret = samba_utils.RUN_COMMAND(cmd)
1120         if ret != 0:
1121             print('Command %s failed with exit status %d' % (cmd, ret))
1122             sys.exit(ret)
1123
1124
1125 def distonly(ctx):
1126     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
1127
1128     distfile = file('.distversion', 'w')
1129     for field in version.vcs_fields:
1130         distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
1131     distfile.close()
1132     samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
1133
1134     t = 'ctdb.spec'
1135     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
1136     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
1137     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
1138         sed_expr1, sed_expr2, t)
1139     ret = samba_utils.RUN_COMMAND(cmd)
1140     if ret != 0:
1141         print('Command "%s" failed with exit status %d' % (cmd, ret))
1142         sys.exit(ret)
1143     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
1144
1145     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1146     for t in manpages:
1147         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1148         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1149                               extend=True)
1150
1151     samba_dist.dist()
1152
1153
1154 def dist():
1155     import Scripting
1156     Scripting.commands.append('manpages')
1157     Scripting.commands.append('distonly')
1158
1159
1160 def rpmonly(ctx):
1161     opts = os.getenv('RPM_OPTIONS') or ''
1162     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
1163     ret = samba_utils.RUN_COMMAND(cmd)
1164     if ret != 0:
1165         print('rpmbuild exited with exit status %d' % ret)
1166         sys.exit(ret)
1167
1168
1169 def rpm(ctx):
1170     import Scripting
1171     Scripting.commands.append('manpages')
1172     Scripting.commands.append('distonly')
1173     Scripting.commands.append('rpmonly')
1174
1175
1176 def ctags(ctx):
1177     "build 'tags' file using ctags"
1178     import Utils
1179     source_root = os.path.dirname(Utils.g_module.root_path)
1180     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1181     print("Running: %s" % cmd)
1182     ret = samba_utils.RUN_COMMAND(cmd)
1183     if ret != 0:
1184         print('ctags failed with exit status %d' % ret)
1185         sys.exit(ret)