witness.idl: fix length calculation for witness_IPaddrInfoList
[Samba.git] / wscript
blobee7daa953b2c3e0f7005d3b69dd62b85283628aa
1 #!/usr/bin/env python
3 top = '.'
4 out = 'bin'
6 APPNAME='samba'
7 VERSION=None
9 import sys, os, tempfile
10 sys.path.insert(0, top+"/buildtools/wafsamba")
11 import shutil
12 import wafsamba, samba_dist, samba_git, samba_version, samba_utils
13 from waflib import Options, Scripting, Logs, Context, Errors
14 from waflib.Tools import bison
16 samba_dist.DIST_DIRS('.')
17 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
19 # install in /usr/local/samba by default
20 default_prefix = Options.default_prefix = '/usr/local/samba'
22 # This callback optionally takes a list of paths as arguments:
23 # --with-system_mitkrb5 /path/to/krb5 /another/path
24 def system_mitkrb5_callback(option, opt, value, parser):
25 setattr(parser.values, option.dest, True)
26 value = []
27 for arg in parser.rargs:
28 # stop on --foo like options
29 if arg[:2] == "--" and len(arg) > 2:
30 break
31 value.append(arg)
32 if len(value)>0:
33 del parser.rargs[:len(value)]
34 setattr(parser.values, option.dest, value)
36 def options(opt):
37 opt.BUILTIN_DEFAULT('NONE')
38 opt.PRIVATE_EXTENSION_DEFAULT('samba4')
39 opt.RECURSE('lib/replace')
40 opt.RECURSE('dynconfig')
41 opt.RECURSE('packaging')
42 opt.RECURSE('lib/ldb')
43 opt.RECURSE('selftest')
44 opt.RECURSE('source4/dsdb/samdb/ldb_modules')
45 opt.RECURSE('pidl')
46 opt.RECURSE('source3')
47 opt.RECURSE('lib/util')
48 opt.RECURSE('lib/crypto')
49 opt.RECURSE('ctdb')
51 # Optional Libraries
52 # ------------------
54 # Most of the calls to opt.add_option() use default=True for the --with case
56 # To assist users and distributors to build Samba with the full feature
57 # set, the build system will abort if our dependent libraries and their
58 # header files are not found on the target system. This will mean for
59 # example, that xattr, acl and ldap headers must be installed for the
60 # default build to complete. The configure system will check for these
61 # headers, and the error message will indicate the option (such as
62 # --without-acl-support) that can be specified to skip this requirement.
64 # This will assist users and in particular distributors in building fully
65 # functional packages, while allowing those on systems truly without these
66 # facilities to continue to build Samba after careful consideration.
68 # It also ensures our container image generation in bootstrap/ is correct
69 # as otherwise a missing package there would just silently work
71 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
73 opt.add_option('--with-system-mitkrb5',
74 help='build Samba with system MIT Kerberos. ' +
75 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
76 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
78 opt.add_option('--with-experimental-mit-ad-dc',
79 help='Enable the experimental MIT Kerberos-backed AD DC. ' +
80 'Note that security patches are not issued for this configuration',
81 action='store_true',
82 dest='with_experimental_mit_ad_dc',
83 default=False)
85 opt.add_option('--with-system-mitkdc',
86 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
87 type="string",
88 dest='with_system_mitkdc',
89 default=None)
91 opt.add_option('--with-system-heimdalkrb5',
92 help=('build Samba with system Heimdal Kerberos. ' +
93 'Requires --without-ad-dc' and
94 'conflicts with --with-system-mitkrb5'),
95 action='store_true',
96 dest='with_system_heimdalkrb5',
97 default=False)
99 opt.add_option('--without-ad-dc',
100 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
101 action='store_true', dest='without_ad_dc', default=False)
103 opt.add_option('--with-pie',
104 help=("Build Position Independent Executables " +
105 "(default if supported by compiler)"),
106 action="store_true", dest='enable_pie')
107 opt.add_option('--without-pie',
108 help=("Disable Position Independent Executable builds"),
109 action="store_false", dest='enable_pie')
111 opt.add_option('--with-relro',
112 help=("Build with full RELocation Read-Only (RELRO)" +
113 "(default if supported by compiler)"),
114 action="store_true", dest='enable_relro')
115 opt.add_option('--without-relro',
116 help=("Disable RELRO builds"),
117 action="store_false", dest='enable_relro')
119 gr = opt.option_group('developer options')
121 opt.load('python') # options for disabling pyc or pyo compilation
122 # enable options related to building python extensions
124 opt.add_option('--with-json',
125 action='store_true', dest='with_json',
126 help=("Build with JSON support (default=True). This "
127 "requires the jansson development headers."))
128 opt.add_option('--without-json',
129 action='store_false', dest='with_json',
130 help=("Build without JSON support."))
132 def configure(conf):
133 version = samba_version.load_version(env=conf.env)
135 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
136 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
137 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
139 if Options.options.developer:
140 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
141 conf.env.DEVELOPER = True
142 # if we are in a git tree without a pre-commit hook, install a
143 # simple default.
144 pre_commit_hook = os.path.join(Context.g_module.top, '.git/hooks/pre-commit')
145 if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
146 not os.path.exists(pre_commit_hook)):
147 shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
148 pre_commit_hook)
150 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
152 conf.env.replace_add_global_pthread = True
153 conf.RECURSE('lib/replace')
155 conf.RECURSE('examples/fuse')
156 conf.RECURSE('examples/winexe')
158 conf.SAMBA_CHECK_PERL(mandatory=True)
159 conf.find_program('xsltproc', var='XSLTPROC')
161 if conf.env.disable_python:
162 if not (Options.options.without_ad_dc):
163 raise Errors.WafError('--disable-python requires --without-ad-dc')
165 conf.SAMBA_CHECK_PYTHON()
166 conf.SAMBA_CHECK_PYTHON_HEADERS()
168 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
169 # Mac OSX needs to have this and it's also needed that the python is compiled with this
170 # otherwise you face errors about common symbols
171 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
172 conf.ADD_CFLAGS('-fno-common')
173 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
174 conf.env.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
176 if sys.platform == 'darwin':
177 conf.ADD_LDFLAGS('-framework CoreFoundation')
179 conf.RECURSE('dynconfig')
180 conf.RECURSE('selftest')
182 conf.CHECK_CFG(package='zlib', minversion='1.2.3',
183 args='--cflags --libs',
184 mandatory=True)
185 conf.CHECK_FUNCS_IN('inflateInit2', 'z')
187 if conf.CHECK_FOR_THIRD_PARTY():
188 conf.RECURSE('third_party')
189 else:
191 if not conf.CHECK_POPT():
192 raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
193 else:
194 conf.define('USING_SYSTEM_POPT', 1)
196 if not conf.CHECK_CMOCKA():
197 raise Errors.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
198 else:
199 conf.define('USING_SYSTEM_CMOCKA', 1)
201 if conf.CONFIG_GET('ENABLE_SELFTEST'):
202 if not conf.CHECK_SOCKET_WRAPPER():
203 raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
204 else:
205 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
207 if not conf.CHECK_NSS_WRAPPER():
208 raise Errors.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
209 else:
210 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
212 if not conf.CHECK_RESOLV_WRAPPER():
213 raise Errors.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
214 else:
215 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
217 if not conf.CHECK_UID_WRAPPER():
218 raise Errors.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
219 else:
220 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
222 if not conf.CHECK_PAM_WRAPPER():
223 raise Errors.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
224 else:
225 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
227 conf.RECURSE('lib/ldb')
229 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
230 conf.env['HAVE_LDWRAP'] = True
231 conf.define('HAVE_LDWRAP', 1)
233 if not (Options.options.without_ad_dc):
234 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
236 # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
237 Logs.info("Checking for flex")
238 conf.find_program('flex', var='FLEX')
239 if conf.env['FLEX']:
240 conf.CHECK_COMMAND('%s --version' % conf.env.FLEX[0],
241 msg='Using flex version',
242 define=None,
243 on_target=False)
244 conf.env.FLEXFLAGS = ['-t']
246 # #line statements in these generated files cause issues for lcov
247 conf.env.FLEXFLAGS += ["--noline"]
249 Logs.info("Checking for bison")
250 bison.configure(conf)
251 if conf.env['BISON']:
252 conf.CHECK_COMMAND('%s --version | head -n1' % conf.env.BISON[0],
253 msg='Using bison version',
254 define=None,
255 on_target=False)
257 # #line statements in these generated files cause issues for lcov
258 conf.env.BISONFLAGS += ["--no-line"]
260 if Options.options.with_system_mitkrb5:
261 if not Options.options.with_experimental_mit_ad_dc and \
262 not Options.options.without_ad_dc:
263 raise Errors.WafError('The MIT Kerberos build of Samba as an AD DC ' +
264 'is experimental. Therefore '
265 '--with-system-mitkrb5 requires either ' +
266 '--with-experimental-mit-ad-dc or ' +
267 '--without-ad-dc')
269 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
271 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
272 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
274 if Options.options.with_system_heimdalkrb5:
275 if Options.options.with_system_mitkrb5:
276 raise Errors.WafError('--with-system-heimdalkrb5 conflicts with ' +
277 '--with-system-mitkrb5')
278 if not Options.options.without_ad_dc:
279 raise Errors.WafError('--with-system-heimdalkrb5 requires ' +
280 '--without-ad-dc')
281 conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
282 'hx509', 'wind', 'gssapi', 'hcrypto',
283 'krb5', 'heimbase', 'asn1_compile',
284 'compile_et', 'kdc', 'hdb', 'heimntlm')
285 conf.PROCESS_SEPARATE_RULE('system_heimdal')
287 if not conf.CONFIG_GET('KRB5_VENDOR'):
288 conf.PROCESS_SEPARATE_RULE('embedded_heimdal')
290 conf.PROCESS_SEPARATE_RULE('system_gnutls')
292 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
293 conf.RECURSE('source4/ntvfs/sysdep')
294 conf.RECURSE('lib/util')
295 conf.RECURSE('lib/util/charset')
296 conf.RECURSE('source4/auth')
297 conf.RECURSE('nsswitch')
298 conf.RECURSE('libcli/smbreadline')
299 conf.RECURSE('lib/crypto')
300 conf.RECURSE('pidl')
301 if conf.CONFIG_GET('ENABLE_SELFTEST'):
302 if not (Options.options.without_ad_dc):
303 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
304 conf.RECURSE('testsuite/unittests')
306 if Options.options.with_pthreadpool:
307 if conf.CONFIG_SET('HAVE_PTHREAD'):
308 conf.DEFINE('WITH_PTHREADPOOL', '1')
309 else:
310 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
311 conf.undefine('WITH_PTHREADPOOL')
313 conf.SET_TARGET_TYPE('jansson', 'EMPTY')
315 if Options.options.with_json != False:
316 if conf.CHECK_CFG(package='jansson', args='--cflags --libs',
317 msg='Checking for jansson'):
318 conf.CHECK_FUNCS_IN('json_object', 'jansson')
320 if not conf.CONFIG_GET('HAVE_JSON_OBJECT'):
321 if Options.options.with_json != False:
322 conf.fatal("Jansson JSON support not found. "
323 "Try installing libjansson-dev or jansson-devel. "
324 "Otherwise, use --without-json to build without "
325 "JSON support. "
326 "JSON support is required for the JSON "
327 "formatted audit log feature, the AD DC, and "
328 "the JSON printers of the net utility")
329 if not Options.options.without_ad_dc:
330 raise Errors.WafError('--without-json requires --without-ad-dc. '
331 'Jansson JSON library is required for '
332 'building the AD DC')
333 Logs.info("Building without Jansson JSON log support")
335 conf.RECURSE('source3')
336 conf.RECURSE('lib/texpect')
337 conf.RECURSE('python')
338 if conf.env.with_ctdb:
339 conf.RECURSE('ctdb')
340 conf.RECURSE('lib/socket')
341 conf.RECURSE('lib/mscat')
342 conf.RECURSE('packaging')
344 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
346 # gentoo always adds this. We want our normal build to be as
347 # strict as the strictest OS we support, so adding this here
348 # allows us to find problems on our development hosts faster.
349 # It also results in faster load time.
351 if conf.CHECK_LDFLAGS('-Wl,--as-needed'):
352 conf.env.append_unique('LINKFLAGS', '-Wl,--as-needed')
354 if not conf.CHECK_NEED_LC("-lc not needed"):
355 conf.ADD_LDFLAGS('-lc', testflags=False)
357 if not conf.CHECK_CODE('#include "tests/summary.c"',
358 define='SUMMARY_PASSES',
359 addmain=False,
360 msg='Checking configure summary'):
361 raise Errors.WafError('configure summary failed')
363 if Options.options.enable_pie != False:
364 if Options.options.enable_pie == True:
365 need_pie = True
366 else:
367 # not specified, only build PIEs if supported by compiler
368 need_pie = False
369 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
370 msg="Checking compiler for PIE support"):
371 conf.env['ENABLE_PIE'] = True
373 if Options.options.enable_relro != False:
374 if Options.options.enable_relro == True:
375 need_relro = True
376 else:
377 # not specified, only build RELROs if supported by compiler
378 need_relro = False
379 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
380 msg="Checking compiler for full RELRO support"):
381 conf.env['ENABLE_RELRO'] = True
384 # FreeBSD is broken. It doesn't include 'extern char **environ'
385 # in any shared library, but statically inside crt0.o.
387 # If we're running on a FreeBSD with the GNU linker ld we
388 # can get around this by explicitly telling the linker to
389 # ignore 'environ' as an unresolved symbol in a shared library.
391 # However, the clang linker ld.lld-XX is broken in that it
392 # doesn't have that option.
394 # First try to see if have '-Wl,--ignore-unresolved-symbol,environ'
395 # and just use that if so.
397 # If not, we have to use '-Wl,--allow-shlib-undefined' instead
398 # and remove all instances of '-Wl,-no-undefined'.
400 if sys.platform.startswith('freebsd'):
401 # Do we have Wl,--ignore-unresolved-symbol,environ ?
402 flag_added = conf.ADD_LDFLAGS('-Wl,--ignore-unresolved-symbol,environ', testflags=True)
403 if not flag_added:
404 # No, fall back to -Wl,--allow-shlib-undefined.
405 conf.ADD_LDFLAGS('-Wl,--allow-shlib-undefined', testflags=True)
406 # Remove any uses of '-Wl,-no-undefined'
407 conf.env['EXTRA_LDFLAGS'] = list(filter(('-Wl,-no-undefined').__ne__, conf.env['EXTRA_LDFLAGS']))
408 # And make sure we don't try and remove it again when 'allow_undefined_symbols=true'
409 conf.env.undefined_ldflags = []
411 conf.SAMBA_CONFIG_H('include/config.h')
413 def etags(ctx):
414 '''build TAGS file using etags'''
415 from waflib import Utils
416 source_root = os.path.dirname(Context.g_module.root_path)
417 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
418 print("Running: %s" % cmd)
419 status = os.system(cmd)
420 if os.WEXITSTATUS(status):
421 raise Errors.WafError('etags failed')
423 def ctags(ctx):
424 "build 'tags' file using ctags"
425 from waflib import Utils
426 source_root = os.path.dirname(Context.g_module.root_path)
427 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
428 print("Running: %s" % cmd)
429 status = os.system(cmd)
430 if os.WEXITSTATUS(status):
431 raise Errors.WafError('ctags failed')
434 # putting this here enabled build in the list
435 # of commands in --help
436 def build(bld):
437 '''build all targets'''
438 samba_version.load_version(env=bld.env, is_install=bld.is_install)
441 def pydoctor(ctx):
442 '''build python apidocs'''
443 bp = os.path.abspath('bin/python')
444 mpaths = {}
445 modules = ['talloc', 'tdb', 'ldb']
446 for m in modules:
447 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
448 try:
449 mpaths[m] = f.read().strip()
450 finally:
451 f.close()
452 mpaths['main'] = bp
453 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
454 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
455 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
456 cmd = cmd % mpaths
457 print("Running: %s" % cmd)
458 status = os.system(cmd)
459 if os.WEXITSTATUS(status):
460 raise Errors.WafError('pydoctor failed')
463 def pep8(ctx):
464 '''run pep8 validator'''
465 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
466 print("Running: %s" % cmd)
467 status = os.system(cmd)
468 if os.WEXITSTATUS(status):
469 raise Errors.WafError('pep8 failed')
472 def wafdocs(ctx):
473 '''build wafsamba apidocs'''
474 from samba_utils import recursive_dirlist
475 os.system('pwd')
476 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
478 print(list)
479 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext' +\
480 "".join(' --add-module %s' % f for f in list)
481 print("Running: %s" % cmd)
482 status = os.system(cmd)
483 if os.WEXITSTATUS(status):
484 raise Errors.WafError('wafdocs failed')
487 def dist():
488 '''makes a tarball for distribution'''
489 sambaversion = samba_version.load_version(env=None)
491 os.system("make -C ctdb manpages")
492 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
494 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + Context.g_module.top + "/release-scripts/build-manpages-nogit")
495 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
497 if sambaversion.IS_SNAPSHOT:
498 # write .distversion file and add to tar
499 if not os.path.isdir(Context.g_module.out):
500 os.makedirs(Context.g_module.out)
501 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=Context.g_module.out)
502 for field in sambaversion.vcs_fields:
503 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
504 distversionf.write(distveroption + '\n')
505 distversionf.flush()
506 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
508 samba_dist.dist()
509 distversionf.close()
510 else:
511 samba_dist.dist()
514 def distcheck():
515 '''test that distribution tarball builds and installs'''
516 samba_version.load_version(env=None)
518 def wildcard_cmd(cmd):
519 '''called on a unknown command'''
520 from samba_wildcard import run_named_build_task
521 run_named_build_task(cmd)
523 def main():
524 from samba_wildcard import wildcard_main
526 wildcard_main(wildcard_cmd)
527 Scripting.main = main
529 def reconfigure(ctx):
530 '''reconfigure if config scripts have changed'''
531 import samba_utils
532 samba_utils.reconfigure(ctx)
535 if os.path.isdir(os.path.join(top, ".git")):
536 # Check if there are submodules that are checked out but out of date.
537 for submodule, status in samba_git.read_submodule_status(top):
538 if status == "out-of-date":
539 raise Errors.WafError("some submodules are out of date. Please run 'git submodule update'")