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