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