fdd187b7d26c99550f911385aafc322b40ac0ec7
[metze/samba/wip.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=False, version=(2,5,0))
111         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
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 gen_ctdb_version(task):
291     fp = file(task.outputs[0].bldpath(task.env), 'w')
292     fp.write('/* This file is auto-generated from waf */\n')
293     fp.write('#include "version.h"\n')
294     fp.write('\n')
295     fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
296     fp.close()
297
298
299 def build(bld):
300     if bld.env.standalone_ctdb:
301         # enable building of public headers in the build tree
302         bld.env.build_public_headers = 'include/public'
303
304     if bld.env.standalone_ctdb:
305         bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
306
307     t = bld.SAMBA_GENERATOR('ctdb-version-header',
308                             target='include/ctdb_version.h',
309                             rule=gen_ctdb_version,
310                             dep_vars=['VERSION'])
311     t.env.VERSION = VERSION
312
313     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
314
315     bld.RECURSE('lib/replace')
316     if bld.CHECK_FOR_THIRD_PARTY():
317         bld.RECURSE('third_party/popt')
318
319     bld.RECURSE('lib/tdb_wrap')
320     bld.RECURSE('lib/util')
321     bld.RECURSE('lib/async_req')
322
323     bld.RECURSE('lib/talloc')
324     bld.RECURSE('lib/tevent')
325     bld.RECURSE('lib/tdb')
326     if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
327         bld.RECURSE('lib/socket_wrapper')
328
329     if bld.env.standalone_ctdb:
330         # If a combined build is implemented, CTDB will want to
331         # build against samba-util rather than samba-util-core.
332         # Similarly, other Samba subsystems expect samba-util.  So,
333         # for a standalone build, just define a fake samba-util
334         # subsystem that pulls in samba-util-core.
335         bld.SAMBA_SUBSYSTEM('samba-util',
336                             source='',
337                             deps='samba-util-core')
338
339     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
340                         source=bld.SUBDIR('tcp',
341                                           'tcp_connect.c tcp_init.c tcp_io.c'),
342                         includes='include',
343                         deps='replace tdb talloc tevent')
344
345     ib_deps = ''
346     if bld.env.HAVE_INFINIBAND:
347         bld.SAMBA_SUBSYSTEM('ctdb-ib',
348                             source=bld.SUBDIR('ib',
349                                               '''ibwrapper.c ibw_ctdb.c
350                                                  ibw_ctdb_init.c'''),
351                             includes='include',
352                             deps='replace talloc tevent tdb')
353         ib_deps = ' ctdb-ib rdmacm ibverbs'
354
355     if sys.platform.startswith('linux'):
356         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
357     elif sys.platform.startswith('aix'):
358         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
359     elif sys.platform.startswith('freebsd'):
360         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
361     elif sys.platform.startswith('gnukfreebsd'):
362         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
363     elif sys.platform == 'gnu':
364         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
365     else:
366         Logs.error("Platform %s not supported" % sys.platform)
367
368     bld.SAMBA_SUBSYSTEM('ctdb-system',
369                         source=bld.SUBDIR('common',
370                                           'system_common.c system_util.c') +
371                                CTDB_SYSTEM_SRC,
372                         includes='include',
373                         deps='replace talloc tevent tdb pcap samba-util')
374
375     bld.SAMBA_SUBSYSTEM('ctdb-common',
376                         source=bld.SUBDIR('common',
377                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
378                                              sock_io.c'''),
379                         includes='include',
380                         deps='''replace popt talloc tevent tdb popt ctdb-system
381                                 ctdb-protocol-util''')
382
383     bld.SAMBA_SUBSYSTEM('ctdb-util',
384                         source=bld.SUBDIR('common',
385                                           '''db_hash.c srvid.c reqid.c
386                                              pkt_read.c pkt_write.c comm.c
387                                              logging.c rb_tree.c tunable.c
388                                              pidfile.c run_proc.c
389                                              hash_count.c run_event.c
390                                              sock_client.c version.c'''),
391                         deps='''samba-util sys_rw tevent-util
392                                 replace talloc tevent tdb''')
393
394     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
395                         source=bld.SUBDIR('protocol',
396                                           '''protocol_header.c protocol_packet.c
397                                              protocol_basic.c protocol_types.c
398                                              protocol_call.c
399                                              protocol_message.c
400                                              protocol_control.c
401                                              protocol_keepalive.c
402                                              protocol_tunnel.c
403                                              protocol_client.c
404                                              protocol_debug.c
405                                              protocol_event.c
406                                              protocol_sock.c'''),
407                         includes='include',
408                         deps='replace talloc tdb')
409
410     bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
411                         source='protocol/protocol_util.c',
412                         deps='replace talloc tdb')
413
414     bld.SAMBA_SUBSYSTEM('ctdb-client',
415                         source=bld.SUBDIR('client', 'ctdb_client.c'),
416                         includes='include',
417                         deps='''replace popt talloc tevent tdb
418                                 samba-util tdb-wrap ctdb-util''')
419
420     bld.SAMBA_SUBSYSTEM('ctdb-client2',
421                         source=bld.SUBDIR('client',
422                                           '''client_connect.c client_call.c
423                                              client_message.c client_control.c
424                                              client_message_sync.c
425                                              client_control_sync.c
426                                              client_db.c client_util.c
427                                              client_event.c client_tunnel.c
428                                           '''),
429                         includes='include',
430                         deps='replace talloc tevent tdb tdb-wrap')
431
432     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
433                         source=bld.SUBDIR('common',
434                                           '''sock_daemon.c'''),
435                         deps='''samba-util ctdb-util tevent-util
436                                 replace talloc tevent''')
437
438     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
439                         source=bld.SUBDIR('server',
440                                           '''ipalloc_deterministic.c
441                                              ipalloc_nondeterministic.c
442                                              ipalloc_lcp2.c
443                                              ipalloc_common.c
444                                              ipalloc.c
445                                           '''),
446                         includes='include',
447                         deps='ctdb-protocol-util replace talloc tevent')
448
449     bld.SAMBA_BINARY('ctdbd',
450                      source='server/ctdbd.c ' +
451                                bld.SUBDIR('server',
452                                           '''ctdb_daemon.c ctdb_recoverd.c
453                                              ctdb_recover.c ctdb_freeze.c
454                                              ctdb_tunables.c ctdb_monitor.c
455                                              ctdb_server.c ctdb_control.c
456                                              ctdb_call.c ctdb_ltdb_server.c
457                                              ctdb_traverse.c eventscript.c
458                                              ctdb_takeover.c
459                                              ctdb_persistent.c ctdb_keepalive.c
460                                              ctdb_cluster_mutex.c
461                                              ctdb_logging.c
462                                              ctdb_uptime.c
463                                              ctdb_vacuum.c ctdb_banning.c
464                                              ctdb_statistics.c
465                                              ctdb_update_record.c
466                                              ctdb_lock.c ctdb_fork.c
467                                              ctdb_tunnel.c'''),
468                      includes='include',
469                      deps='''ctdb-client ctdb-common ctdb-system ctdb-protocol
470                              ctdb-tcp ctdb-util replace sys_rw popt
471                              talloc tevent tdb talloc_report''' +
472                           ib_deps,
473                      install_path='${SBINDIR}',
474                      manpages='ctdbd.1')
475
476     bld.SAMBA_BINARY('ctdb',
477                      source='tools/ctdb.c',
478                      deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
479                              ctdb-util ctdb-system samba-util sys_rw popt''',
480                      install_path='${BINDIR}',
481                      manpages='ctdb.1')
482
483     bld.SAMBA_BINARY('ctdb_killtcp',
484                      source='tools/ctdb_killtcp.c',
485                      deps='''ctdb-protocol-util ctdb-util ctdb-system
486                              samba-util replace''',
487                      install_path='${CTDB_HELPER_BINDIR}')
488
489     bld.SAMBA_BINARY('ctdb_event',
490                      source='tools/ctdb_event.c',
491                      deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
492                              ctdb-util ctdb-system samba-util replace''',
493                      install_path='${CTDB_HELPER_BINDIR}')
494
495     bld.SAMBA_BINARY('ltdbtool',
496                      source='tools/ltdbtool.c',
497                      includes='include',
498                      deps='tdb',
499                      install_path='${BINDIR}',
500                      manpages='ltdbtool.1')
501
502     bld.SAMBA_BINARY('ctdb_eventd',
503                      source='server/ctdb_eventd.c',
504                      deps='''ctdb-server-util ctdb-protocol ctdb-protocol-util
505                              ctdb-util samba-util LIBASYNC_REQ replace popt''',
506                      install_path='${CTDB_HELPER_BINDIR}')
507
508     bld.SAMBA_BINARY('ctdb_lock_helper',
509                      source='server/ctdb_lock_helper.c',
510                      deps='''samba-util sys_rw ctdb-system tevent-util
511                              talloc tevent tdb''',
512                      includes='include',
513                      install_path='${CTDB_HELPER_BINDIR}')
514
515     bld.SAMBA_BINARY('ctdb_recovery_helper',
516                      source='server/ctdb_recovery_helper.c',
517                      deps='''ctdb-client2 ctdb-protocol ctdb-util
518                              samba-util sys_rw replace tdb''',
519                      install_path='${CTDB_HELPER_BINDIR}')
520
521     bld.SAMBA_BINARY('ctdb_takeover_helper',
522                      source='server/ctdb_takeover_helper.c',
523                      deps='''ctdb-client2 ctdb-protocol ctdb-util
524                              samba-util sys_rw replace ctdb-ipalloc popt''',
525                      install_path='${CTDB_HELPER_BINDIR}')
526
527     bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
528                      source='server/ctdb_mutex_fcntl_helper.c',
529                      deps='sys_rw ctdb-system',
530                      includes='include',
531                      install_path='${CTDB_HELPER_BINDIR}')
532
533     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
534                         source='utils/smnotify/smnotify.x',
535                         target='utils/smnotify/smnotify.h',
536                         rule='rpcgen -h ${SRC} > ${TGT}')
537
538     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
539
540     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
541                         source='utils/smnotify/smnotify.x',
542                         target='utils/smnotify/gen_xdr.c',
543                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
544
545     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
546                         source='utils/smnotify/smnotify.x',
547                         target='utils/smnotify/gen_smnotify.c',
548                         rule='rpcgen -l ${SRC} > ${TGT}')
549
550     bld.SAMBA_BINARY('smnotify',
551                      source=bld.SUBDIR('utils/smnotify',
552                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
553                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
554                      includes='utils utils/smnotify',
555                      install_path='${CTDB_HELPER_BINDIR}')
556
557     bld.SAMBA_BINARY('ping_pong',
558                      source='utils/ping_pong/ping_pong.c',
559                      deps='',
560                      install_path='${BINDIR}',
561                      manpages='ping_pong.1')
562
563     if bld.env.HAVE_PMDA:
564         bld.SAMBA_BINARY('pmdactdb',
565                          source='utils/pmda/pmda_ctdb.c',
566                          includes='include',
567                          deps='''ctdb-client2 ctdb-protocol ctdb-util
568                                  samba-util pcp_pmda pcp''',
569                          install_path='${CTDB_PMDADIR}')
570         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
571                           destname='Install')
572         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
573                           destname='Remove')
574         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
575                           destname='pmns')
576         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
577                           destname='domain.h')
578         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
579                           destname='help')
580         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
581                           destname='README')
582
583     if bld.env.HAVE_LIBRADOS:
584         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
585                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
586                          deps='talloc tevent rados',
587                          includes='include',
588                          install_path='${CTDB_HELPER_BINDIR}')
589
590     sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g'  % (bld.env.CTDB_VARDIR)
591     sed_expr2 = 's|/usr/local/etc/ctdb|%s|g'      % (bld.env.CTDB_ETCDIR)
592     sed_expr3 = 's|/usr/local/var/log|%s|g'       % (bld.env.CTDB_LOGDIR)
593     sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g'  % (bld.env.CTDB_RUNDIR)
594     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
595     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
596     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
597     sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
598                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
599                         sed_expr6, sed_expr7)
600
601     manpages_extra = manpages_misc
602     if bld.env.etcd_reclock:
603         manpages_extra += manpages_etcd
604     if bld.env.HAVE_LIBRADOS:
605         manpages_extra += manpages_ceph
606     for f in manpages_binary + manpages_extra:
607         x = '%s.xml' % (f)
608         bld.SAMBA_GENERATOR(x,
609                             source=os.path.join('doc', x),
610                             target=x,
611                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
612
613     if bld.env.ctdb_generate_manpages:
614         bld.MANPAGES(' '.join(manpages_extra), True)
615     else:
616         for m in bld.env.ctdb_prebuilt_manpages:
617             bld.SAMBA_GENERATOR(m,
618                                 source=os.path.join("doc", m),
619                                 target=m,
620                                 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
621             bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
622
623     bld.SAMBA_GENERATOR('ctdb-onnode',
624                         source='tools/onnode',
625                         target='onnode',
626                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
627     bld.INSTALL_FILES('${BINDIR}', 'onnode',
628                       destname='onnode', chmod=0755)
629
630     bld.SAMBA_GENERATOR('ctdb-diagnostics',
631                         source='tools/ctdb_diagnostics',
632                         target='ctdb_diagnostics',
633                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
634     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
635                       destname='ctdb_diagnostics', chmod=0755)
636
637     if bld.env.etcd_reclock:
638         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
639                             source='utils/etcd/ctdb_etcd_lock',
640                             target='ctdb_etcd_lock',
641                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
642         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
643                           destname='ctdb_etcd_lock', chmod=0744)
644
645     bld.SAMBA_GENERATOR('ctdb-natgw',
646                         source='tools/ctdb_natgw',
647                         target='ctdb_natgw',
648                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
649     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
650                       destname='ctdb_natgw', chmod=0755)
651
652     bld.SAMBA_GENERATOR('ctdb-lvs',
653                         source='tools/ctdb_lvs',
654                         target='ctdb_lvs',
655                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
656     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
657                       destname='ctdb_lvs', chmod=0755)
658
659     bld.SAMBA_GENERATOR('ctdbd-wrapper',
660                         source='config/ctdbd_wrapper',
661                         target='ctdbd_wrapper',
662                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
663     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
664                       destname='ctdbd_wrapper', chmod=0755)
665
666     def SUBDIR_MODE_callback(arg, dirname, fnames):
667         for f in fnames:
668             fl = os.path.join(dirname, f)
669             if os.path.isdir(fl) or os.path.islink(fl):
670                 continue
671             mode = os.lstat(fl).st_mode & 0777
672             if arg['trim_path']:
673                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
674             arg['file_list'].append([fl, mode])
675
676     def SUBDIR_MODE(path, trim_path=None):
677         pd = {'trim_path': trim_path, 'file_list': []}
678         os.path.walk(path, SUBDIR_MODE_callback, pd)
679         return pd['file_list']
680
681     etc_subdirs = [
682         'events.d',
683         'nfs-checks.d'
684     ]
685
686     if bld.env.standalone_ctdb:
687         configdir = 'config'
688     else:
689         configdir = 'ctdb/config'
690
691     for t in etc_subdirs:
692         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
693         for fmode in files:
694             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
695                               destname=fmode[0], chmod=fmode[1])
696
697     bld.SAMBA_GENERATOR('ctdb-functions',
698                         source='config/functions',
699                         target='functions',
700                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
701     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
702
703     etc_scripts = [
704         'ctdb-crash-cleanup.sh',
705         'debug-hung-script.sh',
706         'debug_locks.sh',
707         'gcore_trace.sh',
708         'nfs-linux-kernel-callout',
709         'notify.sh',
710         'statd-callout'
711     ]
712
713     for t in etc_scripts:
714         bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % t,
715                           destname=t, chmod=0755)
716
717     bld.SAMBA_GENERATOR('ctdb-sudoers',
718                         source='config/ctdb.sudoers',
719                         target='ctdb.sudoers',
720                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
721     bld.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'ctdb.sudoers',
722                       destname='ctdb')
723
724     bld.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
725                       destname='README')
726
727     bld.install_dir(bld.env.CTDB_LOGDIR)
728     bld.install_dir(bld.env.CTDB_RUNDIR)
729     bld.install_dir(bld.env.CTDB_VARDIR)
730
731     # Unit tests
732     ctdb_unit_tests = [
733         'db_hash_test',
734         'srvid_test',
735         'pkt_read_test',
736         'pkt_write_test',
737         'comm_test',
738         'comm_server_test',
739         'comm_client_test',
740         'pidfile_test',
741         'run_proc_test',
742         'sock_daemon_test',
743         'sock_io_test',
744         'hash_count_test',
745         'run_event_test',
746     ]
747
748     for target in ctdb_unit_tests:
749         src = 'tests/src/' + target + '.c'
750
751         bld.SAMBA_BINARY(target,
752                          source=src,
753                          deps='''talloc tevent tdb tevent-util
754                                  LIBASYNC_REQ samba-util sys_rw''',
755                          install_path='${CTDB_TEST_LIBEXECDIR}')
756
757     bld.SAMBA_BINARY('reqid_test',
758                      source='tests/src/reqid_test.c',
759                      deps='samba-util',
760                      install_path='${CTDB_TEST_LIBEXECDIR}')
761
762     bld.SAMBA_BINARY('rb_test',
763                      source='tests/src/rb_test.c',
764                      deps='samba-util talloc',
765                      install_path='${CTDB_TEST_LIBEXECDIR}')
766
767     bld.SAMBA_BINARY('ctdb_packet_parse',
768                      source='tests/src/ctdb_packet_parse.c',
769                      deps='talloc tevent tdb ctdb-protocol',
770                      install_path='${CTDB_TEST_LIBEXECDIR}')
771
772     bld.SAMBA_BINARY('porting_tests',
773                      source='tests/src/porting_tests.c',
774                      deps='samba-util ctdb-system popt',
775                      install_path='${CTDB_TEST_LIBEXECDIR}')
776
777     bld.SAMBA_SUBSYSTEM('protocol-tests-common',
778                         source=bld.SUBDIR('tests/src',
779                                           '''protocol_common.c
780                                              protocol_common_ctdb.c
781                                              protocol_common_event.c
782                                           '''),
783                         includes='include',
784                         deps='replace popt talloc tevent tdb')
785
786     ctdb_protocol_tests = [
787             'protocol_basic_test',
788             'protocol_types_test',
789             'protocol_ctdb_test',
790             'protocol_event_test',
791             'protocol_util_test',
792             'protocol_types_compat_test',
793             'protocol_ctdb_compat_test',
794     ]
795
796     for target in ctdb_protocol_tests:
797         src = 'tests/src/' + target + '.c'
798
799         bld.SAMBA_BINARY(target,
800                          source=src,
801                          deps='''protocol-tests-common
802                                  samba-util talloc tdb''',
803                          install_path='${CTDB_TEST_LIBEXECDIR}')
804
805     bld.SAMBA_SUBSYSTEM('ctdb-tests-common',
806                         source=bld.SUBDIR('tests/src',
807                                           'cluster_wait.c test_options.c'),
808                         includes='include',
809                         deps='replace popt talloc tevent tdb')
810
811     # Test binaries
812     ctdb_tests = [
813         'g_lock_loop',
814         'message_ring',
815         'fetch_ring',
816         'fetch_loop',
817         'fetch_loop_key',
818         'fetch_readonly',
819         'fetch_readonly_loop',
820         'transaction_loop',
821         'update_record',
822         'update_record_persistent',
823         'lock_tdb',
824         'dummy_client',
825         'tunnel_test',
826         'tunnel_cmd',
827     ]
828
829     for target in ctdb_tests:
830         src = 'tests/src/' + target + '.c'
831
832         bld.SAMBA_BINARY(target,
833                          source=src,
834                          includes='include',
835                          deps='''ctdb-client2 ctdb-protocol ctdb-util
836                                  samba-util ctdb-tests-common''',
837                          install_path='${CTDB_TEST_LIBEXECDIR}')
838
839     bld.SAMBA_BINARY('ctdb_takeover_tests',
840                      source='''tests/src/ctdb_takeover_tests.c
841                                tests/src/ipalloc_read_known_ips.c''',
842                      deps='''replace popt tdb tevent talloc ctdb-system
843                              samba-util tdb-wrap talloc_report
844                              ctdb-ipalloc ctdb-protocol ctdb-util''',
845                      includes='include',
846                      install_path='${CTDB_TEST_LIBEXECDIR}')
847
848     bld.SAMBA_BINARY('fake_ctdbd',
849                      source='''tests/src/fake_ctdbd.c
850                                tests/src/ipalloc_read_known_ips.c''',
851                      deps='''ctdb-util ctdb-protocol ctdb-protocol-util
852                              ctdb-system samba-util tevent-util
853                              LIBASYNC_REQ popt''',
854                      install_path='${CTDB_TEST_LIBEXECDIR}')
855
856     if bld.env.HAVE_INFINIBAND:
857         bld.SAMBA_BINARY('ibwrapper_test',
858                          source='ib/ibwrapper_test.c',
859                          includes='include',
860                          deps='replace talloc ctdb-client ctdb-common sys_rw' +
861                               ib_deps,
862                          install_path='${CTDB_TEST_LIBEXECDIR}')
863
864     if bld.env.HAVE_ROBUST_MUTEXES and sys.platform.startswith('linux'):
865         bld.SAMBA_BINARY('test_mutex_raw',
866                          source='tests/src/test_mutex_raw.c',
867                          deps='pthread',
868                          install_path='${CTDB_TEST_LIBEXECDIR}')
869
870     test_subdirs = [
871         'complex',
872         'cunit',
873         'eventd',
874         'events.d',
875         'eventscripts',
876         'onnode',
877         'shellcheck',
878         'simple',
879         'takeover',
880         'takeover_helper',
881         'tool'
882     ]
883
884     if bld.env.standalone_ctdb:
885         testdir = 'tests'
886     else:
887         testdir = 'ctdb/tests'
888
889     for t in test_subdirs:
890         files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
891         for fmode in files:
892             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
893                               destname=fmode[0], chmod=fmode[1])
894
895     # Install tests/scripts directory without test_wrap
896     test_scripts = [
897         'common.sh',
898         'integration.bash',
899         'unit.sh'
900     ]
901
902     for t in test_scripts:
903         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
904                           os.path.join('tests/scripts', t),
905                           destname=os.path.join('scripts', t))
906
907     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
908                bld.env.CTDB_TEST_LIBEXECDIR)
909     bld.SAMBA_GENERATOR('ctdb-test-wrap',
910                         source='tests/scripts/test_wrap',
911                         target='test_wrap',
912                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
913     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
914                       destname='test_wrap', chmod=0755)
915
916     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
917                         source='tests/scripts/script_install_paths.sh',
918                         target='script_install_paths.sh',
919                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
920     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
921                       'script_install_paths.sh',
922                       destname='script_install_paths.sh', chmod=0644)
923
924     sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
925                     'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
926                     'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
927     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
928     bld.SAMBA_GENERATOR('ctdb-test-runner',
929                         source='tests/run_tests.sh',
930                         target='ctdb_run_tests.sh',
931                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
932                              sed_expr1, sed_expr2))
933     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
934                       destname='ctdb_run_tests', chmod=0755)
935     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
936                    'ctdb_run_tests')
937
938     test_eventscript_links = [
939         'events.d',
940         'functions',
941         'nfs-checks.d',
942         'nfs-linux-kernel-callout',
943         'statd-callout'
944     ]
945
946     test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
947                                  'eventscripts/etc-ctdb')
948     for t in test_eventscript_links:
949         bld.symlink_as(os.path.join(test_link_dir, t),
950                        os.path.join(bld.env.CTDB_ETCDIR, t))
951
952     # Tests that use onnode need to overwrite link to in-tree
953     # functions file when installed
954     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'onnode/functions'),
955                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
956     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/functions'),
957                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
958
959     # Need a link to nodes file because $CTDB_BASE is overridden
960     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/nodes'),
961                    os.path.join(bld.env.CTDB_ETCDIR, 'nodes'))
962
963
964 def testonly(ctx):
965     cmd = 'tests/run_tests.sh -V tests/var'
966     ret = samba_utils.RUN_COMMAND(cmd)
967     if ret != 0:
968         print('tests exited with exit status %d' % ret)
969         sys.exit(ret)
970
971
972 def test(ctx):
973     import Scripting
974     Scripting.commands.append('build')
975     Scripting.commands.append('testonly')
976
977
978 def autotest(ctx):
979     env = samba_utils.LOAD_ENVIRONMENT()
980     ld = 'LD_PRELOAD=%s' % env.SOCKET_WRAPPER_SO_PATH
981     cmd = '%s tests/run_tests.sh -e -S -C' % ld
982     ret = samba_utils.RUN_COMMAND(cmd)
983     if ret != 0:
984         print('autotest exited with exit status %d' % ret)
985         sys.exit(ret)
986
987
988 def show_version(ctx):
989     print VERSION
990
991
992 def manpages(ctx):
993     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
994     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
995     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
996     CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
997     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
998     for t in manpages:
999         cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
1000         ret = samba_utils.RUN_COMMAND(cmd)
1001         if ret != 0:
1002             print('Command %s failed with exit status %d' % (cmd, ret))
1003             sys.exit(ret)
1004
1005         cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
1006         ret = samba_utils.RUN_COMMAND(cmd)
1007         if ret != 0:
1008             print('Command %s failed with exit status %d' % (cmd, ret))
1009             sys.exit(ret)
1010
1011
1012 def distonly(ctx):
1013     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
1014
1015     distfile = file('.distversion', 'w')
1016     for field in version.vcs_fields:
1017         distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
1018     distfile.close()
1019     samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
1020
1021     t = 'ctdb.spec'
1022     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
1023     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
1024     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
1025         sed_expr1, sed_expr2, t)
1026     ret = samba_utils.RUN_COMMAND(cmd)
1027     if ret != 0:
1028         print('Command "%s" failed with exit status %d' % (cmd, ret))
1029         sys.exit(ret)
1030     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
1031
1032     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1033     for t in manpages:
1034         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1035         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1036                               extend=True)
1037
1038     samba_dist.dist()
1039
1040
1041 def dist():
1042     import Scripting
1043     Scripting.commands.append('manpages')
1044     Scripting.commands.append('distonly')
1045
1046
1047 def rpmonly(ctx):
1048     opts = os.getenv('RPM_OPTIONS') or ''
1049     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
1050     ret = samba_utils.RUN_COMMAND(cmd)
1051     if ret != 0:
1052         print('rpmbuild exited with exit status %d' % ret)
1053         sys.exit(ret)
1054
1055
1056 def rpm(ctx):
1057     import Scripting
1058     Scripting.commands.append('manpages')
1059     Scripting.commands.append('distonly')
1060     Scripting.commands.append('rpmonly')
1061
1062
1063 def ctags(ctx):
1064     "build 'tags' file using ctags"
1065     import Utils
1066     source_root = os.path.dirname(Utils.g_module.root_path)
1067     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1068     print("Running: %s" % cmd)
1069     ret = samba_utils.RUN_COMMAND(cmd)
1070     if ret != 0:
1071         print('ctags failed with exit status %d' % ret)
1072         sys.exit(ret)