ctdb-protocol: Add marshalling for eventd protocol
[ambi/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 default_prefix = 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                         lib/async_req:lib/async_req
38                         buildtools:buildtools third_party/waf:third_party/waf''')
39
40 manpages_binary = [
41     'ctdb.1',
42     'ctdbd.1',
43     'ltdbtool.1',
44     'ping_pong.1'
45 ]
46
47 manpages_misc = [
48     'ctdb_diagnostics.1',
49     'ctdbd_wrapper.1',
50     'onnode.1',
51     'ctdbd.conf.5',
52     'ctdb.7',
53     'ctdb-statistics.7',
54     'ctdb-tunables.7',
55 ]
56
57 manpages_etcd = [
58     'ctdb-etcd.7',
59 ]
60
61 manpages_ceph = [
62     'ctdb_mutex_ceph_rados_helper.7',
63 ]
64
65
66 def set_options(opt):
67     opt.PRIVATE_EXTENSION_DEFAULT('ctdb')
68
69     opt.RECURSE('lib/replace')
70
71     opt.RECURSE('lib/util')
72
73     opt.RECURSE('lib/talloc')
74     opt.RECURSE('lib/tevent')
75     opt.RECURSE('lib/tdb')
76
77     opt.add_option('--enable-infiniband',
78                    help=("Turn on infiniband support (default=no)"),
79                    action="store_true", dest='ctdb_infiniband', default=False)
80     opt.add_option('--enable-pmda',
81                    help=("Turn on PCP pmda support (default=no)"),
82                    action="store_true", dest='ctdb_pmda', default=False)
83     opt.add_option('--enable-etcd-reclock',
84                    help=("Enable etcd recovery lock helper (default=no)"),
85                    action="store_true", dest='ctdb_etcd_reclock', default=False)
86     opt.add_option('--enable-ceph-reclock',
87                    help=("Enable Ceph CTDB recovery lock helper (default=no)"),
88                    action="store_true", dest='ctdb_ceph_reclock', default=False)
89
90     opt.add_option('--with-logdir',
91                    help=("Path to log directory"),
92                    action="store", dest='ctdb_logdir', default=None)
93     opt.add_option('--with-socketpath',
94                    help=("path to CTDB daemon socket"),
95                    action="store", dest='ctdb_sockpath', default=None)
96
97
98 def configure(conf):
99
100     # No need to build python bindings for talloc/tevent/tdb
101     if conf.IN_LAUNCH_DIR():
102         conf.env.standalone_ctdb = True
103         Options.options.disable_python = True
104
105     conf.RECURSE('lib/replace')
106
107     if conf.env.standalone_ctdb:
108         conf.SAMBA_CHECK_PERL(mandatory=True)
109
110         conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2,5,0))
111         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
112
113     if conf.CHECK_FOR_THIRD_PARTY():
114         conf.RECURSE('third_party/popt')
115     else:
116         if not conf.CHECK_POPT():
117             raise Utils.WafError('popt development packages have not been found\nIf third_party is installed, check that it is in the proper place.')
118         else:
119             conf.define('USING_SYSTEM_POPT', 1)
120
121     conf.RECURSE('lib/util')
122
123     conf.RECURSE('lib/talloc')
124     conf.RECURSE('lib/tevent')
125     conf.RECURSE('lib/tdb')
126     if conf.env.standalone_ctdb or conf.CONFIG_GET('ENABLE_SELFTEST'):
127         conf.RECURSE('lib/socket_wrapper')
128         conf.env.SOCKET_WRAPPER_SO_PATH = conf.CONFIG_GET('LIBSOCKET_WRAPPER_SO_PATH')
129
130     conf.CHECK_HEADERS('sched.h')
131     conf.CHECK_HEADERS('procinfo.h')
132     if sys.platform.startswith('aix') and not conf.CHECK_FUNCS('thread_setsched'):
133         Logs.error('Need thread_setsched() on AIX')
134         sys.exit(1)
135     elif not conf.CHECK_FUNCS('sched_setscheduler'):
136         Logs.error('Need sched_setscheduler()')
137         sys.exit(1)
138     conf.CHECK_FUNCS('mlockall')
139
140     if not conf.CHECK_VARIABLE('ETIME', headers='errno.h'):
141         conf.DEFINE('ETIME', 'ETIMEDOUT')
142
143     if sys.platform.startswith('linux'):
144         conf.SET_TARGET_TYPE('pcap', 'EMPTY')
145     else:
146         if not conf.CHECK_HEADERS('pcap.h'):
147             Logs.error('Need libpcap')
148             sys.exit(1)
149         if not conf.CHECK_FUNCS_IN('pcap_open_live', 'pcap', headers='pcap.h'):
150             Logs.error('Need libpcap')
151             sys.exit(1)
152
153     if not conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo',
154                                checklibc=True, headers='execinfo.h'):
155         Logs.error('backtrace support not available')
156
157     have_pmda = False
158     if Options.options.ctdb_pmda:
159         pmda_support = True
160
161         if not conf.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
162                                   together=True):
163             pmda_support = False
164         if not conf.CHECK_FUNCS_IN('pmProgname', 'pcp'):
165             pmda_support = False
166         if not conf.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
167             pmda_support = False
168         if pmda_support:
169             have_pmda = True
170         else:
171             Logs.error("PMDA support not available")
172             sys.exit(1)
173     if have_pmda:
174         Logs.info('Building with PMDA support')
175         conf.define('HAVE_PMDA', 1)
176         conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
177                                              'lib/pcp/pmdas/ctdb')
178
179     have_infiniband = False
180     if Options.options.ctdb_infiniband:
181         ib_support = True
182
183         if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
184             ib_support = False
185         if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
186             ib_support = False
187         if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
188             ib_support = False
189         if ib_support:
190             have_infiniband = True
191         else:
192             Logs.error("Infiniband support not available")
193             sys.exit(1)
194     if have_infiniband:
195         Logs.info('Building with Infiniband support')
196         conf.define('HAVE_INFINIBAND', 1)
197         conf.define('USE_INFINIBAND', 1)
198
199     have_etcd_reclock = False
200     if Options.options.ctdb_etcd_reclock:
201         try:
202             conf.check_python_module('etcd')
203             have_etcd_reclock = True
204         except:
205             Logs.error('etcd support not available')
206             sys.exit(1)
207     if have_etcd_reclock:
208         Logs.info('Building with etcd support')
209     conf.env.etcd_reclock = have_etcd_reclock
210
211     if Options.options.ctdb_ceph_reclock:
212         if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
213                                         conf.CHECK_LIB('rados', shlib=True)):
214             Logs.info('Building with Ceph librados recovery lock support')
215             conf.define('HAVE_LIBRADOS', 1)
216         else:
217             Logs.error("Missing librados for Ceph recovery lock support")
218             sys.exit(1)
219
220     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
221     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
222     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
223     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
224     conf.env.CTDB_HELPER_BINDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb')
225
226     if Options.options.ctdb_logdir:
227         conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
228     else:
229         conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
230
231     if Options.options.ctdb_sockpath:
232         conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
233     else:
234         conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
235                                               'ctdbd.socket')
236     conf.define('CTDB_SOCKET', conf.env.CTDB_SOCKPATH)
237
238     conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
239                        -DLOGDIR=\"%s\"
240                        -DCTDB_ETCDIR=\"%s\"
241                        -DCTDB_VARDIR=\"%s\"
242                        -DCTDB_RUNDIR=\"%s\"''' % (
243                     conf.env.CTDB_HELPER_BINDIR,
244                     conf.env.CTDB_LOGDIR,
245                     conf.env.CTDB_ETCDIR,
246                     conf.env.CTDB_VARDIR,
247                     conf.env.CTDB_RUNDIR))
248
249     conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
250                                               'share/ctdb/tests')
251     conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
252
253     # Allow unified compilation and separate compilation of utilities
254     # to find includes
255     if not conf.env.standalone_ctdb:
256         conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
257     else:
258         if srcdir == '.':
259             # Building from tarball
260             conf.ADD_EXTRA_INCLUDES('#include')
261         else:
262             # Building standalone CTDB from within Samba tree
263             conf.ADD_EXTRA_INCLUDES('#ctdb/include')
264             conf.ADD_EXTRA_INCLUDES('#ctdb')
265         conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
266
267         conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
268         conf.DEFINE('SAMBA_UTIL_CORE_ONLY', 1, add_to_cflags=True)
269         conf.SAMBA_CONFIG_H()
270
271     if 'XSLTPROC_MANPAGES' in conf.env and conf.env['XSLTPROC_MANPAGES']:
272         conf.env.ctdb_generate_manpages = True
273     else:
274         conf.env.ctdb_generate_manpages = False
275
276         Logs.info("xsltproc unavailable, checking for pre-built manpages")
277         conf.env.ctdb_prebuilt_manpages = []
278         manpages = manpages_binary + manpages_misc
279         if conf.env.etcd_reclock:
280             manpages += manpages_etcd
281         if conf.env.HAVE_LIBRADOS:
282             manpages += manpages_ceph
283         for m in manpages:
284             if os.path.exists(os.path.join("doc", m)):
285                 Logs.info("  %s: yes" % (m))
286                 conf.env.ctdb_prebuilt_manpages.append(m)
287             else:
288                 Logs.info("  %s: no" % (m))
289
290 def build(bld):
291     if bld.env.standalone_ctdb:
292         # enable building of public headers in the build tree
293         bld.env.build_public_headers = 'include/public'
294
295     version_h = samba_utils.os_path_relpath(os.path.join(Options.launch_dir,
296                                                          "version.h"),
297                                             bld.curdir)
298
299     if bld.env.standalone_ctdb:
300         ctdb_mkversion = '../packaging/mkversion.sh'
301         t = bld.SAMBA_GENERATOR('ctdb-version-header',
302                                 target='include/ctdb_version.h',
303                                 rule='%s ${TGT} %s' % (ctdb_mkversion, VERSION),
304                                 dep_vars=['VERSION'])
305         t.env.VERSION = VERSION
306
307         t = bld.SAMBA_GENERATOR('ctdb-samba-version-header',
308                                 target=version_h,
309                                 rule='printf "#include \\"ctdb_version.h\\" \\n#define SAMBA_VERSION_STRING CTDB_VERSION_STRING\\n" > ${TGT}',
310                                 dep_vars=['VERSION'])
311         t.env.VERSION = VERSION
312     else:
313         t = bld.SAMBA_GENERATOR('ctdb-samba-version-header',
314                                 target='include/ctdb_version.h',
315                                 rule='printf "#include \\"%s\\" \\n#define CTDB_VERSION_STRING SAMBA_VERSION_STRING\\n" > ${TGT}' % version_h,
316                                 dep_vars=['VERSION'])
317         t.env.VERSION = VERSION
318
319     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
320
321     bld.RECURSE('lib/replace')
322     if bld.CHECK_FOR_THIRD_PARTY():
323         bld.RECURSE('third_party/popt')
324
325     bld.RECURSE('lib/tdb_wrap')
326     bld.RECURSE('lib/util')
327     bld.RECURSE('lib/async_req')
328
329     bld.RECURSE('lib/talloc')
330     bld.RECURSE('lib/tevent')
331     bld.RECURSE('lib/tdb')
332     if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
333         bld.RECURSE('lib/socket_wrapper')
334
335     if bld.env.standalone_ctdb:
336         # If a combined build is implemented, CTDB will want to
337         # build against samba-util rather than samba-util-core.
338         # Similarly, other Samba subsystems expect samba-util.  So,
339         # for a standalone build, just define a fake samba-util
340         # subsystem that pulls in samba-util-core.
341         bld.SAMBA_SUBSYSTEM('samba-util',
342                             source='',
343                             deps='samba-util-core')
344
345     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
346                         source=bld.SUBDIR('tcp',
347                                           'tcp_connect.c tcp_init.c tcp_io.c'),
348                         includes='include',
349                         deps='replace tdb talloc tevent')
350
351     ib_deps = ''
352     if bld.env.HAVE_INFINIBAND:
353         bld.SAMBA_SUBSYSTEM('ctdb-ib',
354                             source=bld.SUBDIR('ib',
355                                               '''ibwrapper.c ibw_ctdb.c
356                                                  ibw_ctdb_init.c'''),
357                             includes='include',
358                             deps='replace talloc tevent tdb')
359         ib_deps = ' ctdb-ib rdmacm ibverbs'
360
361     if sys.platform.startswith('linux'):
362         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
363     elif sys.platform.startswith('aix'):
364         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
365     elif sys.platform.startswith('freebsd'):
366         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
367     elif sys.platform.startswith('gnukfreebsd'):
368         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
369     elif sys.platform == 'gnu':
370         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
371     else:
372         Logs.error("Platform %s not supported" % sys.platform)
373
374     bld.SAMBA_SUBSYSTEM('ctdb-system',
375                         source=bld.SUBDIR('common',
376                                           'system_common.c system_util.c') +
377                                CTDB_SYSTEM_SRC,
378                         includes='include',
379                         deps='replace talloc tevent tdb pcap samba-util')
380
381     bld.SAMBA_SUBSYSTEM('ctdb-common',
382                         source=bld.SUBDIR('common',
383                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
384                                              sock_io.c'''),
385                         includes='include',
386                         deps='replace popt talloc tevent tdb popt ctdb-system')
387
388     bld.SAMBA_SUBSYSTEM('ctdb-util',
389                         source=bld.SUBDIR('common',
390                                           '''db_hash.c srvid.c reqid.c
391                                              pkt_read.c pkt_write.c comm.c
392                                              logging.c rb_tree.c tunable.c
393                                              pidfile.c run_proc.c'''),
394                         deps='''samba-util sys_rw tevent-util
395                                 replace talloc tevent tdb''')
396
397     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
398                         source=bld.SUBDIR('protocol',
399                                           '''protocol_header.c protocol_packet.c
400                                              protocol_types.c protocol_call.c
401                                              protocol_message.c
402                                              protocol_control.c
403                                              protocol_client.c
404                                              protocol_debug.c
405                                              protocol_util.c
406                                              protocol_event.c'''),
407                         includes='include',
408                         deps='replace talloc tdb')
409
410     bld.SAMBA_SUBSYSTEM('ctdb-client',
411                         source=bld.SUBDIR('client', 'ctdb_client.c'),
412                         includes='include',
413                         deps='''replace popt talloc tevent tdb
414                                 samba-util tdb-wrap ctdb-util''')
415
416     bld.SAMBA_SUBSYSTEM('ctdb-client2',
417                         source=bld.SUBDIR('client',
418                                           '''client_connect.c client_call.c
419                                              client_message.c client_control.c
420                                              client_message_sync.c
421                                              client_control_sync.c
422                                              client_db.c client_util.c
423                                           '''),
424                         includes='include',
425                         deps='replace talloc tevent tdb tdb-wrap')
426
427     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
428                         source=bld.SUBDIR('common',
429                                           '''sock_daemon.c'''),
430                         deps='''samba-util ctdb-util tevent-util
431                                 replace talloc tevent''')
432
433     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
434                         source=bld.SUBDIR('server',
435                                           '''ipalloc_deterministic.c
436                                              ipalloc_nondeterministic.c
437                                              ipalloc_lcp2.c
438                                              ipalloc_common.c
439                                              ipalloc.c
440                                           '''),
441                         includes='include',
442                         deps='ctdb-protocol replace talloc tevent')
443
444     bld.SAMBA_BINARY('ctdbd',
445                      source='server/ctdbd.c ' +
446                                bld.SUBDIR('server',
447                                           '''ctdb_daemon.c ctdb_recoverd.c
448                                              ctdb_recover.c ctdb_freeze.c
449                                              ctdb_tunables.c ctdb_monitor.c
450                                              ctdb_server.c ctdb_control.c
451                                              ctdb_call.c ctdb_ltdb_server.c
452                                              ctdb_traverse.c eventscript.c
453                                              ctdb_takeover.c
454                                              ctdb_persistent.c ctdb_keepalive.c
455                                              ctdb_cluster_mutex.c
456                                              ctdb_logging.c
457                                              ctdb_uptime.c
458                                              ctdb_vacuum.c ctdb_banning.c
459                                              ctdb_statistics.c
460                                              ctdb_update_record.c
461                                              ctdb_lock.c ctdb_fork.c'''),
462                      includes='include',
463                      deps='''ctdb-ipalloc ctdb-client ctdb-common ctdb-system
464                              ctdb-tcp ctdb-util replace sys_rw popt
465                              talloc tevent tdb talloc_report''' +
466                           ib_deps,
467                      install_path='${SBINDIR}',
468                      manpages='ctdbd.1')
469
470     bld.SAMBA_BINARY('ctdb',
471                      source='tools/ctdb.c',
472                      deps='''ctdb-client2 ctdb-protocol ctdb-util ctdb-system
473                              samba-util sys_rw popt''',
474                      install_path='${BINDIR}',
475                      manpages='ctdb.1')
476
477     bld.SAMBA_BINARY('ctdb_killtcp',
478                      source='tools/ctdb_killtcp.c',
479                      deps='''ctdb-protocol ctdb-util ctdb-system
480                              samba-util replace''',
481                      install_path='${CTDB_HELPER_BINDIR}')
482
483     bld.SAMBA_BINARY('ltdbtool',
484                      source='tools/ltdbtool.c',
485                      includes='include',
486                      deps='tdb',
487                      install_path='${BINDIR}',
488                      manpages='ltdbtool.1')
489
490     bld.SAMBA_BINARY('ctdb_lock_helper',
491                      source='server/ctdb_lock_helper.c',
492                      deps='samba-util sys_rw ctdb-system talloc tdb',
493                      includes='include',
494                      install_path='${CTDB_HELPER_BINDIR}')
495
496     bld.SAMBA_BINARY('ctdb_event_helper',
497                      source='server/ctdb_event_helper.c',
498                      includes='include',
499                      deps='samba-util sys_rw ctdb-system replace tdb',
500                      install_path='${CTDB_HELPER_BINDIR}')
501
502     bld.SAMBA_BINARY('ctdb_recovery_helper',
503                      source='server/ctdb_recovery_helper.c',
504                      deps='''ctdb-client2 ctdb-protocol ctdb-util
505                              samba-util sys_rw replace tdb''',
506                      install_path='${CTDB_HELPER_BINDIR}')
507
508     bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
509                      source='server/ctdb_mutex_fcntl_helper.c',
510                      deps='sys_rw ctdb-system',
511                      includes='include',
512                      install_path='${CTDB_HELPER_BINDIR}')
513
514     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
515                         source='utils/smnotify/smnotify.x',
516                         target='utils/smnotify/smnotify.h',
517                         rule='rpcgen -h ${SRC} > ${TGT}')
518
519     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
520
521     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
522                         source='utils/smnotify/smnotify.x',
523                         target='utils/smnotify/gen_xdr.c',
524                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
525
526     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
527                         source='utils/smnotify/smnotify.x',
528                         target='utils/smnotify/gen_smnotify.c',
529                         rule='rpcgen -l ${SRC} > ${TGT}')
530
531     bld.SAMBA_BINARY('smnotify',
532                      source=bld.SUBDIR('utils/smnotify',
533                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
534                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
535                      includes='utils utils/smnotify',
536                      install_path='${CTDB_HELPER_BINDIR}')
537
538     bld.SAMBA_BINARY('ping_pong',
539                      source='utils/ping_pong/ping_pong.c',
540                      deps='',
541                      install_path='${BINDIR}',
542                      manpages='ping_pong.1')
543
544     if bld.env.HAVE_PMDA:
545         bld.SAMBA_BINARY('pmdactdb',
546                          source='utils/pmda/pmda_ctdb.c',
547                          includes='include',
548                          deps='''ctdb-client2 ctdb-protocol ctdb-util
549                                  samba-util pcp_pmda pcp''',
550                          install_path='${CTDB_PMDADIR}')
551         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
552                           destname='Install')
553         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
554                           destname='Remove')
555         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
556                           destname='pmns')
557         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
558                           destname='domain.h')
559         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
560                           destname='help')
561         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
562                           destname='README')
563
564     if bld.env.HAVE_LIBRADOS:
565         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
566                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
567                          deps='talloc tevent rados',
568                          includes='include',
569                          install_path='${CTDB_HELPER_BINDIR}')
570
571     sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g'  % (bld.env.CTDB_VARDIR)
572     sed_expr2 = 's|/usr/local/etc/ctdb|%s|g'      % (bld.env.CTDB_ETCDIR)
573     sed_expr3 = 's|/usr/local/var/log|%s|g'       % (bld.env.CTDB_LOGDIR)
574     sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g'  % (bld.env.CTDB_RUNDIR)
575     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
576     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
577     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
578     sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
579                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
580                         sed_expr6, sed_expr7)
581
582     manpages_extra = manpages_misc
583     if bld.env.etcd_reclock:
584         manpages_extra += manpages_etcd
585     if bld.env.HAVE_LIBRADOS:
586         manpages_extra += manpages_ceph
587     for f in manpages_binary + manpages_extra:
588         x = '%s.xml' % (f)
589         bld.SAMBA_GENERATOR(x,
590                             source=os.path.join('doc', x),
591                             target=x,
592                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
593
594     if bld.env.ctdb_generate_manpages:
595         bld.MANPAGES(' '.join(manpages_extra), True)
596     else:
597         for m in bld.env.ctdb_prebuilt_manpages:
598             bld.SAMBA_GENERATOR(m,
599                                 source=os.path.join("doc", m),
600                                 target=m,
601                                 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
602             bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
603
604     bld.SAMBA_GENERATOR('ctdb-onnode',
605                         source='tools/onnode',
606                         target='onnode',
607                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
608     bld.INSTALL_FILES('${BINDIR}', 'onnode',
609                       destname='onnode', chmod=0755)
610
611     bld.SAMBA_GENERATOR('ctdb-diagnostics',
612                         source='tools/ctdb_diagnostics',
613                         target='ctdb_diagnostics',
614                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
615     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
616                       destname='ctdb_diagnostics', chmod=0755)
617
618     if bld.env.etcd_reclock:
619         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
620                             source='utils/etcd/ctdb_etcd_lock',
621                             target='ctdb_etcd_lock',
622                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
623         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
624                           destname='ctdb_etcd_lock', chmod=0744)
625
626     bld.SAMBA_GENERATOR('ctdb-natgw',
627                         source='tools/ctdb_natgw',
628                         target='ctdb_natgw',
629                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
630     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
631                       destname='ctdb_natgw', chmod=0755)
632
633     bld.SAMBA_GENERATOR('ctdb-lvs',
634                         source='tools/ctdb_lvs',
635                         target='ctdb_lvs',
636                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
637     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
638                       destname='ctdb_lvs', chmod=0755)
639
640     bld.SAMBA_GENERATOR('ctdbd-wrapper',
641                         source='config/ctdbd_wrapper',
642                         target='ctdbd_wrapper',
643                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
644     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
645                       destname='ctdbd_wrapper', chmod=0755)
646
647     def SUBDIR_MODE_callback(arg, dirname, fnames):
648         for f in fnames:
649             fl = os.path.join(dirname, f)
650             if os.path.isdir(fl) or os.path.islink(fl):
651                 continue
652             mode = os.lstat(fl).st_mode & 0777
653             if arg['trim_path']:
654                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
655             arg['file_list'].append([fl, mode])
656
657     def SUBDIR_MODE(path, trim_path=None):
658         pd = {'trim_path': trim_path, 'file_list': []}
659         os.path.walk(path, SUBDIR_MODE_callback, pd)
660         return pd['file_list']
661
662     etc_subdirs = [
663         'events.d',
664         'nfs-checks.d'
665     ]
666
667     if bld.env.standalone_ctdb:
668         configdir = 'config'
669     else:
670         configdir = 'ctdb/config'
671
672     for t in etc_subdirs:
673         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
674         for fmode in files:
675             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
676                               destname=fmode[0], chmod=fmode[1])
677
678     bld.SAMBA_GENERATOR('ctdb-functions',
679                         source='config/functions',
680                         target='functions',
681                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
682     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
683
684     etc_scripts = [
685         'ctdb-crash-cleanup.sh',
686         'debug-hung-script.sh',
687         'debug_locks.sh',
688         'gcore_trace.sh',
689         'nfs-linux-kernel-callout',
690         'notify.sh',
691         'statd-callout'
692     ]
693
694     for t in etc_scripts:
695         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
696                           destname=t, chmod=0755)
697
698     bld.SAMBA_GENERATOR('ctdb-sudoers',
699                         source='config/ctdb.sudoers',
700                         target='ctdb.sudoers',
701                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
702     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
703                       destname='ctdb')
704
705     bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
706                       destname='README')
707
708     bld.install_dir(bld.env.CTDB_LOGDIR)
709     bld.install_dir(bld.env.CTDB_RUNDIR)
710     bld.install_dir(bld.env.CTDB_VARDIR)
711
712     # Unit tests
713     ctdb_unit_tests = [
714         'db_hash_test',
715         'srvid_test',
716         'pkt_read_test',
717         'pkt_write_test',
718         'comm_test',
719         'comm_server_test',
720         'comm_client_test',
721         'protocol_types_test',
722         'protocol_client_test',
723         'pidfile_test',
724         'run_proc_test',
725         'sock_daemon_test',
726     ]
727
728     for target in ctdb_unit_tests:
729         src = 'tests/src/' + target + '.c'
730
731         bld.SAMBA_BINARY(target,
732                          source=src,
733                          deps='''talloc tevent tdb tevent-util
734                                  LIBASYNC_REQ samba-util sys_rw''',
735                          install_path='${CTDB_TEST_LIBEXECDIR}')
736
737     bld.SAMBA_BINARY('reqid_test',
738                      source='tests/src/reqid_test.c',
739                      deps='samba-util',
740                      install_path='${CTDB_TEST_LIBEXECDIR}')
741
742     bld.SAMBA_BINARY('rb_test',
743                      source='tests/src/rb_test.c',
744                      deps='samba-util talloc',
745                      install_path='${CTDB_TEST_LIBEXECDIR}')
746
747     bld.SAMBA_BINARY('ctdb_packet_parse',
748                      source='tests/src/ctdb_packet_parse.c',
749                      deps='talloc tevent tdb ctdb-protocol',
750                      install_path='${CTDB_TEST_LIBEXECDIR}')
751
752     bld.SAMBA_BINARY('porting_tests',
753                      source='tests/src/porting_tests.c',
754                      deps='samba-util ctdb-system popt',
755                      install_path='${CTDB_TEST_LIBEXECDIR}')
756
757
758     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
759                         source=bld.SUBDIR('tests/src',
760                                           'cluster_wait.c test_options.c'),
761                         includes='include',
762                         deps='replace popt talloc tevent tdb')
763
764     bld.SAMBA_BINARY('protocol_util_test',
765                      source='tests/src/protocol_util_test.c',
766                      deps='talloc ctdb-protocol samba-util',
767                      install_path='${CTDB_TEST_LIBEXECDIR}')
768
769     # Test binaries
770     ctdb_tests = [
771         'g_lock_loop',
772         'message_ring',
773         'fetch_ring',
774         'fetch_loop',
775         'fetch_loop_key',
776         'fetch_readonly',
777         'fetch_readonly_loop',
778         'transaction_loop',
779         'update_record',
780         'update_record_persistent',
781         'lock_tdb'
782     ]
783
784     for target in ctdb_tests:
785         src = 'tests/src/' + target + '.c'
786
787         bld.SAMBA_BINARY(target,
788                          source=src,
789                          includes='include',
790                          deps='''ctdb-client2 ctdb-protocol ctdb-util
791                                  samba-util ctdb-tests-common''',
792                          install_path='${CTDB_TEST_LIBEXECDIR}')
793
794     bld.SAMBA_BINARY('ctdb_takeover_tests',
795                      source='tests/src/ctdb_takeover_tests.c',
796                      deps='''replace popt tdb tevent talloc ctdb-system
797                              samba-util tdb-wrap talloc_report
798                              ctdb-ipalloc ctdb-protocol ctdb-util''',
799                      includes='include',
800                      install_path='${CTDB_TEST_LIBEXECDIR}')
801
802     bld.SAMBA_BINARY('fake_ctdbd',
803                      source='tests/src/fake_ctdbd.c',
804                      deps='''ctdb-util ctdb-protocol ctdb-system
805                              samba-util tevent-util LIBASYNC_REQ popt''',
806                      install_path='${CTDB_TEST_LIBEXECDIR}')
807
808     if bld.env.HAVE_INFINIBAND:
809         bld.SAMBA_BINARY('ibwrapper_test',
810                          source='ib/ibwrapper_test.c',
811                          includes='include',
812                          deps='replace talloc ctdb-client ctdb-common sys_rw' +
813                               ib_deps,
814                          install_path='${CTDB_TEST_LIBEXECDIR}')
815
816     test_subdirs = [
817         'complex',
818         'cunit',
819         'events.d',
820         'eventscripts',
821         'onnode',
822         'shellcheck',
823         'simple',
824         'takeover',
825         'tool'
826     ]
827
828     for t in test_subdirs:
829         files = SUBDIR_MODE('tests/%s' % t, trim_path='tests')
830         for fmode in files:
831             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
832                               destname=fmode[0], chmod=fmode[1])
833
834     # Install tests/scripts directory without test_wrap
835     test_scripts = [
836         'common.sh',
837         'integration.bash',
838         'unit.sh'
839     ]
840
841     for t in test_scripts:
842         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
843                           os.path.join('tests/scripts', t),
844                           destname=os.path.join('scripts', t))
845
846     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
847                bld.env.CTDB_TEST_LIBEXECDIR)
848     bld.SAMBA_GENERATOR('ctdb-test-wrap',
849                         source='tests/scripts/test_wrap',
850                         target='test_wrap',
851                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
852     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
853                       destname='test_wrap', chmod=0755)
854
855     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
856                         source='tests/scripts/script_install_paths.sh',
857                         target='script_install_paths.sh',
858                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
859     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
860                       'script_install_paths.sh',
861                       destname='script_install_paths.sh', chmod=0644)
862
863     sed_expr1 = 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
864                 bld.env.CTDB_TEST_DATADIR, bld.env.CTDB_TEST_LIBEXECDIR)
865     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
866     bld.SAMBA_GENERATOR('ctdb-test-runner',
867                         source='tests/run_tests.sh',
868                         target='ctdb_run_tests.sh',
869                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
870                              sed_expr1, sed_expr2))
871     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
872                       destname='ctdb_run_tests', chmod=0755)
873     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
874                    'ctdb_run_tests')
875
876     test_eventscript_links = [
877         'events.d',
878         'functions',
879         'nfs-checks.d',
880         'nfs-linux-kernel-callout',
881         'statd-callout'
882     ]
883
884     test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
885                                  'eventscripts/etc-ctdb')
886     for t in test_eventscript_links:
887         bld.symlink_as(os.path.join(test_link_dir, t),
888                        os.path.join(bld.env.CTDB_ETCDIR, t))
889
890     # Tests that use onnode need to overwrite link to in-tree
891     # functions file when installed
892     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'onnode/functions'),
893                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
894     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/functions'),
895                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
896
897     # Need a link to nodes file because $CTDB_BASE is overridden
898     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/nodes'),
899                    os.path.join(bld.env.CTDB_ETCDIR, 'nodes'))
900
901
902 def testonly(ctx):
903     cmd = 'tests/run_tests.sh -V tests/var'
904     ret = samba_utils.RUN_COMMAND(cmd)
905     if ret != 0:
906         print('tests exited with exit status %d' % ret)
907         sys.exit(ret)
908
909
910 def test(ctx):
911     import Scripting
912     Scripting.commands.append('build')
913     Scripting.commands.append('testonly')
914
915
916 def autotest(ctx):
917     env = samba_utils.LOAD_ENVIRONMENT()
918     ld = 'LD_PRELOAD=%s' % env.SOCKET_WRAPPER_SO_PATH
919     cmd = '%s tests/run_tests.sh -e -S -C' % ld
920     ret = samba_utils.RUN_COMMAND(cmd)
921     if ret != 0:
922         print('autotest exited with exit status %d' % ret)
923         sys.exit(ret)
924
925
926 def show_version(ctx):
927     print VERSION
928
929
930 def dist():
931     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
932
933     t = 'include/ctdb_version.h'
934     cmd = 'packaging/mkversion.sh %s %s' % (t, VERSION)
935     ret = samba_utils.RUN_COMMAND(cmd)
936     if ret != 0:
937         print('Command "%s" failed with exit status %d' % (cmd, ret))
938         sys.exit(ret)
939     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
940
941     t = 'ctdb.spec'
942     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
943     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
944     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
945         sed_expr1, sed_expr2, t)
946     ret = samba_utils.RUN_COMMAND(cmd)
947     if ret != 0:
948         print('Command "%s" failed with exit status %d' % (cmd, ret))
949         sys.exit(ret)
950     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
951
952     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
953     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
954     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
955     CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
956     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
957     for t in manpages:
958         cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
959         ret = samba_utils.RUN_COMMAND(cmd)
960         if ret != 0:
961             print('Command %s failed with exit status %d' % (cmd, ret))
962             sys.exit(ret)
963
964         cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
965         ret = samba_utils.RUN_COMMAND(cmd)
966         if ret != 0:
967             print('Command %s failed with exit status %d' % (cmd, ret))
968             sys.exit(ret)
969
970         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
971         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
972                               extend=True)
973
974     samba_dist.dist()
975
976
977 def rpmonly(ctx):
978     opts = os.getenv('RPM_OPTIONS') or ''
979     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
980     ret = samba_utils.RUN_COMMAND(cmd)
981     if ret != 0:
982         print('rpmbuild exited with exit status %d' % ret)
983         sys.exit(ret)
984
985
986 def rpm(ctx):
987     import Scripting
988     Scripting.commands.append('dist')
989     Scripting.commands.append('rpmonly')
990
991
992 def ctags(ctx):
993     "build 'tags' file using ctags"
994     import Utils
995     source_root = os.path.dirname(Utils.g_module.root_path)
996     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
997     print("Running: %s" % cmd)
998     ret = samba_utils.RUN_COMMAND(cmd)
999     if ret != 0:
1000         print('ctags failed with exit status %d' % ret)
1001         sys.exit(ret)