ctdb-build: Create ctdb only ctags
[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
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 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 lib/popt:lib/popt
33                         lib/socket_wrapper:lib/socket_wrapper
34                         buildtools:buildtools''')
35
36 def set_options(opt):
37     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
38     opt.RECURSE('lib/replace')
39     opt.RECURSE('lib/talloc')
40     opt.RECURSE('lib/tevent')
41     opt.RECURSE('lib/tdb')
42
43     opt.add_option('--enable-infiniband',
44                    help=("Turn on infiniband support (default=no)"),
45                    action="store_true", dest='ctdb_infiniband', default=False)
46     opt.add_option('--enable-pmda',
47                    help=("Turn on PCP pmda support (default=no)"),
48                    action="store_true", dest='ctdb_pmda', default=False)
49
50     opt.add_option('--with-logdir',
51                    help=("Path to log directory"),
52                    action="store", dest='ctdb_logdir', default=None)
53     opt.add_option('--with-socketpath',
54                   help=("path to CTDB daemon socket"),
55                   action="store_true", dest='ctdb_sockpath', default=False)
56
57 def configure(conf):
58
59     # CTDB relies on nested event loops
60     conf.env.TEVENT_DEPRECATED = 1
61
62     # No need to build python bindings for talloc/tevent/tdb
63     if conf.IN_LAUNCH_DIR():
64         Options.options.disable_python = True
65
66     conf.RECURSE('lib/replace')
67     conf.RECURSE('lib/popt')
68     conf.RECURSE('lib/talloc')
69     conf.RECURSE('lib/tevent')
70     conf.RECURSE('lib/tdb')
71     conf.RECURSE('lib/socket_wrapper')
72
73     have_pmda = False
74     if Options.options.ctdb_pmda:
75         pmda_support = True
76
77         if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
78                                   together=True):
79             pmda_support = False
80         if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
81             pmda_support = False
82         if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
83             pmda_support = False
84         if pmda_support:
85             have_pmda = True
86         else:
87             Logs.error("PMDA support not available")
88     if have_pmda:
89         Logs.info('Building with PMDA support')
90         conf.define('HAVE_PMDA', 1)
91         conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
92                                              'lib/pcp/pmdas/ctdb')
93
94     have_infiniband = False
95     if Options.options.ctdb_infiniband:
96         ib_support = True
97
98         if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
99             ib_support = False
100         if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
101             ib_support = False
102         if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
103             ib_support = False
104         if ib_support:
105             have_infiniband = True
106         else:
107             Logs.error("Infiniband support not available")
108     if have_infiniband:
109         Logs.info('Building with Infiniband support')
110         conf.define('HAVE_INFINIBAND', 1)
111         conf.define('USE_INFINIBAND', 1)
112
113     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
114     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
115     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
116     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
117
118     machine = os.uname()[4]
119     if machine in ['x86_64', 'ppc64', 'powerpc64']:
120         conf.env.LIBDIR = conf.env.LIBDIR + '64'
121
122     if Options.options.ctdb_logdir:
123         conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
124     else:
125         conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
126
127     if Options.options.ctdb_sockpath:
128         conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
129     else:
130         conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
131                                               'ctdbd.socket')
132
133     conf.ADD_CFLAGS('''-DBINDIR=\"%s\"
134                        -DLOGDIR=\"%s\"
135                        -DSOCKPATH=\"%s\"
136                        -DCTDB_ETCDIR=\"%s\"
137                        -DCTDB_VARDIR=\"%s\"
138                        -DCTDB_RUNDIR=\"%s\"''' % (
139                     conf.env.CTDB_BINDIR,
140                     conf.env.CTDB_LOGDIR,
141                     conf.env.CTDB_SOCKPATH,
142                     conf.env.CTDB_ETCDIR,
143                     conf.env.CTDB_VARDIR,
144                     conf.env.CTDB_RUNDIR))
145
146     conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
147                                               'share/ctdb-tests')
148     conf.env.CTDB_TEST_LIBDIR = os.path.join(conf.env.LIBDIR, 'ctdb-tests')
149
150     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
151     conf.SAMBA_CONFIG_H()
152
153 def build(bld):
154     bld.RECURSE('lib/replace')
155     bld.RECURSE('lib/popt')
156     bld.RECURSE('lib/talloc')
157     bld.RECURSE('lib/tevent')
158     bld.RECURSE('lib/tdb')
159     bld.RECURSE('lib/socket_wrapper')
160
161     bld.SAMBA_GENERATOR('ctdb-version-header',
162                         target='include/ctdb_version.h',
163                         rule='../packaging/mkversion.sh ${TGT} %s' % (VERSION),
164                         always=True)
165
166     bld.SAMBA_SUBSYSTEM('ctdb-util',
167                         source=bld.SUBDIR('lib/util',
168                                           'util.c util_file.c util_time.c'),
169                         includes='include include/internal',
170                         deps='replace talloc tevent tdb')
171
172     bld.SAMBA_SUBSYSTEM('ctdb-util-misc',
173                         source=bld.SUBDIR('lib/util',
174                                           '''db_wrap.c debug.c fault.c
175                                              idtree.c signal.c strlist.c
176                                              substitute.c'''),
177                         includes='include include/internal lib/util',
178                         deps='replace talloc tevent tdb')
179
180     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
181                         source=bld.SUBDIR('tcp',
182                                           'tcp_connect.c tcp_init.c tcp_io.c'),
183                         includes='include include/internal',
184                         deps='replace tdb talloc tevent')
185
186     ib_deps = ''
187     if bld.env.HAVE_INFINIBAND:
188         bld.SAMBA_SUBSYSTEM('ctdb-ib',
189                             source=bld.SUBDIR('ib',
190                                               '''ibwrapper.c ibw_ctdb.c
191                                                  ibw_ctdb_init.c'''),
192                             includes='include include/internal',
193                             deps='replace')
194         ib_deps = ' ctdb-ib rdmacm ibverbs'
195
196     bld.SAMBA_SUBSYSTEM('ctdb-common',
197                         source=bld.SUBDIR('common',
198                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
199                                              ctdb_message.c cmdline.c rb_tree.c
200                                              system_common.c ctdb_fork.c'''),
201                         includes='include include/internal common . lib/util',
202                         deps='replace popt talloc tevent tdb')
203
204     bld.SAMBA_SUBSYSTEM('ctdb-common-util',
205                         source=bld.SUBDIR('common',
206                                           'system_util.c ctdb_logging.c'),
207                         includes='include include/internal',
208                         deps='replace tevent tdb')
209
210     if sys.platform == 'linux2':
211         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
212     elif sys.platform == 'aix':
213         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
214     elif sys.platform == 'freebsd':
215         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
216     elif sys.platform == 'kfreebsd':
217         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
218     elif sys.platform == 'gnu':
219         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
220     else:
221         Logs.error("Platform %s not supported" % sys.platform)
222
223     bld.SAMBA_SUBSYSTEM('ctdb-system',
224                         source=CTDB_SYSTEM_SRC,
225                         includes='include include/internal',
226                         deps='replace talloc tevent tdb')
227
228     bld.SAMBA_SUBSYSTEM('ctdb-client',
229                         source=bld.SUBDIR('client', 'ctdb_client.c'),
230                         includes='include include/internal lib/util',
231                         public_headers='include/ctdb_client.h',
232                         deps='replace popt talloc tevent tdb')
233
234     bld.SAMBA_SUBSYSTEM('ctdb-server',
235                         source='server/ctdbd.c ' +
236                                bld.SUBDIR('server',
237                                           '''ctdb_daemon.c ctdb_recoverd.c
238                                              ctdb_recover.c ctdb_freeze.c
239                                              ctdb_tunables.c ctdb_monitor.c
240                                              ctdb_server.c ctdb_control.c
241                                              ctdb_call.c ctdb_ltdb_server.c
242                                              ctdb_traverse.c eventscript.c
243                                              ctdb_takeover.c ctdb_serverids.c
244                                              ctdb_persistent.c ctdb_keepalive.c
245                                              ctdb_logging.c ctdb_uptime.c
246                                              ctdb_vacuum.c ctdb_banning.c
247                                              ctdb_statistics.c
248                                              ctdb_update_record.c
249                                              ctdb_lock.c'''),
250                         includes='include include/internal lib/util',
251                         public_headers='''include/ctdb.h
252                                           include/ctdb_private.h
253                                           include/ctdb_protocol.h
254                                           include/ctdb_typesafe_cb.h''',
255                         deps='replace popt talloc tevent tdb')
256
257     bld.SAMBA_BINARY('bin/ctdbd',
258                      source='',
259                      deps='''ctdb-server ctdb-client ctdb-common
260                              ctdb-common-util ctdb-system ctdb-tcp
261                              ctdb-util ctdb-util-misc''' +
262                           ib_deps,
263                      install_path='${SBINDIR}',
264                      manpages='doc/ctdbd.1')
265
266     bld.SAMBA_BINARY('bin/ctdb',
267                      source='tools/ctdb.c tools/ctdb_vacuum.c',
268                      deps='''ctdb-client ctdb-common ctdb-common-util
269                              ctdb-system ctdb-util ctdb-util-misc''',
270                      install_path='${BINDIR}',
271                      manpages='doc/ctdb.1')
272
273     bld.SAMBA_BINARY('bin/ltdbtool',
274                      source='tools/ltdbtool.c',
275                      includes='include',
276                      deps='tdb',
277                      install_path='${BINDIR}',
278                      manpages='doc/ltdbtool.1')
279
280     bld.SAMBA_BINARY('bin/ctdb_lock_helper',
281                      source='server/ctdb_lock_helper.c',
282                      deps='ctdb-util ctdb-util-misc ctdb-common-util talloc tdb',
283                      install_path='${BINDIR}')
284
285     bld.SAMBA_BINARY('bin/ctdb_event_helper',
286                      source='server/ctdb_event_helper.c',
287                      includes='include include/internal',
288                      deps='ctdb-util ctdb-util-misc ctdb-common-util replace tdb',
289                      install_path='${BINDIR}')
290
291     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
292                         source='utils/smnotify/smnotify.x',
293                         target='utils/smnotify/smnotify.h',
294                         rule='rpcgen -h ${SRC} > ${TGT}')
295
296     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
297                         source='utils/smnotify/smnotify.x',
298                         target='utils/smnotify/gen_xdr.c',
299                         rule='rpcgen -c ${SRC} > ${TGT}')
300
301     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
302                         source='utils/smnotify/smnotify.x',
303                         target='utils/smnotify/gen_smnotify.c',
304                         rule='rpcgen -l ${SRC} > ${TGT}')
305
306     bld.SAMBA_BINARY('bin/smnotify',
307                      source=bld.SUBDIR('utils/smnotify',
308                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
309                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
310                      includes='utils utils/smnotify',
311                      install_path='${BINDIR}')
312
313     bld.SAMBA_BINARY('bin/ping_pong',
314                      source='utils/ping_pong/ping_pong.c',
315                      deps='',
316                      install_path='${BINDIR}',
317                      manpages='doc/ping_pong.1')
318
319     if bld.env.HAVE_PMDA:
320         bld.SAMBA_BINARY('bin/pmdactdb',
321                          source='utils/pmda/pmda_ctdb.c',
322                          includes='include include/internal',
323                          deps='''ctdb-client ctdb-common ctdb-system
324                                  ctdb-util-misc ctdb-util pcp_pmda pcp''',
325                          install_path='${CTDB_PMDADIR}')
326         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
327                           destname='Install')
328         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
329                           destname='Remove')
330         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
331                           destname='pmns')
332         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
333                           destname='domain.h')
334         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
335                           destname='help')
336         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
337                           destname='README')
338
339     bld.MANPAGES('''doc/onnode.1 doc/ctdbd_wrapper.1 doc/ctdbd.conf.5
340                     doc/ctdb.7 doc/ctdb-tunables.7''', True)
341
342     bld.INSTALL_FILES('${BINDIR}', 'tools/onnode',
343                       destname='onnode', chmod=0755)
344     bld.INSTALL_FILES('${BINDIR}', 'tools/ctdb_diagnostics',
345                       destname='ctdb_diagnostics', chmod=0755)
346     bld.INSTALL_FILES('${SBINDIR}', 'config/ctdbd_wrapper',
347                       destname='ctdbd_wrapper', chmod=0755)
348
349     def SUBDIR_MODE_callback(arg, dirname, fnames):
350         for f in fnames:
351             fl = os.path.join(dirname, f)
352             if os.path.isdir(fl) or os.path.islink(fl):
353                 continue
354             mode = os.lstat(fl).st_mode & 0777
355             if arg['trim_path']:
356                     fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
357             arg['file_list'].append([fl, mode])
358
359     def SUBDIR_MODE(path, trim_path=None):
360          pd = {'trim_path': trim_path, 'file_list': []}
361          os.path.walk(path, SUBDIR_MODE_callback, pd)
362          return pd['file_list']
363
364     etc_subdirs = [
365         'events.d',
366         'nfs-rpc-checks.d'
367     ]
368
369     for t in etc_subdirs:
370         files = SUBDIR_MODE('config/%s' % t, trim_path='config')
371         for fmode in files:
372             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
373                               destname=fmode[0], chmod=fmode[1])
374
375     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/functions',
376                       destname='functions')
377
378     etc_scripts = [
379         'ctdb-crash-cleanup.sh',
380         'debug-hung-script.sh',
381         'debug_locks.sh',
382         'gcore_trace.sh',
383         'notify.sh',
384         'statd-callout'
385     ]
386
387     for t in etc_scripts:
388         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/' + t,
389                           destname=t, chmod=0755)
390
391     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'config/ctdb.sudoers',
392                       destname='ctdb')
393
394     bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
395                       destname='README')
396
397     bld.install_dir(bld.env.CTDB_LOGDIR)
398     bld.install_dir(bld.env.CTDB_RUNDIR)
399     bld.install_dir(bld.env.CTDB_VARDIR)
400
401     sed_expr = 's/@PACKAGE_VERSION@/%s/g' % VERSION
402     bld.SAMBA_GENERATOR('ctdb-pc',
403                         source='ctdb.pc.in',
404                         target='ctdb.pc',
405                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
406     bld.INSTALL_FILES('${LIBDIR}/pkgconfig', 'ctdb.pc')
407
408     # Test binaries
409     ctdb_tests = [
410         'rb_test',
411         'ctdb_bench',
412         'ctdb_fetch',
413         'ctdb_fetch_one',
414         'ctdb_fetch_readonly_once',
415         'ctdb_fetch_readonly_loop',
416         'ctdb_trackingdb_test',
417         'ctdb_update_record',
418         'ctdb_update_record_persistent',
419         'ctdb_store',
420         'ctdb_traverse',
421         'ctdb_randrec',
422         'ctdb_persistent',
423         'ctdb_porting_tests',
424         'ctdb_transaction',
425         'ctdb_lock_tdb'
426     ]
427
428     for t in ctdb_tests:
429          target = 'bin/' + t
430          src = 'tests/src/' + t + '.c'
431
432          bld.SAMBA_BINARY(target,
433                           source=src,
434                           deps='''ctdb-client ctdb-common ctdb-common-util
435                                   ctdb-system ctdb-util ctdb-util-misc''',
436                           install_path='${CTDB_TEST_LIBDIR}')
437
438     bld.SAMBA_BINARY('bin/ctdb_takeover_tests',
439                      source='tests/src/ctdb_takeover_tests.c',
440                      deps='replace popt tdb tevent talloc ctdb-system' +
441                           ib_deps,
442                      includes='../include ../include/internal lib/util',
443                      install_path='${CTDB_TEST_LIBDIR}')
444
445     bld.SAMBA_BINARY('bin/ctdb_functest',
446                      source='tests/src/ctdb_functest.c',
447                      deps='replace tdb tevent talloc popt ctdb-system',
448                      includes='../include ../include/internal lib/util',
449                      install_path='${CTDB_TEST_LIBDIR}')
450
451     bld.SAMBA_BINARY('bin/ctdb_stubtest',
452                      source='tests/src/ctdb_test.c',
453                      deps='replace tdb tevent talloc popt ctdb-system',
454                      includes='../include ../include/internal lib/util',
455                      install_path='${CTDB_TEST_LIBDIR}')
456
457     if bld.env.HAVE_INFINIBAND:
458         bld.SAMBA_BINARY('bin/ibwrapper_test',
459                          source='ib/ibwrapper_test.c',
460                          includes='include include/internal',
461                          deps='''replace talloc ctdb-client ctdb-common
462                                  ctdb-system ctdb-util-misc ctdb-util''' +
463                               ib_deps,
464                          install_path='${CTDB_TEST_LIBDIR}')
465
466     test_subdirs = [
467         'complex',
468         'events.d',
469         'eventscripts',
470         'onnode',
471         'simple',
472         'takeover',
473         'tool'
474     ]
475
476     for t in test_subdirs:
477         files = SUBDIR_MODE('tests/%s' % t, trim_path='tests')
478         for fmode in files:
479             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
480                               destname=fmode[0], chmod=fmode[1])
481
482     # Install tests/scripts directory without test_wrap
483     test_scripts = [
484         'common.sh',
485         'integration.bash',
486         'unit.sh'
487     ]
488
489     for t in test_scripts:
490         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
491                           os.path.join('tests/scripts', t),
492                           destname=os.path.join('scripts', t))
493
494     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
495                bld.env.CTDB_TEST_LIBDIR)
496     bld.SAMBA_GENERATOR('ctdb-test-wrap',
497                         source='tests/scripts/test_wrap',
498                         target='test_wrap',
499                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
500     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
501                       destname='test_wrap', chmod=0755)
502
503     sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
504                 bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBDIR)
505     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
506     bld.SAMBA_GENERATOR('ctdb-test-runner',
507                         source='tests/run_tests.sh',
508                         target='ctdb_run_tests.sh',
509                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
510                              sed_expr1, sed_expr2))
511     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
512                       destname='ctdb_run_tests', chmod=0755)
513     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
514                    'ctdb_run_tests')
515
516     test_eventscript_links = [
517         'events.d',
518         'functions',
519         'nfs-rpc-checks.d'
520     ]
521
522     test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
523                                  'eventscripts/etc-ctdb')
524     for t in test_eventscript_links:
525         bld.symlink_as(os.path.join(test_link_dir, t),
526                        os.path.join(bld.env.CTDB_ETCDIR, t))
527
528
529 def testonly(ctx):
530     cmd = 'tests/run_tests.sh -V tests/var'
531     ret = samba_utils.RUN_COMMAND(cmd)
532     if ret != 0:
533         print('tests exited with exit status %d' % ret)
534         sys.exit(ret)
535
536 def test(ctx):
537     import Scripting
538     Scripting.commands.append('build')
539     Scripting.commands.append('testonly')
540
541 def autotest(ctx):
542     cmd = 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
543     ret = samba_utils.RUN_COMMAND(cmd)
544     if ret != 0:
545         print('autotest exited with exit status %d' % ret)
546         sys.exit(ret)
547
548 def show_version(ctx):
549     print VERSION
550
551 def dist():
552     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
553
554     t = 'include/ctdb_version.h'
555     cmd = 'packaging/mkversion.sh %s %s' % (t, VERSION)
556     ret = samba_utils.RUN_COMMAND(cmd)
557     if ret != 0:
558         print('Command "%s" failed with exit status %d' % (cmd, ret))
559         sys.exit(ret)
560     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
561
562     t = 'ctdb.spec'
563     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
564     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
565     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
566         sed_expr1, sed_expr2, t)
567     ret = samba_utils.RUN_COMMAND(cmd)
568     if ret != 0:
569         print('Command "%s" failed with exit status %d' % (cmd, ret))
570         sys.exit(ret)
571     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
572
573     manpages = [
574         'ctdb.1',
575         'ctdb.7',
576         'ctdbd.1',
577         'ctdbd.conf.5',
578         'ctdbd_wrapper.1',
579         'ctdb-tunables.7',
580         'ltdbtool.1'
581     ]
582
583     cmd = 'make -C doc'
584     ret = samba_utils.RUN_COMMAND(cmd)
585     if ret != 0:
586         print('Command "%s" failed with exit status %d' % (cmd, ret))
587         sys.exit(ret)
588     for t in manpages:
589         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
590         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
591                               extend=True)
592
593     samba_dist.dist()
594
595 def rpmonly(ctx):
596     cmd = 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
597     ret = samba_utils.RUN_COMMAND(cmd)
598     if ret != 0:
599         print('rpmbuild exited with exit status %d' % ret)
600         sys.exit(ret)
601
602 def rpm(ctx):
603     import Scripting
604     Scripting.commands.append('dist')
605     Scripting.commands.append('rpmonly')
606
607 def ctags(ctx):
608     "build 'tags' file using ctags"
609     import Utils
610     source_root = os.path.dirname(Utils.g_module.root_path)
611     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
612     print("Running: %s" % cmd)
613     ret = samba_utils.RUN_COMMAND(cmd)
614     if ret != 0:
615         print('ctags failed with exit status %d' % ret)
616         sys.exit(ret)