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