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