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