build: Move socket_wrapper to third_party
[bbaumbach/samba-autobuild/.git] / ctdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'ctdb'
4
5 blddir = 'bin'
6
7 import sys, os
8
9 # find the buildtools directory
10 srcdir = '.'
11 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
12     srcdir = srcdir + '/..'
13 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
14
15 import wafsamba, samba_dist, Options, Logs, Utils
16 import samba_utils, samba_version
17
18 env = samba_utils.LOAD_ENVIRONMENT()
19 if os.path.isfile('./VERSION'):
20     vdir = '.'
21 elif os.path.isfile('../VERSION'):
22     vdir = '..'
23 else:
24     Logs.error("VERSION file not found")
25
26 version = samba_version.samba_version_file('%s/VERSION' % vdir, vdir, env)
27 VERSION = version.STRING.replace('-', '.')
28
29 default_prefix = Options.default_prefix = '/usr/local'
30
31 samba_dist.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
32                         lib/tevent:lib/tevent lib/tdb:lib/tdb
33                         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             have_pmda = True
179         else:
180             Logs.error("PMDA support not available")
181             sys.exit(1)
182     if have_pmda:
183         Logs.info('Building with PMDA support')
184         conf.define('HAVE_PMDA', 1)
185         conf.env.CTDB_PMDADIR = os.path.join(conf.env.LOCALSTATEDIR,
186                                              'lib/pcp/pmdas/ctdb')
187
188     have_infiniband = False
189     if Options.options.ctdb_infiniband:
190         ib_support = True
191
192         if not conf.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
193             ib_support = False
194         if not conf.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
195             ib_support = False
196         if not conf.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
197             ib_support = False
198         if ib_support:
199             have_infiniband = True
200         else:
201             Logs.error("Infiniband support not available")
202             sys.exit(1)
203     if have_infiniband:
204         Logs.info('Building with Infiniband support')
205         conf.define('HAVE_INFINIBAND', 1)
206         conf.define('USE_INFINIBAND', 1)
207
208     have_etcd_reclock = False
209     if Options.options.ctdb_etcd_reclock:
210         try:
211             conf.check_python_module('etcd')
212             have_etcd_reclock = True
213         except:
214             Logs.error('etcd support not available')
215             sys.exit(1)
216     if have_etcd_reclock:
217         Logs.info('Building with etcd support')
218     conf.env.etcd_reclock = have_etcd_reclock
219
220     if Options.options.ctdb_ceph_reclock:
221         if (conf.CHECK_HEADERS('rados/librados.h', False, False, 'rados') and
222                                         conf.CHECK_LIB('rados', shlib=True)):
223             Logs.info('Building with Ceph librados recovery lock support')
224             conf.define('HAVE_LIBRADOS', 1)
225         else:
226             Logs.error("Missing librados for Ceph recovery lock support")
227             sys.exit(1)
228
229     conf.env.CTDB_BINDIR = os.path.join(conf.env.EXEC_PREFIX, 'bin')
230     conf.env.CTDB_ETCDIR = os.path.join(conf.env.SYSCONFDIR, 'ctdb')
231     conf.env.CTDB_VARDIR = os.path.join(conf.env.LOCALSTATEDIR, 'lib/ctdb')
232     conf.env.CTDB_RUNDIR = os.path.join(conf.env.LOCALSTATEDIR, 'run/ctdb')
233     conf.env.CTDB_HELPER_BINDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb')
234
235     if Options.options.ctdb_logdir:
236         conf.env.CTDB_LOGDIR = Options.options.ctdb_logdir
237     else:
238         conf.env.CTDB_LOGDIR = os.path.join(conf.env.LOCALSTATEDIR, 'log')
239
240     if Options.options.ctdb_sockpath:
241         conf.env.CTDB_SOCKPATH = Options.options.ctdb_sockpath
242     else:
243         conf.env.CTDB_SOCKPATH = os.path.join(conf.env.CTDB_RUNDIR,
244                                               'ctdbd.socket')
245     conf.define('CTDB_SOCKET', conf.env.CTDB_SOCKPATH)
246
247     conf.ADD_CFLAGS('''-DCTDB_HELPER_BINDIR=\"%s\"
248                        -DLOGDIR=\"%s\"
249                        -DCTDB_ETCDIR=\"%s\"
250                        -DCTDB_VARDIR=\"%s\"
251                        -DCTDB_RUNDIR=\"%s\"''' % (
252                     conf.env.CTDB_HELPER_BINDIR,
253                     conf.env.CTDB_LOGDIR,
254                     conf.env.CTDB_ETCDIR,
255                     conf.env.CTDB_VARDIR,
256                     conf.env.CTDB_RUNDIR))
257
258     conf.env.CTDB_TEST_DATADIR = os.path.join(conf.env.EXEC_PREFIX,
259                                               'share/ctdb/tests')
260     conf.env.CTDB_TEST_LIBEXECDIR = os.path.join(conf.env.LIBEXECDIR, 'ctdb/tests')
261
262     # Allow unified compilation and separate compilation of utilities
263     # to find includes
264     if not conf.env.standalone_ctdb:
265         conf.ADD_EXTRA_INCLUDES('#include/public #ctdb/include #ctdb')
266     else:
267         if srcdir == '.':
268             # Building from tarball
269             conf.ADD_EXTRA_INCLUDES('#include')
270         else:
271             # Building standalone CTDB from within Samba tree
272             conf.ADD_EXTRA_INCLUDES('#ctdb/include')
273             conf.ADD_EXTRA_INCLUDES('#ctdb')
274         conf.ADD_EXTRA_INCLUDES('#lib #lib/replace')
275
276         conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
277         conf.DEFINE('SAMBA_UTIL_CORE_ONLY', 1, add_to_cflags=True)
278         conf.SAMBA_CONFIG_H()
279
280     if 'XSLTPROC_MANPAGES' in conf.env and conf.env['XSLTPROC_MANPAGES']:
281         conf.env.ctdb_generate_manpages = True
282     else:
283         conf.env.ctdb_generate_manpages = False
284
285         Logs.info("xsltproc unavailable, checking for pre-built manpages")
286         conf.env.ctdb_prebuilt_manpages = []
287         manpages = manpages_binary + manpages_misc
288         if conf.env.etcd_reclock:
289             manpages += manpages_etcd
290         if conf.env.HAVE_LIBRADOS:
291             manpages += manpages_ceph
292         for m in manpages:
293             if os.path.exists(os.path.join("doc", m)):
294                 Logs.info("  %s: yes" % (m))
295                 conf.env.ctdb_prebuilt_manpages.append(m)
296             else:
297                 Logs.info("  %s: no" % (m))
298
299 def gen_ctdb_version(task):
300     fp = file(task.outputs[0].bldpath(task.env), 'w')
301     fp.write('/* This file is auto-generated from waf */\n')
302     fp.write('#include "version.h"\n')
303     fp.write('\n')
304     fp.write('#define CTDB_VERSION_STRING "%s"\n' % VERSION)
305     fp.close()
306
307
308 def build(bld):
309     if bld.env.standalone_ctdb:
310         # enable building of public headers in the build tree
311         bld.env.build_public_headers = 'include/public'
312
313     if bld.env.standalone_ctdb:
314         bld.SAMBA_MKVERSION('version.h', '%s/VERSION' % vdir)
315
316     t = bld.SAMBA_GENERATOR('ctdb-version-header',
317                             target='include/ctdb_version.h',
318                             rule=gen_ctdb_version,
319                             dep_vars=['VERSION'])
320     t.env.VERSION = VERSION
321
322     bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
323
324     bld.RECURSE('lib/replace')
325     if bld.CHECK_FOR_THIRD_PARTY():
326         bld.RECURSE('third_party/popt')
327         if bld.env.standalone_ctdb or bld.CONFIG_GET('SOCKET_WRAPPER'):
328             bld.RECURSE('third_party/socket_wrapper')
329
330     bld.RECURSE('lib/tdb_wrap')
331     bld.RECURSE('lib/util')
332     bld.RECURSE('lib/async_req')
333
334     bld.RECURSE('lib/talloc')
335     bld.RECURSE('lib/tevent')
336     bld.RECURSE('lib/tdb')
337
338     if bld.env.standalone_ctdb:
339         # If a combined build is implemented, CTDB will want to
340         # build against samba-util rather than samba-util-core.
341         # Similarly, other Samba subsystems expect samba-util.  So,
342         # for a standalone build, just define a fake samba-util
343         # subsystem that pulls in samba-util-core.
344         bld.SAMBA_SUBSYSTEM('samba-util',
345                             source='',
346                             deps='samba-util-core')
347
348     bld.SAMBA_SUBSYSTEM('ctdb-tcp',
349                         source=bld.SUBDIR('tcp',
350                                           'tcp_connect.c tcp_init.c tcp_io.c'),
351                         includes='include',
352                         deps='replace tdb talloc tevent')
353
354     ib_deps = ''
355     if bld.env.HAVE_INFINIBAND:
356         bld.SAMBA_SUBSYSTEM('ctdb-ib',
357                             source=bld.SUBDIR('ib',
358                                               '''ibwrapper.c ibw_ctdb.c
359                                                  ibw_ctdb_init.c'''),
360                             includes='include',
361                             deps='replace talloc tevent tdb')
362         ib_deps = ' ctdb-ib rdmacm ibverbs'
363
364     if sys.platform.startswith('linux'):
365         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_linux.c')
366     elif sys.platform.startswith('aix'):
367         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_aix.c')
368     elif sys.platform.startswith('freebsd'):
369         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_freebsd.c')
370     elif sys.platform.startswith('gnukfreebsd'):
371         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_kfreebsd.c')
372     elif sys.platform == 'gnu':
373         CTDB_SYSTEM_SRC = bld.SUBDIR('common', 'system_gnu.c')
374     else:
375         Logs.error("Platform %s not supported" % sys.platform)
376
377     bld.SAMBA_SUBSYSTEM('ctdb-system',
378                         source=bld.SUBDIR('common',
379                                           'system_common.c system_util.c') +
380                                CTDB_SYSTEM_SRC,
381                         includes='include',
382                         deps='replace talloc tevent tdb pcap samba-util')
383
384     bld.SAMBA_SUBSYSTEM('ctdb-common',
385                         source=bld.SUBDIR('common',
386                                           '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
387                                              sock_io.c'''),
388                         includes='include',
389                         deps='''replace popt talloc tevent tdb popt ctdb-system
390                                 ctdb-protocol-util''')
391
392     bld.SAMBA_SUBSYSTEM('ctdb-util',
393                         source=bld.SUBDIR('common',
394                                           '''db_hash.c srvid.c reqid.c
395                                              pkt_read.c pkt_write.c comm.c
396                                              logging.c rb_tree.c tunable.c
397                                              pidfile.c run_proc.c
398                                              hash_count.c run_event.c
399                                              sock_client.c version.c'''),
400                         deps='''samba-util sys_rw tevent-util
401                                 replace talloc tevent tdb''')
402
403     bld.SAMBA_SUBSYSTEM('ctdb-protocol',
404                         source=bld.SUBDIR('protocol',
405                                           '''protocol_header.c protocol_packet.c
406                                              protocol_basic.c protocol_types.c
407                                              protocol_call.c
408                                              protocol_message.c
409                                              protocol_control.c
410                                              protocol_keepalive.c
411                                              protocol_tunnel.c
412                                              protocol_client.c
413                                              protocol_debug.c
414                                              protocol_event.c
415                                              protocol_sock.c'''),
416                         includes='include',
417                         deps='replace talloc tdb')
418
419     bld.SAMBA_SUBSYSTEM('ctdb-protocol-util',
420                         source='protocol/protocol_util.c',
421                         deps='replace talloc tdb')
422
423     bld.SAMBA_SUBSYSTEM('ctdb-client',
424                         source=bld.SUBDIR('client', 'ctdb_client.c'),
425                         includes='include',
426                         deps='''replace popt talloc tevent tdb
427                                 samba-util tdb-wrap ctdb-util''')
428
429     bld.SAMBA_SUBSYSTEM('ctdb-client2',
430                         source=bld.SUBDIR('client',
431                                           '''client_connect.c client_call.c
432                                              client_message.c client_control.c
433                                              client_message_sync.c
434                                              client_control_sync.c
435                                              client_db.c client_util.c
436                                              client_event.c client_tunnel.c
437                                           '''),
438                         includes='include',
439                         deps='replace talloc tevent tdb tdb-wrap')
440
441     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
442                         source=bld.SUBDIR('common',
443                                           '''sock_daemon.c'''),
444                         deps='''samba-util ctdb-util tevent-util
445                                 replace talloc tevent''')
446
447     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
448                         source=bld.SUBDIR('server',
449                                           '''ipalloc_deterministic.c
450                                              ipalloc_nondeterministic.c
451                                              ipalloc_lcp2.c
452                                              ipalloc_common.c
453                                              ipalloc.c
454                                           '''),
455                         includes='include',
456                         deps='ctdb-protocol-util replace talloc tevent')
457
458     bld.SAMBA_BINARY('ctdbd',
459                      source='server/ctdbd.c ' +
460                                bld.SUBDIR('server',
461                                           '''ctdb_daemon.c ctdb_recoverd.c
462                                              ctdb_recover.c ctdb_freeze.c
463                                              ctdb_tunables.c ctdb_monitor.c
464                                              ctdb_server.c ctdb_control.c
465                                              ctdb_call.c ctdb_ltdb_server.c
466                                              ctdb_traverse.c eventscript.c
467                                              ctdb_takeover.c
468                                              ctdb_persistent.c ctdb_keepalive.c
469                                              ctdb_cluster_mutex.c
470                                              ctdb_logging.c
471                                              ctdb_uptime.c
472                                              ctdb_vacuum.c ctdb_banning.c
473                                              ctdb_statistics.c
474                                              ctdb_update_record.c
475                                              ctdb_lock.c ctdb_fork.c
476                                              ctdb_tunnel.c'''),
477                      includes='include',
478                      deps='''ctdb-client ctdb-common ctdb-system ctdb-protocol
479                              ctdb-tcp ctdb-util replace sys_rw popt
480                              talloc tevent tdb talloc_report''' +
481                           ib_deps,
482                      install_path='${SBINDIR}',
483                      manpages='ctdbd.1')
484
485     bld.SAMBA_BINARY('ctdb',
486                      source='tools/ctdb.c',
487                      deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
488                              ctdb-util ctdb-system samba-util sys_rw popt''',
489                      install_path='${BINDIR}',
490                      manpages='ctdb.1')
491
492     bld.SAMBA_BINARY('ctdb_killtcp',
493                      source='tools/ctdb_killtcp.c',
494                      deps='''ctdb-protocol-util ctdb-util ctdb-system
495                              samba-util replace''',
496                      install_path='${CTDB_HELPER_BINDIR}')
497
498     bld.SAMBA_BINARY('ctdb_event',
499                      source='tools/ctdb_event.c',
500                      deps='''ctdb-client2 ctdb-protocol ctdb-protocol-util
501                              ctdb-util ctdb-system samba-util replace''',
502                      install_path='${CTDB_HELPER_BINDIR}')
503
504     bld.SAMBA_BINARY('ltdbtool',
505                      source='tools/ltdbtool.c',
506                      includes='include',
507                      deps='tdb',
508                      install_path='${BINDIR}',
509                      manpages='ltdbtool.1')
510
511     bld.SAMBA_BINARY('ctdb_eventd',
512                      source='server/ctdb_eventd.c',
513                      deps='''ctdb-server-util ctdb-protocol ctdb-protocol-util
514                              ctdb-util samba-util LIBASYNC_REQ replace popt''',
515                      install_path='${CTDB_HELPER_BINDIR}')
516
517     bld.SAMBA_BINARY('ctdb_lock_helper',
518                      source='server/ctdb_lock_helper.c',
519                      deps='''samba-util sys_rw ctdb-system tevent-util
520                              talloc tevent tdb''',
521                      includes='include',
522                      install_path='${CTDB_HELPER_BINDIR}')
523
524     bld.SAMBA_BINARY('ctdb_recovery_helper',
525                      source='server/ctdb_recovery_helper.c',
526                      deps='''ctdb-client2 ctdb-protocol ctdb-util
527                              samba-util sys_rw replace tdb''',
528                      install_path='${CTDB_HELPER_BINDIR}')
529
530     bld.SAMBA_BINARY('ctdb_takeover_helper',
531                      source='server/ctdb_takeover_helper.c',
532                      deps='''ctdb-client2 ctdb-protocol ctdb-util
533                              samba-util sys_rw replace ctdb-ipalloc popt''',
534                      install_path='${CTDB_HELPER_BINDIR}')
535
536     bld.SAMBA_BINARY('ctdb_mutex_fcntl_helper',
537                      source='server/ctdb_mutex_fcntl_helper.c',
538                      deps='sys_rw ctdb-system',
539                      includes='include',
540                      install_path='${CTDB_HELPER_BINDIR}')
541
542     bld.SAMBA_GENERATOR('ctdb-smnotify-h',
543                         source='utils/smnotify/smnotify.x',
544                         target='utils/smnotify/smnotify.h',
545                         rule='rpcgen -h ${SRC} > ${TGT}')
546
547     xdr_buf_hack = 'sed -e "s@^\([ \t]*register int32_t \*buf\);@\\1 = buf;@"'
548
549     bld.SAMBA_GENERATOR('ctdb-smnotify-x',
550                         source='utils/smnotify/smnotify.x',
551                         target='utils/smnotify/gen_xdr.c',
552                         rule='rpcgen -c ${SRC} | ' + xdr_buf_hack + ' > ${TGT}')
553
554     bld.SAMBA_GENERATOR('ctdb-smnotify-c',
555                         source='utils/smnotify/smnotify.x',
556                         target='utils/smnotify/gen_smnotify.c',
557                         rule='rpcgen -l ${SRC} > ${TGT}')
558
559     bld.SAMBA_BINARY('smnotify',
560                      source=bld.SUBDIR('utils/smnotify',
561                                        'smnotify.c gen_smnotify.c gen_xdr.c'),
562                      deps='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
563                      includes='utils utils/smnotify',
564                      install_path='${CTDB_HELPER_BINDIR}')
565
566     bld.SAMBA_BINARY('ping_pong',
567                      source='utils/ping_pong/ping_pong.c',
568                      deps='',
569                      install_path='${BINDIR}',
570                      manpages='ping_pong.1')
571
572     if bld.env.HAVE_PMDA:
573         bld.SAMBA_BINARY('pmdactdb',
574                          source='utils/pmda/pmda_ctdb.c',
575                          includes='include',
576                          deps='''ctdb-client2 ctdb-protocol ctdb-util
577                                  samba-util pcp_pmda pcp''',
578                          install_path='${CTDB_PMDADIR}')
579         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
580                           destname='Install')
581         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
582                           destname='Remove')
583         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
584                           destname='pmns')
585         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
586                           destname='domain.h')
587         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
588                           destname='help')
589         bld.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
590                           destname='README')
591
592     if bld.env.HAVE_LIBRADOS:
593         bld.SAMBA_BINARY('ctdb_mutex_ceph_rados_helper',
594                          source='utils/ceph/ctdb_mutex_ceph_rados_helper.c',
595                          deps='talloc tevent rados',
596                          includes='include',
597                          install_path='${CTDB_HELPER_BINDIR}')
598
599     sed_expr1 = 's|/usr/local/var/lib/ctdb|%s|g'  % (bld.env.CTDB_VARDIR)
600     sed_expr2 = 's|/usr/local/etc/ctdb|%s|g'      % (bld.env.CTDB_ETCDIR)
601     sed_expr3 = 's|/usr/local/var/log|%s|g'       % (bld.env.CTDB_LOGDIR)
602     sed_expr4 = 's|/usr/local/var/run/ctdb|%s|g'  % (bld.env.CTDB_RUNDIR)
603     sed_expr5 = 's|/usr/local/sbin|%s|g'          % (bld.env.SBINDIR)
604     sed_expr6 = 's|/usr/local/libexec/ctdb|%s|g'  % (bld.env.CTDB_HELPER_BINDIR)
605     sed_expr7 = 's|/usr/local/bin|%s|g'           % (bld.env.BINDIR)
606     sed_cmdline = '-e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s" -e "%s"' % \
607                        (sed_expr1, sed_expr2, sed_expr3, sed_expr4, sed_expr5,
608                         sed_expr6, sed_expr7)
609
610     manpages_extra = manpages_misc
611     if bld.env.etcd_reclock:
612         manpages_extra += manpages_etcd
613     if bld.env.HAVE_LIBRADOS:
614         manpages_extra += manpages_ceph
615     for f in manpages_binary + manpages_extra:
616         x = '%s.xml' % (f)
617         bld.SAMBA_GENERATOR(x,
618                             source=os.path.join('doc', x),
619                             target=x,
620                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
621
622     if bld.env.ctdb_generate_manpages:
623         bld.MANPAGES(' '.join(manpages_extra), True)
624     else:
625         for m in bld.env.ctdb_prebuilt_manpages:
626             bld.SAMBA_GENERATOR(m,
627                                 source=os.path.join("doc", m),
628                                 target=m,
629                                 rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
630             bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m)
631
632     bld.SAMBA_GENERATOR('ctdb-onnode',
633                         source='tools/onnode',
634                         target='onnode',
635                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
636     bld.INSTALL_FILES('${BINDIR}', 'onnode',
637                       destname='onnode', chmod=0755)
638
639     bld.SAMBA_GENERATOR('ctdb-diagnostics',
640                         source='tools/ctdb_diagnostics',
641                         target='ctdb_diagnostics',
642                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
643     bld.INSTALL_FILES('${BINDIR}', 'ctdb_diagnostics',
644                       destname='ctdb_diagnostics', chmod=0755)
645
646     if bld.env.etcd_reclock:
647         bld.SAMBA_GENERATOR('ctdb-etcd-lock',
648                             source='utils/etcd/ctdb_etcd_lock',
649                             target='ctdb_etcd_lock',
650                             rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
651         bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_etcd_lock',
652                           destname='ctdb_etcd_lock', chmod=0744)
653
654     bld.SAMBA_GENERATOR('ctdb-natgw',
655                         source='tools/ctdb_natgw',
656                         target='ctdb_natgw',
657                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
658     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_natgw',
659                       destname='ctdb_natgw', chmod=0755)
660
661     bld.SAMBA_GENERATOR('ctdb-lvs',
662                         source='tools/ctdb_lvs',
663                         target='ctdb_lvs',
664                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
665     bld.INSTALL_FILES('${CTDB_HELPER_BINDIR}', 'ctdb_lvs',
666                       destname='ctdb_lvs', chmod=0755)
667
668     bld.SAMBA_GENERATOR('ctdbd-wrapper',
669                         source='config/ctdbd_wrapper',
670                         target='ctdbd_wrapper',
671                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
672     bld.INSTALL_FILES('${SBINDIR}', 'ctdbd_wrapper',
673                       destname='ctdbd_wrapper', chmod=0755)
674
675     def SUBDIR_MODE_callback(arg, dirname, fnames):
676         for f in fnames:
677             fl = os.path.join(dirname, f)
678             if os.path.isdir(fl) or os.path.islink(fl):
679                 continue
680             mode = os.lstat(fl).st_mode & 0777
681             if arg['trim_path']:
682                 fl = samba_utils.os_path_relpath(fl, arg['trim_path'])
683             arg['file_list'].append([fl, mode])
684
685     def SUBDIR_MODE(path, trim_path=None):
686         pd = {'trim_path': trim_path, 'file_list': []}
687         os.path.walk(path, SUBDIR_MODE_callback, pd)
688         return pd['file_list']
689
690     etc_subdirs = [
691         'events.d',
692         'nfs-checks.d'
693     ]
694
695     if bld.env.standalone_ctdb:
696         configdir = 'config'
697     else:
698         configdir = 'ctdb/config'
699
700     for t in etc_subdirs:
701         files = SUBDIR_MODE('%s/%s' % (configdir, t), trim_path=configdir)
702         for fmode in files:
703             bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'config/%s' % fmode[0],
704                               destname=fmode[0], chmod=fmode[1])
705
706     bld.SAMBA_GENERATOR('ctdb-functions',
707                         source='config/functions',
708                         target='functions',
709                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
710     bld.INSTALL_FILES(bld.env.CTDB_ETCDIR, 'functions', destname='functions')
711
712     etc_scripts = [
713         'ctdb-crash-cleanup.sh',
714         'debug-hung-script.sh',
715         'debug_locks.sh',
716         'gcore_trace.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         'events.d',
884         'eventscripts',
885         'onnode',
886         'shellcheck',
887         'simple',
888         'takeover',
889         'takeover_helper',
890         'tool'
891     ]
892
893     if bld.env.standalone_ctdb:
894         testdir = 'tests'
895     else:
896         testdir = 'ctdb/tests'
897
898     for t in test_subdirs:
899         files = SUBDIR_MODE('%s/%s' % (testdir, t), trim_path=testdir)
900         for fmode in files:
901             bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR, 'tests/%s' % fmode[0],
902                               destname=fmode[0], chmod=fmode[1])
903
904     # Install tests/scripts directory without test_wrap
905     test_scripts = [
906         'common.sh',
907         'integration.bash',
908         'unit.sh'
909     ]
910
911     for t in test_scripts:
912         bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR,
913                           os.path.join('tests/scripts', t),
914                           destname=os.path.join('scripts', t))
915
916     sed_expr = 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
917                bld.env.CTDB_TEST_LIBEXECDIR)
918     bld.SAMBA_GENERATOR('ctdb-test-wrap',
919                         source='tests/scripts/test_wrap',
920                         target='test_wrap',
921                         rule='sed -e "%s" ${SRC} > ${TGT}' % sed_expr)
922     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts", 'test_wrap',
923                       destname='test_wrap', chmod=0755)
924
925     bld.SAMBA_GENERATOR('ctdb-test-script-install-paths',
926                         source='tests/scripts/script_install_paths.sh',
927                         target='script_install_paths.sh',
928                         rule='sed %s ${SRC} > ${TGT}' % (sed_cmdline))
929     bld.INSTALL_FILES(bld.env.CTDB_TEST_DATADIR+"/scripts",
930                       'script_install_paths.sh',
931                       destname='script_install_paths.sh', chmod=0644)
932
933     sed_expr1 = 's@^\(export %s\)=.*@\\1=%s\\nexport %s=\"%s\"@''' % (
934                     'CTDB_TEST_DIR', bld.env.CTDB_TEST_DATADIR,
935                     'TEST_BIN_DIR', bld.env.CTDB_TEST_LIBEXECDIR)
936     sed_expr2 = 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
937     bld.SAMBA_GENERATOR('ctdb-test-runner',
938                         source='tests/run_tests.sh',
939                         target='ctdb_run_tests.sh',
940                         rule='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
941                              sed_expr1, sed_expr2))
942     bld.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
943                       destname='ctdb_run_tests', chmod=0755)
944     bld.symlink_as(os.path.join(bld.env.BINDIR, 'ctdb_run_cluster_tests'),
945                    'ctdb_run_tests')
946
947     test_eventscript_links = [
948         'events.d',
949         'functions',
950         'nfs-checks.d',
951         'nfs-linux-kernel-callout',
952         'statd-callout'
953     ]
954
955     test_link_dir = os.path.join(bld.env.CTDB_TEST_DATADIR,
956                                  'eventscripts/etc-ctdb')
957     for t in test_eventscript_links:
958         bld.symlink_as(os.path.join(test_link_dir, t),
959                        os.path.join(bld.env.CTDB_ETCDIR, t))
960
961     # Tests that use onnode need to overwrite link to in-tree
962     # functions file when installed
963     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'onnode/functions'),
964                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
965     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/functions'),
966                    os.path.join(bld.env.CTDB_ETCDIR, 'functions'))
967
968     # Need a link to nodes file because $CTDB_BASE is overridden
969     bld.symlink_as(os.path.join(bld.env.CTDB_TEST_DATADIR, 'simple/nodes'),
970                    os.path.join(bld.env.CTDB_ETCDIR, 'nodes'))
971
972
973 def testonly(ctx):
974     cmd = 'tests/run_tests.sh -V tests/var'
975     ret = samba_utils.RUN_COMMAND(cmd)
976     if ret != 0:
977         print('tests exited with exit status %d' % ret)
978         sys.exit(ret)
979
980
981 def test(ctx):
982     import Scripting
983     Scripting.commands.append('build')
984     Scripting.commands.append('testonly')
985
986
987 def autotest(ctx):
988     env = samba_utils.LOAD_ENVIRONMENT()
989     ld = 'LD_PRELOAD=%s' % env.SOCKET_WRAPPER_SO_PATH
990     cmd = '%s tests/run_tests.sh -e -S -C' % ld
991     ret = samba_utils.RUN_COMMAND(cmd)
992     if ret != 0:
993         print('autotest exited with exit status %d' % ret)
994         sys.exit(ret)
995
996
997 def show_version(ctx):
998     print VERSION
999
1000
1001 def manpages(ctx):
1002     BASE_URL = 'http://docbook.sourceforge.net/release/xsl/current'
1003     MAN_XSL = '%s/manpages/docbook.xsl' % BASE_URL
1004     HTML_XSL = '%s/html/docbook.xsl' % BASE_URL
1005     CMD_TEMPLATE = 'xsltproc --xinclude -o %s --nonet %s %s'
1006     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1007     for t in manpages:
1008         cmd = CMD_TEMPLATE % ('doc/%s' % t, MAN_XSL, 'doc/%s.xml' % t)
1009         ret = samba_utils.RUN_COMMAND(cmd)
1010         if ret != 0:
1011             print('Command %s failed with exit status %d' % (cmd, ret))
1012             sys.exit(ret)
1013
1014         cmd = CMD_TEMPLATE % ('doc/%s.html' % t, HTML_XSL, 'doc/%s.xml' % t)
1015         ret = samba_utils.RUN_COMMAND(cmd)
1016         if ret != 0:
1017             print('Command %s failed with exit status %d' % (cmd, ret))
1018             sys.exit(ret)
1019
1020
1021 def distonly(ctx):
1022     samba_dist.DIST_FILES('VERSION:VERSION', extend=True)
1023
1024     distfile = file('.distversion', 'w')
1025     for field in version.vcs_fields:
1026         distfile.write('%s=%s\n' % (field, str(version.vcs_fields[field])))
1027     distfile.close()
1028     samba_dist.DIST_FILES('ctdb/.distversion:.distversion', extend=True)
1029
1030     t = 'ctdb.spec'
1031     sed_expr1 = 's/@VERSION@/%s/g' % VERSION
1032     sed_expr2 = 's/@RELEASE@/%s/g' % '1'
1033     cmd = 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
1034         sed_expr1, sed_expr2, t)
1035     ret = samba_utils.RUN_COMMAND(cmd)
1036     if ret != 0:
1037         print('Command "%s" failed with exit status %d' % (cmd, ret))
1038         sys.exit(ret)
1039     samba_dist.DIST_FILES('ctdb/%s:%s' % (t, t), extend=True)
1040
1041     manpages = manpages_binary + manpages_misc + manpages_etcd + manpages_ceph
1042     for t in manpages:
1043         samba_dist.DIST_FILES('ctdb/doc/%s:doc/%s' % (t, t), extend=True)
1044         samba_dist.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t, t),
1045                               extend=True)
1046
1047     samba_dist.dist()
1048
1049
1050 def dist():
1051     import Scripting
1052     Scripting.commands.append('manpages')
1053     Scripting.commands.append('distonly')
1054
1055
1056 def rpmonly(ctx):
1057     opts = os.getenv('RPM_OPTIONS') or ''
1058     cmd = 'rpmbuild -ta --clean --rmsource %s ctdb-%s.tar.gz' % (opts, VERSION)
1059     ret = samba_utils.RUN_COMMAND(cmd)
1060     if ret != 0:
1061         print('rpmbuild exited with exit status %d' % ret)
1062         sys.exit(ret)
1063
1064
1065 def rpm(ctx):
1066     import Scripting
1067     Scripting.commands.append('manpages')
1068     Scripting.commands.append('distonly')
1069     Scripting.commands.append('rpmonly')
1070
1071
1072 def ctags(ctx):
1073     "build 'tags' file using ctags"
1074     import Utils
1075     source_root = os.path.dirname(Utils.g_module.root_path)
1076     cmd = 'ctags $(find %s -name "*.[ch]")' % source_root
1077     print("Running: %s" % cmd)
1078     ret = samba_utils.RUN_COMMAND(cmd)
1079     if ret != 0:
1080         print('ctags failed with exit status %d' % ret)
1081         sys.exit(ret)