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''')
38 opt
.PRIVATE_EXTENSION_DEFAULT('ctdb')
39 opt
.RECURSE('lib/replace')
40 opt
.RECURSE('lib/talloc')
41 opt
.RECURSE('lib/tevent')
42 opt
.RECURSE('lib/tdb')
44 opt
.add_option('--enable-infiniband',
45 help=("Turn on infiniband support (default=no)"),
46 action
="store_true", dest
='ctdb_infiniband', default
=False)
47 opt
.add_option('--enable-pmda',
48 help=("Turn on PCP pmda support (default=no)"),
49 action
="store_true", dest
='ctdb_pmda', default
=False)
51 opt
.add_option('--with-logdir',
52 help=("Path to log directory"),
53 action
="store", dest
='ctdb_logdir', default
=None)
54 opt
.add_option('--with-socketpath',
55 help=("path to CTDB daemon socket"),
56 action
="store_true", dest
='ctdb_sockpath', default
=False)
61 # CTDB relies on nested event loops
62 conf
.env
.TEVENT_DEPRECATED
= 1
64 # No need to build python bindings for talloc/tevent/tdb
65 if conf
.IN_LAUNCH_DIR():
66 Options
.options
.disable_python
= True
68 conf
.RECURSE('lib/replace')
69 conf
.RECURSE('lib/popt')
70 conf
.RECURSE('lib/talloc')
71 conf
.RECURSE('lib/tevent')
72 conf
.RECURSE('lib/tdb')
73 conf
.RECURSE('lib/socket_wrapper')
76 if Options
.options
.ctdb_pmda
:
79 if not conf
.CHECK_HEADERS('pcp/pmapi.h pcp/impl.h pcp/pmda.h',
82 if not conf
.CHECK_FUNCS_IN('pmProgname', 'pcp'):
84 if not conf
.CHECK_FUNCS_IN('pmdaDaemon', 'pcp_pmda'):
89 Logs
.error("PMDA support not available")
91 Logs
.info('Building with PMDA support')
92 conf
.define('HAVE_PMDA', 1)
93 conf
.env
.CTDB_PMDADIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
,
96 have_infiniband
= False
97 if Options
.options
.ctdb_infiniband
:
100 if not conf
.CHECK_HEADERS('infiniband/verbs.h rdma/rdma_cma.h'):
102 if not conf
.CHECK_FUNCS_IN('ibv_create_qp', 'ibverbs'):
104 if not conf
.CHECK_FUNCS_IN('rdma_connect', 'rdmacm'):
107 have_infiniband
= True
109 Logs
.error("Infiniband support not available")
111 Logs
.info('Building with Infiniband support')
112 conf
.define('HAVE_INFINIBAND', 1)
113 conf
.define('USE_INFINIBAND', 1)
115 conf
.env
.CTDB_BINDIR
= os
.path
.join(conf
.env
.EXEC_PREFIX
, 'bin')
116 conf
.env
.CTDB_ETCDIR
= os
.path
.join(conf
.env
.SYSCONFDIR
, 'ctdb')
117 conf
.env
.CTDB_VARDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'lib/ctdb')
118 conf
.env
.CTDB_RUNDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'run/ctdb')
120 machine
= os
.uname()[4]
121 if machine
in ['x86_64', 'ppc64', 'powerpc64']:
122 conf
.env
.LIBDIR
= conf
.env
.LIBDIR
+ '64'
124 if Options
.options
.ctdb_logdir
:
125 conf
.env
.CTDB_LOGDIR
= Options
.options
.ctdb_logdir
127 conf
.env
.CTDB_LOGDIR
= os
.path
.join(conf
.env
.LOCALSTATEDIR
, 'log')
129 if Options
.options
.ctdb_sockpath
:
130 conf
.env
.CTDB_SOCKPATH
= Options
.options
.ctdb_sockpath
132 conf
.env
.CTDB_SOCKPATH
= os
.path
.join(conf
.env
.CTDB_RUNDIR
,
135 conf
.ADD_CFLAGS('''-DBINDIR=\"%s\"
140 -DCTDB_RUNDIR=\"%s\"''' % (
141 conf
.env
.CTDB_BINDIR
,
142 conf
.env
.CTDB_LOGDIR
,
143 conf
.env
.CTDB_SOCKPATH
,
144 conf
.env
.CTDB_ETCDIR
,
145 conf
.env
.CTDB_VARDIR
,
146 conf
.env
.CTDB_RUNDIR
))
148 conf
.env
.CTDB_TEST_DATADIR
= os
.path
.join(conf
.env
.EXEC_PREFIX
,
150 conf
.env
.CTDB_TEST_LIBDIR
= os
.path
.join(conf
.env
.LIBDIR
, 'ctdb-tests')
152 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
153 conf
.SAMBA_CONFIG_H()
157 bld
.RECURSE('lib/replace')
158 bld
.RECURSE('lib/popt')
159 bld
.RECURSE('lib/talloc')
160 bld
.RECURSE('lib/tevent')
161 bld
.RECURSE('lib/tdb')
162 bld
.RECURSE('lib/socket_wrapper')
164 bld
.SAMBA_GENERATOR('ctdb-version-header',
165 target
='include/ctdb_version.h',
166 rule
='../packaging/mkversion.sh ${TGT} %s' % (VERSION
),
169 bld
.SAMBA_SUBSYSTEM('ctdb-util',
170 source
=bld
.SUBDIR('lib/util',
171 'util.c util_file.c util_time.c'),
172 includes
='include include/internal',
173 deps
='replace talloc tevent tdb')
175 bld
.SAMBA_SUBSYSTEM('ctdb-util-misc',
176 source
=bld
.SUBDIR('lib/util',
177 '''db_wrap.c debug.c fault.c
178 idtree.c signal.c strlist.c
180 includes
='include include/internal lib/util',
181 deps
='replace talloc tevent tdb')
183 bld
.SAMBA_SUBSYSTEM('ctdb-tcp',
184 source
=bld
.SUBDIR('tcp',
185 'tcp_connect.c tcp_init.c tcp_io.c'),
186 includes
='include include/internal',
187 deps
='replace tdb talloc tevent')
190 if bld
.env
.HAVE_INFINIBAND
:
191 bld
.SAMBA_SUBSYSTEM('ctdb-ib',
192 source
=bld
.SUBDIR('ib',
193 '''ibwrapper.c ibw_ctdb.c
195 includes
='include include/internal',
197 ib_deps
= ' ctdb-ib rdmacm ibverbs'
199 bld
.SAMBA_SUBSYSTEM('ctdb-common',
200 source
=bld
.SUBDIR('common',
201 '''ctdb_io.c ctdb_util.c ctdb_ltdb.c
202 ctdb_message.c cmdline.c rb_tree.c
203 system_common.c ctdb_fork.c'''),
204 includes
='include include/internal common . lib/util',
205 deps
='replace popt talloc tevent tdb')
207 bld
.SAMBA_SUBSYSTEM('ctdb-common-util',
208 source
=bld
.SUBDIR('common',
209 'system_util.c ctdb_logging.c'),
210 includes
='include include/internal',
211 deps
='replace tevent tdb')
213 if sys
.platform
== 'linux2':
214 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_linux.c')
215 elif sys
.platform
== 'aix':
216 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_aix.c')
217 elif sys
.platform
== 'freebsd':
218 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_freebsd.c')
219 elif sys
.platform
== 'kfreebsd':
220 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_kfreebsd.c')
221 elif sys
.platform
== 'gnu':
222 CTDB_SYSTEM_SRC
= bld
.SUBDIR('common', 'system_gnu.c')
224 Logs
.error("Platform %s not supported" % sys
.platform
)
226 bld
.SAMBA_SUBSYSTEM('ctdb-system',
227 source
=CTDB_SYSTEM_SRC
,
228 includes
='include include/internal',
229 deps
='replace talloc tevent tdb')
231 bld
.SAMBA_SUBSYSTEM('ctdb-client',
232 source
=bld
.SUBDIR('client', 'ctdb_client.c'),
233 includes
='include include/internal lib/util',
234 public_headers
='include/ctdb_client.h',
235 deps
='replace popt talloc tevent tdb')
237 bld
.SAMBA_SUBSYSTEM('ctdb-server',
238 source
='server/ctdbd.c ' +
240 '''ctdb_daemon.c ctdb_recoverd.c
241 ctdb_recover.c ctdb_freeze.c
242 ctdb_tunables.c ctdb_monitor.c
243 ctdb_server.c ctdb_control.c
244 ctdb_call.c ctdb_ltdb_server.c
245 ctdb_traverse.c eventscript.c
246 ctdb_takeover.c ctdb_serverids.c
247 ctdb_persistent.c ctdb_keepalive.c
248 ctdb_logging.c ctdb_uptime.c
249 ctdb_vacuum.c ctdb_banning.c
253 includes
='include include/internal lib/util',
254 public_headers
='''include/ctdb.h
255 include/ctdb_private.h
256 include/ctdb_protocol.h
257 include/ctdb_typesafe_cb.h''',
258 deps
='replace popt talloc tevent tdb')
260 bld
.SAMBA_BINARY('bin/ctdbd',
262 deps
='''ctdb-server ctdb-client ctdb-common
263 ctdb-common-util ctdb-system ctdb-tcp
264 ctdb-util ctdb-util-misc''' +
266 install_path
='${SBINDIR}',
267 manpages
='doc/ctdbd.1')
269 bld
.SAMBA_BINARY('bin/ctdb',
270 source
='tools/ctdb.c tools/ctdb_vacuum.c',
271 deps
='''ctdb-client ctdb-common ctdb-common-util
272 ctdb-system ctdb-util ctdb-util-misc''',
273 install_path
='${BINDIR}',
274 manpages
='doc/ctdb.1')
276 bld
.SAMBA_BINARY('bin/ltdbtool',
277 source
='tools/ltdbtool.c',
280 install_path
='${BINDIR}',
281 manpages
='doc/ltdbtool.1')
283 bld
.SAMBA_BINARY('bin/ctdb_lock_helper',
284 source
='server/ctdb_lock_helper.c',
285 deps
='ctdb-util ctdb-util-misc ctdb-common-util talloc tdb',
286 install_path
='${BINDIR}')
288 bld
.SAMBA_BINARY('bin/ctdb_event_helper',
289 source
='server/ctdb_event_helper.c',
290 includes
='include include/internal',
291 deps
='ctdb-util ctdb-util-misc ctdb-common-util replace tdb',
292 install_path
='${BINDIR}')
294 bld
.SAMBA_GENERATOR('ctdb-smnotify-h',
295 source
='utils/smnotify/smnotify.x',
296 target
='utils/smnotify/smnotify.h',
297 rule
='rpcgen -h ${SRC} > ${TGT}')
299 bld
.SAMBA_GENERATOR('ctdb-smnotify-x',
300 source
='utils/smnotify/smnotify.x',
301 target
='utils/smnotify/gen_xdr.c',
302 rule
='rpcgen -c ${SRC} > ${TGT}')
304 bld
.SAMBA_GENERATOR('ctdb-smnotify-c',
305 source
='utils/smnotify/smnotify.x',
306 target
='utils/smnotify/gen_smnotify.c',
307 rule
='rpcgen -l ${SRC} > ${TGT}')
309 bld
.SAMBA_BINARY('bin/smnotify',
310 source
=bld
.SUBDIR('utils/smnotify',
311 'smnotify.c gen_smnotify.c gen_xdr.c'),
312 deps
='ctdb-smnotify-h ctdb-smnotify-c ctdb-smnotify-x popt',
313 includes
='utils utils/smnotify',
314 install_path
='${BINDIR}')
316 bld
.SAMBA_BINARY('bin/ping_pong',
317 source
='utils/ping_pong/ping_pong.c',
319 install_path
='${BINDIR}',
320 manpages
='doc/ping_pong.1')
322 if bld
.env
.HAVE_PMDA
:
323 bld
.SAMBA_BINARY('bin/pmdactdb',
324 source
='utils/pmda/pmda_ctdb.c',
325 includes
='include include/internal',
326 deps
='''ctdb-client ctdb-common ctdb-system
327 ctdb-util-misc ctdb-util pcp_pmda pcp''',
328 install_path
='${CTDB_PMDADIR}')
329 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Install',
331 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/Remove',
333 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/pmns',
335 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/domain.h',
337 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/help',
339 bld
.INSTALL_FILES('${CTDB_PMDADIR}', 'utils/pmda/README',
342 bld
.MANPAGES('''doc/onnode.1 doc/ctdbd_wrapper.1 doc/ctdbd.conf.5
343 doc/ctdb.7 doc/ctdb-tunables.7''', True)
345 bld
.INSTALL_FILES('${BINDIR}', 'tools/onnode',
346 destname
='onnode', chmod
=0755)
347 bld
.INSTALL_FILES('${BINDIR}', 'tools/ctdb_diagnostics',
348 destname
='ctdb_diagnostics', chmod
=0755)
349 bld
.INSTALL_FILES('${SBINDIR}', 'config/ctdbd_wrapper',
350 destname
='ctdbd_wrapper', chmod
=0755)
352 def SUBDIR_MODE_callback(arg
, dirname
, fnames
):
354 fl
= os
.path
.join(dirname
, f
)
355 if os
.path
.isdir(fl
) or os
.path
.islink(fl
):
357 mode
= os
.lstat(fl
).st_mode
& 0777
359 fl
= samba_utils
.os_path_relpath(fl
, arg
['trim_path'])
360 arg
['file_list'].append([fl
, mode
])
362 def SUBDIR_MODE(path
, trim_path
=None):
363 pd
= {'trim_path': trim_path
, 'file_list': []}
364 os
.path
.walk(path
, SUBDIR_MODE_callback
, pd
)
365 return pd
['file_list']
372 for t
in etc_subdirs
:
373 files
= SUBDIR_MODE('config/%s' % t
, trim_path
='config')
375 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/%s' % fmode
[0],
376 destname
=fmode
[0], chmod
=fmode
[1])
378 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/functions',
379 destname
='functions')
382 'ctdb-crash-cleanup.sh',
383 'debug-hung-script.sh',
390 for t
in etc_scripts
:
391 bld
.INSTALL_FILES(bld
.env
.CTDB_ETCDIR
, 'config/' + t
,
392 destname
=t
, chmod
=0755)
394 bld
.INSTALL_FILES('${SYSCONFDIR}/sudoers.d', 'config/ctdb.sudoers',
397 bld
.INSTALL_FILES('${CTDB_ETCDIR}/notify.d', 'config/notify.d.README',
400 bld
.install_dir(bld
.env
.CTDB_LOGDIR
)
401 bld
.install_dir(bld
.env
.CTDB_RUNDIR
)
402 bld
.install_dir(bld
.env
.CTDB_VARDIR
)
404 sed_expr
= 's/@PACKAGE_VERSION@/%s/g' % VERSION
405 bld
.SAMBA_GENERATOR('ctdb-pc',
408 rule
='sed -e "%s" ${SRC} > ${TGT}' % sed_expr
)
409 bld
.INSTALL_FILES('${LIBDIR}/pkgconfig', 'ctdb.pc')
417 'ctdb_fetch_readonly_once',
418 'ctdb_fetch_readonly_loop',
419 'ctdb_trackingdb_test',
420 'ctdb_update_record',
421 'ctdb_update_record_persistent',
426 'ctdb_porting_tests',
433 src
= 'tests/src/' + t
+ '.c'
435 bld
.SAMBA_BINARY(target
,
437 deps
='''ctdb-client ctdb-common ctdb-common-util
438 ctdb-system ctdb-util ctdb-util-misc''',
439 install_path
='${CTDB_TEST_LIBDIR}')
441 bld
.SAMBA_BINARY('bin/ctdb_takeover_tests',
442 source
='tests/src/ctdb_takeover_tests.c',
443 deps
='replace popt tdb tevent talloc ctdb-system' +
445 includes
='../include ../include/internal lib/util',
446 install_path
='${CTDB_TEST_LIBDIR}')
448 bld
.SAMBA_BINARY('bin/ctdb_functest',
449 source
='tests/src/ctdb_functest.c',
450 deps
='replace tdb tevent talloc popt ctdb-system',
451 includes
='../include ../include/internal lib/util',
452 install_path
='${CTDB_TEST_LIBDIR}')
454 bld
.SAMBA_BINARY('bin/ctdb_stubtest',
455 source
='tests/src/ctdb_test.c',
456 deps
='replace tdb tevent talloc popt ctdb-system',
457 includes
='../include ../include/internal lib/util',
458 install_path
='${CTDB_TEST_LIBDIR}')
460 if bld
.env
.HAVE_INFINIBAND
:
461 bld
.SAMBA_BINARY('bin/ibwrapper_test',
462 source
='ib/ibwrapper_test.c',
463 includes
='include include/internal',
464 deps
='''replace talloc ctdb-client ctdb-common
465 ctdb-system ctdb-util-misc ctdb-util''' +
467 install_path
='${CTDB_TEST_LIBDIR}')
479 for t
in test_subdirs
:
480 files
= SUBDIR_MODE('tests/%s' % t
, trim_path
='tests')
482 bld
.INSTALL_FILES(bld
.env
.CTDB_TEST_DATADIR
, 'tests/%s' % fmode
[0],
483 destname
=fmode
[0], chmod
=fmode
[1])
485 # Install tests/scripts directory without test_wrap
492 for t
in test_scripts
:
493 bld
.INSTALL_FILES(bld
.env
.CTDB_TEST_DATADIR
,
494 os
.path
.join('tests/scripts', t
),
495 destname
=os
.path
.join('scripts', t
))
497 sed_expr
= 's@^TEST_SCRIPTS_DIR=.*@&\\nexport TEST_BIN_DIR=\"%s\"@' % (
498 bld
.env
.CTDB_TEST_LIBDIR
)
499 bld
.SAMBA_GENERATOR('ctdb-test-wrap',
500 source
='tests/scripts/test_wrap',
502 rule
='sed -e "%s" ${SRC} > ${TGT}' % sed_expr
)
503 bld
.INSTALL_FILES(bld
.env
.CTDB_TEST_DATADIR
+"/scripts", 'test_wrap',
504 destname
='test_wrap', chmod
=0755)
506 sed_expr1
= 's@^test_dir=.*@test_dir=%s\\nexport TEST_BIN_DIR=\"%s\"@' % (
507 bld
.env
.CTDB_TEST_DATADIR
, bld
.env
.CTDB_TEST_LIBDIR
)
508 sed_expr2
= 's@^\(export CTDB_TESTS_ARE_INSTALLED\)=false@\\1=true@'
509 bld
.SAMBA_GENERATOR('ctdb-test-runner',
510 source
='tests/run_tests.sh',
511 target
='ctdb_run_tests.sh',
512 rule
='sed -e "%s" -e "%s" ${SRC} > ${TGT}' % (
513 sed_expr1
, sed_expr2
))
514 bld
.INSTALL_FILES('${BINDIR}', 'ctdb_run_tests.sh',
515 destname
='ctdb_run_tests', chmod
=0755)
516 bld
.symlink_as(os
.path
.join(bld
.env
.BINDIR
, 'ctdb_run_cluster_tests'),
519 test_eventscript_links
= [
525 test_link_dir
= os
.path
.join(bld
.env
.CTDB_TEST_DATADIR
,
526 'eventscripts/etc-ctdb')
527 for t
in test_eventscript_links
:
528 bld
.symlink_as(os
.path
.join(test_link_dir
, t
),
529 os
.path
.join(bld
.env
.CTDB_ETCDIR
, t
))
533 cmd
= 'tests/run_tests.sh -V tests/var'
534 ret
= samba_utils
.RUN_COMMAND(cmd
)
536 print('tests exited with exit status %d' % ret
)
542 Scripting
.commands
.append('build')
543 Scripting
.commands
.append('testonly')
547 cmd
= 'LD_PRELOAD=bin/shared/libsocket-wrapper.so tests/run_tests.sh -e -S -C'
548 ret
= samba_utils
.RUN_COMMAND(cmd
)
550 print('autotest exited with exit status %d' % ret
)
554 def show_version(ctx
):
559 samba_dist
.DIST_FILES('VERSION:VERSION', extend
=True)
561 t
= 'include/ctdb_version.h'
562 cmd
= 'packaging/mkversion.sh %s %s' % (t
, VERSION
)
563 ret
= samba_utils
.RUN_COMMAND(cmd
)
565 print('Command "%s" failed with exit status %d' % (cmd
, ret
))
567 samba_dist
.DIST_FILES('ctdb/%s:%s' % (t
, t
), extend
=True)
570 sed_expr1
= 's/@VERSION@/%s/g' % VERSION
571 sed_expr2
= 's/@RELEASE@/%s/g' % '1'
572 cmd
= 'sed -e "%s" -e "%s" packaging/RPM/ctdb.spec.in > %s' % (
573 sed_expr1
, sed_expr2
, t
)
574 ret
= samba_utils
.RUN_COMMAND(cmd
)
576 print('Command "%s" failed with exit status %d' % (cmd
, ret
))
578 samba_dist
.DIST_FILES('ctdb/%s:%s' % (t
, t
), extend
=True)
591 ret
= samba_utils
.RUN_COMMAND(cmd
)
593 print('Command "%s" failed with exit status %d' % (cmd
, ret
))
596 samba_dist
.DIST_FILES('ctdb/doc/%s:doc/%s' % (t
, t
), extend
=True)
597 samba_dist
.DIST_FILES('ctdb/doc/%s.html:doc/%s.html' % (t
, t
),
604 cmd
= 'rpmbuild -ta --clean --rmsource ctdb-%s.tar.gz' % VERSION
605 ret
= samba_utils
.RUN_COMMAND(cmd
)
607 print('rpmbuild exited with exit status %d' % ret
)
613 Scripting
.commands
.append('dist')
614 Scripting
.commands
.append('rpmonly')
618 "build 'tags' file using ctags"
620 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
621 cmd
= 'ctags $(find %s -name "*.[ch]")' % source_root
622 print("Running: %s" % cmd
)
623 ret
= samba_utils
.RUN_COMMAND(cmd
)
625 print('ctags failed with exit status %d' % ret
)