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