9 # find the buildtools directory
11 while not os
.path
.exists(srcdir
+'/buildtools') and len(srcdir
.split('/')) < 5:
12 srcdir
= srcdir
+ '/..'
13 sys
.path
.insert(0, srcdir
+ '/buildtools/wafsamba')
15 import wafsamba
, samba_dist
, Options
, Logs
16 import samba_utils
, samba_version
18 env
= samba_utils
.LOAD_ENVIRONMENT()
19 if os
.path
.isfile('./VERSION'):
21 elif os
.path
.isfile('../VERSION'):
24 Logs
.error("VERSION file not found")
26 version
= samba_version
.samba_version_file('%s/VERSION' % vdir
, vdir
, env
)
27 VERSION
= version
.STRING
.replace('-', '.')
29 Options
.default_prefix
= '/usr/local'
31 samba_dist
.DIST_DIRS('''ctdb:. lib/replace:lib/replace lib/talloc:lib/talloc
32 lib/tevent:lib/tevent lib/tdb:lib/tdb lib/popt:lib/popt
33 lib/socket_wrapper:lib/socket_wrapper
34 buildtools:buildtools''')
37 opt
.PRIVATE_EXTENSION_DEFAULT('ctdb')
38 opt
.RECURSE('lib/replace')
39 opt
.RECURSE('lib/talloc')
40 opt
.RECURSE('lib/tevent')
41 opt
.RECURSE('lib/tdb')
43 opt
.add_option('--enable-infiniband',
44 help=("Turn on infiniband support (default=no)"),
45 action
="store_true", dest
='ctdb_infiniband', default
=False)
46 opt
.add_option('--enable-pmda',
47 help=("Turn on PCP pmda support (default=no)"),
48 action
="store_true", dest
='ctdb_pmda', default
=False)
50 opt
.add_option('--with-logdir',
51 help=("Path to log directory"),
52 action
="store", dest
='ctdb_logdir', default
=None)
53 opt
.add_option('--with-socketpath',
54 help=("path to CTDB daemon socket"),
55 action
="store_true", dest
='ctdb_sockpath', default
=False)
59 # CTDB relies on nested event loops
60 conf
.env
.TEVENT_DEPRECATED
= 1
62 # No need to build python bindings for talloc/tevent/tdb
63 if conf
.IN_LAUNCH_DIR():
64 Options
.options
.disable_python
= True
66 conf
.RECURSE('lib/replace')
67 conf
.RECURSE('lib/popt')
68 conf
.RECURSE('lib/talloc')
69 conf
.RECURSE('lib/tevent')
70 conf
.RECURSE('lib/tdb')
71 conf
.RECURSE('lib/socket_wrapper')
74 if Options
.options
.ctdb_pmda
:
77 if not conf
.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
80 if not conf
.CHECK_FUNCS_IN('pmProgname', 'pcp'):
82 if not conf
.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
87 Logs
.error("PMDA support not available")
89 Logs
.info('Building with PMDA support')
90 conf
.define('HAVE_PMDA', 1)
91 conf
.env
.CTDB_PMDADIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
,
94 have_infiniband
= False
95 if Options
.options
.ctdb_infiniband
:
98 if not conf
.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
100 if not conf
.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
102 if not conf
.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
105 have_infiniband
= True
107 Logs
.error("Infiniband support not available")
109 Logs
.info('Building with Infiniband support')
110 conf
.define('HAVE_INFINIBAND', 1)
111 conf
.define('USE_INFINIBAND', 1)
113 conf
.env
.CTDB_BINDIR
= os
.path
.join(conf
.env
.EXEC_PREFIX
, 'bin')
114 conf
.env
.CTDB_ETCDIR
= os
.path
.join(conf
.env
.SYSCONFDIR
, 'ctdb')
115 conf
.env
.CTDB_VARDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'lib/ctdb')
116 conf
.env
.CTDB_RUNDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'run/ctdb')
118 machine
= os
.uname()[4]
119 if machine
in ['x86_64', 'ppc64', 'powerpc64']:
120 conf
.env
.LIBDIR
= conf
.env
.LIBDIR
+ '64'
122 if Options
.options
.ctdb_logdir
:
123 conf
.env
.CTDB_LOGDIR
= Options
.options
.ctdb_logdir
125 conf
.env
.CTDB_LOGDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'log')
127 if Options
.options
.ctdb_sockpath
:
128 conf
.env
.CTDB_SOCKPATH
= Options
.options
.ctdb_sockpath
130 conf
.env
.CTDB_SOCKPATH
= os
.path
.join(conf
.env
.CTDB_RUNDIR
,
133 conf
.ADD_CFLAGS('''-DBINDIR=\"%s\" -DETCDIR=\"%s\" -DVARDIR=\"%s\"
134 -DLOGDIR=\"%s\" -DSOCKPATH=\"%s\"
135 -DCTDB_VARDIR=\"%s\"''' % (
136 conf
.env
.CTDB_BINDIR
,
137 conf
.env
.CTDB_ETCDIR
,
138 conf
.env
.CTDB_VARDIR
,
139 conf
.env
.CTDB_LOGDIR
,
140 conf
.env
.CTDB_SOCKPATH
,
141 conf
.env
.CTDB_VARDIR
))
143 conf
.env
.CTDB_TEST_DATADIR
= os
.path
.join(conf
.env
.EXEC_PREFIX
,
145 conf
.env
.CTDB_TEST_LIBDIR
= os
.path
.join(conf
.env
.LIBDIR
, 'ctdb-tests')
147 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
148 conf
.SAMBA_CONFIG_H()
151 bld
.RECURSE('lib/replace')
152 bld
.RECURSE('lib/popt')
153 bld
.RECURSE('lib/talloc')
154 bld
.RECURSE('lib/tevent')
155 bld
.RECURSE('lib/tdb')
156 bld
.RECURSE('lib/socket_wrapper')
158 bld
.SAMBA_GENERATOR('ctdb-version-header',
159 target
='include/ctdb_version.h',
160 rule
='../packaging/mkversion.sh ${TGT} %s' % (VERSION
),
163 bld
.SAMBA_SUBSYSTEM('ctdb-util',
164 source
=bld
.SUBDIR('lib/util',
165 'util.c util_file.c util_time.c'),
166 includes
='include include/internal',
167 deps
='replace talloc tevent tdb')
169 bld
.SAMBA_SUBSYSTEM('ctdb-util-misc',
170 source
=bld
.SUBDIR('lib/util',
171 '''db_wrap.c debug.c fault.c
172 idtree.c signal.c strlist.c
174 includes
='include include/internal lib/util',
175 deps
='replace talloc tevent tdb')
177 bld
.SAMBA_SUBSYSTEM('ctdb-tcp',
178 source
=bld
.SUBDIR('tcp',
179 'tcp_connect.c tcp_init.c tcp_io.c'),
180 includes
='include include/internal',
181 deps
='replace tdb talloc tevent')
184 if bld
.env
.HAVE_INFINIBAND
:
185 bld
.SAMBA_SUBSYSTEM('ctdb-ib',
186 source
=bld
.SUBDIR('ib',
187 '''ibwrapper.c ibw_ctdb.c
189 includes
='include include/internal',
191 ib_deps
= ' ctdb-ib rdmacm ibverbs'
193 bld
.SAMBA_SUBSYSTEM('ctdb-common',
194 source
=bld
.SUBDIR('common',
195 '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
196 ctdb_message.c cmdline.c rb_tree.c
197 system_common.c ctdb_fork.c'''),
198 includes
='include include/internal common . lib/util',
199 deps
='replace popt talloc tevent tdb')
201 bld
.SAMBA_SUBSYSTEM('ctdb-common-util',
202 source
=bld
.SUBDIR('common',
203 'system_util.c ctdb_logging.c'),
204 includes
='include include/internal',
205 deps
='replace tevent tdb')
207 if sys
.platform
== 'linux2':
208 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_linux.c')
209 elif sys
.platform
== 'aix':
210 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_aix.c')
211 elif sys
.platform
== 'freebsd':
212 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_freebsd.c')
213 elif sys
.platform
== 'kfreebsd':
214 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_kfreebsd.c')
215 elif sys
.platform
== 'gnu':
216 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_gnu.c')
218 Logs
.error("Platform %s not supported" % sys
.platform
)
220 bld
.SAMBA_SUBSYSTEM('ctdb-system',
221 source
=CTDB_SYSTEM_SRC
,
222 includes
='include include/internal',
223 deps
='replace talloc tevent tdb')
225 bld
.SAMBA_SUBSYSTEM('ctdb-client',
226 source
=bld
.SUBDIR('client', 'ctdb_client.c'),
227 includes
='include include/internal lib/util',
228 public_headers
='include/ctdb_client.h',
229 deps
='replace popt talloc tevent tdb')
231 bld
.SAMBA_SUBSYSTEM('ctdb-server',
232 source
='server/ctdbd.c ' +
234 '''ctdb_daemon.c ctdb_recoverd.c
235 ctdb_recover.c ctdb_freeze.c
236 ctdb_tunables.c ctdb_monitor.c
237 ctdb_server.c ctdb_control.c
238 ctdb_call.c ctdb_ltdb_server.c
239 ctdb_traverse.c eventscript.c
240 ctdb_takeover.c ctdb_serverids.c
241 ctdb_persistent.c ctdb_keepalive.c
242 ctdb_logging.c ctdb_uptime.c
243 ctdb_vacuum.c ctdb_banning.c
247 includes
='include include/internal lib/util',
248 public_headers
='''include/ctdb.h
249 include/ctdb_private.h
250 include/ctdb_protocol.h
251 include/ctdb_typesafe_cb.h''',
252 deps
='replace popt talloc tevent tdb')
254 bld
.SAMBA_BINARY('bin/ctdbd',
256 deps
='''ctdb-server ctdb-client ctdb-common
257 ctdb-common-util ctdb-system ctdb-tcp
258 ctdb-util ctdb-util-misc''' +
260 install_path
='${SBINDIR}',
261 manpages
='doc/ctdbd.1')
263 bld
.SAMBA_BINARY('bin/ctdb',
264 source
='tools/ctdb.c tools/ctdb_vacuum.c',
265 deps
='''ctdb-client ctdb-common ctdb-common-util
266 ctdb-system ctdb-util ctdb-util-misc''',
267 install_path
='${BINDIR}',
268 manpages
='doc/ctdb.1')
270 bld
.SAMBA_BINARY('bin/ltdbtool',
271 source
='tools/ltdbtool.c',
274 install_path
='${BINDIR}',
275 manpages
='doc/ltdbtool.1')
277 bld
.SAMBA_BINARY('bin/ctdb_lock_helper',
278 source
='server/ctdb_lock_helper.c',
279 deps
='ctdb-util ctdb-util-misc ctdb-common-util talloc tdb',
280 install_path
='${BINDIR}')
282 bld
.SAMBA_BINARY('bin/ctdb_event_helper',
283 source
='server/ctdb_event_helper.c',
284 includes
='include include/internal',
285 deps
='ctdb-util ctdb-util-misc ctdb-common-util replace tdb',
286 install_path
='${BINDIR}')
288 bld
.SAMBA_GENERATOR('ctdb-smnotify-h',
289 source
='utils/smnotify/smnotify.x',
290 target
='utils/smnotify/smnotify.h',
291 rule
='rpcgen -h ${SRC} > ${TGT}')
293 bld
.SAMBA_GENERATOR('ctdb-smnotify-x',
294 source
='utils/smnotify/smnotify.x',
295 target
='utils/smnotify/gen_xdr.c',
296 rule
='rpcgen -c ${SRC} > ${TGT}')
298 bld
.SAMBA_GENERATOR('ctdb-smnotify-c',
299 source
='utils/smnotify/smnotify.x',
300 target
='utils/smnotify/gen_smnotify.c',
301 rule
='rpcgen -l ${SRC} > ${TGT}')
303 bld
.SAMBA_BINARY('bin/smnotify',
304 source
=bld
.SUBDIR('utils/smnotify',
305 'smnotify.c gen_smnotify.c gen_xdr.c'),
306 deps
='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
307 includes
='utils utils/smnotify',
308 install_path
='${BINDIR}')
310 bld
.SAMBA_BINARY('bin/ping_pong',
311 source
='utils/ping_pong/ping_pong.c',
313 install_path
='${BINDIR}',
314 manpages
='doc/ping_pong.1')
316 if bld
.env
.HAVE_PMDA
:
317 bld
.SAMBA_BINARY('bin/pmdactdb',
318 source
='utils/pmda/pmda_ctdb.c',
319 includes
='include include/internal',
320 deps
='''ctdb-client ctdb-common ctdb-system
321 ctdb-util-misc ctdb-util pcp_pmda pcp''',
322 install_path
='${CTDB_PMDADIR}')
323 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
325 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
327 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
329 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
331 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
333 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
336 bld
.MANPAGES('''doc/onnode.1 doc/ctdbd_wrapper.1 doc/ctdbd.conf.5
337 doc/ctdb.7 doc/ctdb-tunables.7''', True)
339 bld
.INSTALL_FILES('${BINDIR}', 'tools/onnode',
340 destname
='onnode', chmod
=0755)
341 bld
.INSTALL_FILES('${BINDIR}', 'tools/ctdb_diagnostics',
342 destname
='ctdb_diagnostics', chmod
=0755)
343 bld
.INSTALL_FILES('${SBINDIR}', 'config/ctdbd_wrapper',
344 destname
='ctdbd_wrapper', chmod
=0755)
346 def SUBDIR_MODE_callback(arg
, dirname
, fnames
):
348 fl
= os
.path
.join(dirname
, f
)
349 if os
.path
.isdir(fl
) or os
.path
.islink(fl
):
351 mode
= os
.lstat(fl
).st_mode
& 0777
353 fl
= samba_utils
.os_path_relpath(fl
, arg
['trim_path'])
354 arg
['file_list'].append([fl
, mode
])
356 def SUBDIR_MODE(path
, trim_path
=None):
357 pd
= {'trim_path': trim_path
, 'file_list': []}
358 os
.path
.walk(path
, SUBDIR_MODE_callback
, pd
)
359 return pd
['file_list']
366 for t
in etc_subdirs
:
367 files
= SUBDIR_MODE('config/%s' % t
, trim_path
='config')
369 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/%s' % fmode
[0],
370 destname
=fmode
[0], chmod
=fmode
[1])
372 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/functions',
373 destname
='functions')
376 'ctdb-crash-cleanup.sh',
377 'debug-hung-script.sh',
384 for t
in etc_scripts
:
385 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/' + t
,
386 destname
=t
, chmod
=0755)
388 bld
.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'config/ctdb.sudoers',
391 bld
.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
394 bld
.install_dir(bld
.env
.CTDB_LOGDIR
)
395 bld
.install_dir(bld
.env
.CTDB_RUNDIR
)
396 bld
.install_dir(bld
.env
.CTDB_VARDIR
)
398 sed_expr
= 's/@PACKAGE_VERSION@/%s/g' % VERSION
399 bld
.SAMBA_GENERATOR('ctdb-pc',
402 rule
='sed -e "%s" ${SRC} > ${TGT}' % sed_expr
)
403 bld
.INSTALL_FILES('${LIBDIR}/pkgconfig', 'ctdb.pc')
411 'ctdb_fetch_readonly_once',
412 'ctdb_fetch_readonly_loop',
413 'ctdb_trackingdb_test',
414 'ctdb_update_record',
415 'ctdb_update_record_persistent',
420 'ctdb_porting_tests',
427 src
= 'tests/src/' + t
+ '.c'
429 bld
.SAMBA_BINARY(target
,
431 deps
='''ctdb-client ctdb-common ctdb-common-util
432 ctdb-system ctdb-util ctdb-util-misc''',
433 install_path
='${CTDB_TEST_LIBDIR}')
435 bld
.SAMBA_BINARY('bin/ctdb_takeover_tests',
436 source
='tests/src/ctdb_takeover_tests.c',
437 deps
='replace popt tdb tevent talloc ctdb-system' +
439 includes
='../include ../include/internal lib/util',
440 install_path
='${CTDB_TEST_LIBDIR}')
442 bld
.SAMBA_BINARY('bin/ctdb_functest',
443 source
='tests/src/ctdb_functest.c',
444 deps
='replace tdb tevent talloc popt ctdb-system',
445 includes
='../include ../include/internal lib/util',
446 install_path
='${CTDB_TEST_LIBDIR}')
448 bld
.SAMBA_BINARY('bin/ctdb_stubtest',
449 source
='tests/src/ctdb_test.c',
450 deps
='replace tdb tevent talloc popt ctdb-system',
451 includes
='../include ../include/internal lib/util',
452 install_path
='${CTDB_TEST_LIBDIR}')
454 if bld
.env
.HAVE_INFINIBAND
:
455 bld
.SAMBA_BINARY('bin/ibwrapper_test',
456 source
='ib/ibwrapper_test.c',
457 includes
='include include/internal',
458 deps
='''replace talloc ctdb-client ctdb-common
459 ctdb-system ctdb-util-misc ctdb-util''' +
461 install_path
='${CTDB_TEST_LIBDIR}')
474 for t
in test_subdirs
:
475 files
= SUBDIR_MODE('tests/%s' % t
, trim_path
='tests')
477 bld
.INSTALL_FILES(bld
.env
.CTDB_TEST_DATADIR
, 'tests/%s' % fmode
[0],
478 destname
=fmode
[0], chmod
=fmode
[1])
480 sed_expr
= 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
481 bld
.env
.CTDB_TEST_LIBDIR
)
482 bld
.SAMBA_GENERATOR('ctdb-test-wrap',
483 source
='tests/scripts/test_wrap',
485 rule
='sed -e "%s" ${SRC} > ${TGT}' % sed_expr
)
487 sed_expr1
= 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
488 bld
.env
.CTDB_DATA_DIR
, bld
.env
.CTDB_LIBDIR
)
489 sed_expr2
= 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\1=true@'
490 bld
.SAMBA_GENERATOR('ctdb-test-runner',
491 source
='tests/run_tests.sh',
492 target
='ctdb_run_tests.sh',
493 rule
='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
494 sed_expr1
, sed_expr2
))
495 bld
.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
496 destname
='ctdb_run_tests', chmod
=0755)
497 bld
.symlink_as(os
.path
.join(bld
.env
.BINDIR
, 'ctdb_run_cluster_tests'),
500 test_eventscript_links
= [
506 test_link_dir
= os
.path
.join(bld
.env
.CTDB_TEST_DATADIR
,
507 'eventscripts/etc-ctdb')
508 for t
in test_eventscript_links
:
509 bld
.symlink_as(os
.path
.join(test_link_dir
, t
),
510 os
.path
.join(bld
.env
.CTDB_ETCDIR
, t
))
514 cmd
= 'tests/run_tests.sh -V tests/var'
515 samba_utils
.RUN_COMMAND(cmd
)
519 Scripting
.commands
.append('build')
520 Scripting
.commands
.append('testonly')
523 cmd
= 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
524 samba_utils
.RUN_COMMAND(cmd
)
528 samba_dist
.DIST_FILES('VERSION:VERSION', extend
=True)
530 t
= 'include/ctdb_version.h'
531 out
= os
.system('packaging/mkversion.sh %s %s' % (t
, VERSION
))
532 samba_dist
.DIST_FILES('ctdb/%s:%s' % (t
, t
), extend
=True)
535 sed_expr1
= 's/@VERSION@/%s/g' % VERSION
536 sed_expr2
= 's/@RELEASE@/%s/g' % '1'
537 os
.system('sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' %
538 (sed_expr1
, sed_expr2
, t
))
539 samba_dist
.DIST_FILES('ctdb/%s:%s' % (t
, t
), extend
=True)
551 os
.system('make -C doc')
553 samba_dist
.DIST_FILES('ctdb/doc/%s:doc/%s' % (t
, t
), extend
=True)
554 samba_dist
.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t
, t
),
560 cmd
= 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
561 samba_utils
.RUN_COMMAND(cmd
)
565 Scripting
.commands
.append('dist')
566 Scripting
.commands
.append('rpmonly')
569 "build 'tags' file using ctags"
571 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
572 cmd
= 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
573 print("Running: %s" % cmd
)