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