torture: smbtorture test case to verify Compound related handling
[Samba.git] / wscript
blobdc547b44aa44e67ccb286374612007ede7f04858
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
15 samba_dist.DIST_DIRS('.')
16 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
18 # install in /usr/local/samba by default
19 default_prefix = Options.default_prefix = '/usr/local/samba'
21 # This callback optionally takes a list of paths as arguments:
22 # --with-system_mitkrb5 /path/to/krb5 /another/path
23 def system_mitkrb5_callback(option, opt, value, parser):
24 setattr(parser.values, option.dest, True)
25 value = []
26 for arg in parser.rargs:
27 # stop on --foo like options
28 if arg[:2] == "--" and len(arg) > 2:
29 break
30 value.append(arg)
31 if len(value)>0:
32 del parser.rargs[:len(value)]
33 setattr(parser.values, option.dest, value)
35 def options(opt):
36 opt.BUILTIN_DEFAULT('NONE')
37 opt.PRIVATE_EXTENSION_DEFAULT('samba4')
38 opt.RECURSE('lib/replace')
39 opt.RECURSE('dynconfig')
40 opt.RECURSE('packaging')
41 opt.RECURSE('lib/ldb')
42 opt.RECURSE('selftest')
43 opt.RECURSE('source4/dsdb/samdb/ldb_modules')
44 opt.RECURSE('pidl')
45 opt.RECURSE('source3')
46 opt.RECURSE('lib/util')
47 opt.RECURSE('lib/crypto')
48 opt.RECURSE('ctdb')
50 # Optional Libraries
51 # ------------------
53 # Most of the calls to opt.add_option() use default=True for the --with case
55 # To assist users and distributors to build Samba with the full feature
56 # set, the build system will abort if our dependent libraries and their
57 # header files are not found on the target system. This will mean for
58 # example, that xattr, acl and ldap headers must be installed for the
59 # default build to complete. The configure system will check for these
60 # headers, and the error message will indicate the option (such as
61 # --without-acl-support) that can be specified to skip this requirement.
63 # This will assist users and in particular distributors in building fully
64 # functional packages, while allowing those on systems truly without these
65 # facilities to continue to build Samba after careful consideration.
67 # It also ensures our container image generation in bootstrap/ is correct
68 # as otherwise a missing package there would just silently work
70 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
72 opt.add_option('--with-system-mitkrb5',
73 help='build Samba with system MIT Kerberos. ' +
74 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
75 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
77 opt.add_option('--with-experimental-mit-ad-dc',
78 help='Enable the experimental MIT Kerberos-backed AD DC. ' +
79 'Note that security patches are not issued for this configuration',
80 action='store_true',
81 dest='with_experimental_mit_ad_dc',
82 default=False)
84 opt.add_option('--with-system-mitkdc',
85 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
86 type="string",
87 dest='with_system_mitkdc',
88 default=None)
90 opt.add_option('--with-system-heimdalkrb5',
91 help=('build Samba with system Heimdal Kerberos. ' +
92 'Requires --without-ad-dc' and
93 'conflicts with --with-system-mitkrb5'),
94 action='store_true',
95 dest='with_system_heimdalkrb5',
96 default=False)
98 opt.add_option('--without-ad-dc',
99 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
100 action='store_true', dest='without_ad_dc', default=False)
102 opt.add_option('--with-pie',
103 help=("Build Position Independent Executables " +
104 "(default if supported by compiler)"),
105 action="store_true", dest='enable_pie')
106 opt.add_option('--without-pie',
107 help=("Disable Position Independent Executable builds"),
108 action="store_false", dest='enable_pie')
110 opt.add_option('--with-relro',
111 help=("Build with full RELocation Read-Only (RELRO)" +
112 "(default if supported by compiler)"),
113 action="store_true", dest='enable_relro')
114 opt.add_option('--without-relro',
115 help=("Disable RELRO builds"),
116 action="store_false", dest='enable_relro')
118 gr = opt.option_group('developer options')
120 opt.load('python') # options for disabling pyc or pyo compilation
121 # enable options related to building python extensions
123 opt.add_option('--with-json',
124 action='store_true', dest='with_json',
125 help=("Build with JSON support (default=True). This "
126 "requires the jansson development headers."))
127 opt.add_option('--without-json',
128 action='store_false', dest='with_json',
129 help=("Build without JSON support."))
131 def configure(conf):
132 version = samba_version.load_version(env=conf.env)
134 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
135 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
136 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
138 if Options.options.developer:
139 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
140 conf.env.DEVELOPER = True
141 # if we are in a git tree without a pre-commit hook, install a
142 # simple default.
143 pre_commit_hook = os.path.join(Context.g_module.top, '.git/hooks/pre-commit')
144 if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
145 not os.path.exists(pre_commit_hook)):
146 shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
147 pre_commit_hook)
149 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
151 conf.env.replace_add_global_pthread = True
152 conf.RECURSE('lib/replace')
154 conf.RECURSE('examples/fuse')
155 conf.RECURSE('examples/winexe')
157 conf.SAMBA_CHECK_PERL(mandatory=True)
158 conf.find_program('xsltproc', var='XSLTPROC')
160 if conf.env.disable_python:
161 if not (Options.options.without_ad_dc):
162 raise Errors.WafError('--disable-python requires --without-ad-dc')
164 conf.SAMBA_CHECK_PYTHON()
165 conf.SAMBA_CHECK_PYTHON_HEADERS()
167 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
168 # Mac OSX needs to have this and it's also needed that the python is compiled with this
169 # otherwise you face errors about common symbols
170 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
171 conf.ADD_CFLAGS('-fno-common')
172 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
173 conf.env.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
175 if sys.platform == 'darwin':
176 conf.ADD_LDFLAGS('-framework CoreFoundation')
178 conf.RECURSE('dynconfig')
179 conf.RECURSE('selftest')
181 conf.CHECK_CFG(package='zlib', minversion='1.2.3',
182 args='--cflags --libs',
183 mandatory=True)
184 conf.CHECK_FUNCS_IN('inflateInit2', 'z')
186 if conf.CHECK_FOR_THIRD_PARTY():
187 conf.RECURSE('third_party')
188 else:
190 if not conf.CHECK_POPT():
191 raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
192 else:
193 conf.define('USING_SYSTEM_POPT', 1)
195 if not conf.CHECK_CMOCKA():
196 raise Errors.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
197 else:
198 conf.define('USING_SYSTEM_CMOCKA', 1)
200 if conf.CONFIG_GET('ENABLE_SELFTEST'):
201 if not conf.CHECK_SOCKET_WRAPPER():
202 raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
203 else:
204 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
206 if not conf.CHECK_NSS_WRAPPER():
207 raise Errors.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
208 else:
209 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
211 if not conf.CHECK_RESOLV_WRAPPER():
212 raise Errors.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
213 else:
214 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
216 if not conf.CHECK_UID_WRAPPER():
217 raise Errors.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
218 else:
219 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
221 if not conf.CHECK_PAM_WRAPPER():
222 raise Errors.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
223 else:
224 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
226 conf.RECURSE('lib/ldb')
228 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
229 conf.env['HAVE_LDWRAP'] = True
230 conf.define('HAVE_LDWRAP', 1)
232 if not (Options.options.without_ad_dc):
233 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
235 # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
236 Logs.info("Checking for flex")
237 conf.find_program('flex', var='FLEX')
238 if conf.env['FLEX']:
239 conf.CHECK_COMMAND('%s --version' % conf.env.FLEX[0],
240 msg='Using flex version',
241 define=None,
242 on_target=False)
243 conf.env.FLEXFLAGS = ['-t']
245 # #line statements in these generated files cause issues for lcov
246 conf.env.FLEXFLAGS += ["--noline"]
248 if Options.options.with_system_mitkrb5:
249 if not Options.options.with_experimental_mit_ad_dc and \
250 not Options.options.without_ad_dc:
251 raise Errors.WafError('The MIT Kerberos build of Samba as an AD DC ' +
252 'is experimental. Therefore '
253 '--with-system-mitkrb5 requires either ' +
254 '--with-experimental-mit-ad-dc or ' +
255 '--without-ad-dc')
257 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
259 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
260 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
262 if Options.options.with_system_heimdalkrb5:
263 if Options.options.with_system_mitkrb5:
264 raise Errors.WafError('--with-system-heimdalkrb5 conflicts with ' +
265 '--with-system-mitkrb5')
266 if not Options.options.without_ad_dc:
267 raise Errors.WafError('--with-system-heimdalkrb5 requires ' +
268 '--without-ad-dc')
269 conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
270 'hx509', 'wind', 'gssapi', 'hcrypto',
271 'krb5', 'heimbase', 'asn1_compile',
272 'compile_et', 'kdc', 'hdb', 'heimntlm')
273 conf.PROCESS_SEPARATE_RULE('system_heimdal')
275 if not conf.CONFIG_GET('KRB5_VENDOR'):
276 conf.PROCESS_SEPARATE_RULE('embedded_heimdal')
278 conf.PROCESS_SEPARATE_RULE('system_gnutls')
280 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
281 conf.RECURSE('source4/ntvfs/sysdep')
282 conf.RECURSE('lib/util')
283 conf.RECURSE('lib/util/charset')
284 conf.RECURSE('source4/auth')
285 conf.RECURSE('nsswitch')
286 conf.RECURSE('libcli/smbreadline')
287 conf.RECURSE('lib/crypto')
288 conf.RECURSE('pidl')
289 if conf.CONFIG_GET('ENABLE_SELFTEST'):
290 if not (Options.options.without_ad_dc):
291 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
292 conf.RECURSE('testsuite/unittests')
294 if Options.options.with_pthreadpool:
295 if conf.CONFIG_SET('HAVE_PTHREAD'):
296 conf.DEFINE('WITH_PTHREADPOOL', '1')
297 else:
298 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
299 conf.undefine('WITH_PTHREADPOOL')
301 conf.SET_TARGET_TYPE('jansson', 'EMPTY')
303 if Options.options.with_json != False:
304 if conf.CHECK_CFG(package='jansson', args='--cflags --libs',
305 msg='Checking for jansson'):
306 conf.CHECK_FUNCS_IN('json_object', 'jansson')
308 if not conf.CONFIG_GET('HAVE_JSON_OBJECT'):
309 if Options.options.with_json != False:
310 conf.fatal("Jansson JSON support not found. "
311 "Try installing libjansson-dev or jansson-devel. "
312 "Otherwise, use --without-json to build without "
313 "JSON support. "
314 "JSON support is required for the JSON "
315 "formatted audit log feature, the AD DC, and "
316 "the JSON printers of the net utility")
317 if not Options.options.without_ad_dc:
318 raise Errors.WafError('--without-json requires --without-ad-dc. '
319 'Jansson JSON library is required for '
320 'building the AD DC')
321 Logs.info("Building without Jansson JSON log support")
323 conf.RECURSE('source3')
324 conf.RECURSE('lib/texpect')
325 conf.RECURSE('python')
326 if conf.env.with_ctdb:
327 conf.RECURSE('ctdb')
328 conf.RECURSE('lib/socket')
329 conf.RECURSE('lib/mscat')
330 conf.RECURSE('packaging')
332 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
334 # gentoo always adds this. We want our normal build to be as
335 # strict as the strictest OS we support, so adding this here
336 # allows us to find problems on our development hosts faster.
337 # It also results in faster load time.
339 if conf.CHECK_LDFLAGS('-Wl,--as-needed'):
340 conf.env.append_unique('LINKFLAGS', '-Wl,--as-needed')
342 if not conf.CHECK_NEED_LC("-lc not needed"):
343 conf.ADD_LDFLAGS('-lc', testflags=False)
345 if not conf.CHECK_CODE('#include "tests/summary.c"',
346 define='SUMMARY_PASSES',
347 addmain=False,
348 msg='Checking configure summary'):
349 raise Errors.WafError('configure summary failed')
351 if Options.options.enable_pie != False:
352 if Options.options.enable_pie == True:
353 need_pie = True
354 else:
355 # not specified, only build PIEs if supported by compiler
356 need_pie = False
357 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
358 msg="Checking compiler for PIE support"):
359 conf.env['ENABLE_PIE'] = True
361 if Options.options.enable_relro != False:
362 if Options.options.enable_relro == True:
363 need_relro = True
364 else:
365 # not specified, only build RELROs if supported by compiler
366 need_relro = False
367 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
368 msg="Checking compiler for full RELRO support"):
369 conf.env['ENABLE_RELRO'] = True
371 conf.SAMBA_CONFIG_H('include/config.h')
373 def etags(ctx):
374 '''build TAGS file using etags'''
375 from waflib import Utils
376 source_root = os.path.dirname(Context.g_module.root_path)
377 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
378 print("Running: %s" % cmd)
379 status = os.system(cmd)
380 if os.WEXITSTATUS(status):
381 raise Errors.WafError('etags failed')
383 def ctags(ctx):
384 "build 'tags' file using ctags"
385 from waflib import Utils
386 source_root = os.path.dirname(Context.g_module.root_path)
387 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
388 print("Running: %s" % cmd)
389 status = os.system(cmd)
390 if os.WEXITSTATUS(status):
391 raise Errors.WafError('ctags failed')
394 # putting this here enabled build in the list
395 # of commands in --help
396 def build(bld):
397 '''build all targets'''
398 samba_version.load_version(env=bld.env, is_install=bld.is_install)
401 def pydoctor(ctx):
402 '''build python apidocs'''
403 bp = os.path.abspath('bin/python')
404 mpaths = {}
405 modules = ['talloc', 'tdb', 'ldb']
406 for m in modules:
407 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
408 try:
409 mpaths[m] = f.read().strip()
410 finally:
411 f.close()
412 mpaths['main'] = bp
413 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
414 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
415 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
416 cmd = cmd % mpaths
417 print("Running: %s" % cmd)
418 status = os.system(cmd)
419 if os.WEXITSTATUS(status):
420 raise Errors.WafError('pydoctor failed')
423 def pep8(ctx):
424 '''run pep8 validator'''
425 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
426 print("Running: %s" % cmd)
427 status = os.system(cmd)
428 if os.WEXITSTATUS(status):
429 raise Errors.WafError('pep8 failed')
432 def wafdocs(ctx):
433 '''build wafsamba apidocs'''
434 from samba_utils import recursive_dirlist
435 os.system('pwd')
436 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
438 print(list)
439 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext' +\
440 "".join(' --add-module %s' % f for f in list)
441 print("Running: %s" % cmd)
442 status = os.system(cmd)
443 if os.WEXITSTATUS(status):
444 raise Errors.WafError('wafdocs failed')
447 def dist():
448 '''makes a tarball for distribution'''
449 sambaversion = samba_version.load_version(env=None)
451 os.system("make -C ctdb manpages")
452 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
454 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + Context.g_module.top + "/release-scripts/build-manpages-nogit")
455 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
457 if sambaversion.IS_SNAPSHOT:
458 # write .distversion file and add to tar
459 if not os.path.isdir(Context.g_module.out):
460 os.makedirs(Context.g_module.out)
461 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=Context.g_module.out)
462 for field in sambaversion.vcs_fields:
463 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
464 distversionf.write(distveroption + '\n')
465 distversionf.flush()
466 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
468 samba_dist.dist()
469 distversionf.close()
470 else:
471 samba_dist.dist()
474 def distcheck():
475 '''test that distribution tarball builds and installs'''
476 samba_version.load_version(env=None)
478 def wildcard_cmd(cmd):
479 '''called on a unknown command'''
480 from samba_wildcard import run_named_build_task
481 run_named_build_task(cmd)
483 def main():
484 from samba_wildcard import wildcard_main
486 wildcard_main(wildcard_cmd)
487 Scripting.main = main
489 def reconfigure(ctx):
490 '''reconfigure if config scripts have changed'''
491 import samba_utils
492 samba_utils.reconfigure(ctx)
495 if os.path.isdir(os.path.join(top, ".git")):
496 # Check if there are submodules that are checked out but out of date.
497 for submodule, status in samba_git.read_submodule_status(top):
498 if status == "out-of-date":
499 raise Errors.WafError("some submodules are out of date. Please run 'git submodule update'")