libcli:smbreadline: Fix code spelling
[Samba.git] / wscript
blob681e669d01983d1f9c99e12797f01417c3d4e277
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 opt.add_option('--with-kernel-keyring',
120 help=('Enable kernely keyring support for credential storage ' +
121 '(default if keyutils libraries are available)'),
122 action='store_true', dest='enable_keyring')
123 opt.add_option('--without-kernel-keyring',
124 help=('Disable kernely keyring support for credential storage'),
125 action='store_false', dest='enable_keyring')
127 gr = opt.option_group('developer options')
129 opt.load('python') # options for disabling pyc or pyo compilation
130 # enable options related to building python extensions
132 opt.add_option('--with-json',
133 action='store_true', dest='with_json',
134 help=("Build with JSON support (default=True). This "
135 "requires the jansson development headers."))
136 opt.add_option('--without-json',
137 action='store_false', dest='with_json',
138 help=("Build without JSON support."))
140 opt.samba_add_onoff_option('smb1-server',
141 dest='with_smb1server',
142 help=("Build smbd with SMB1 support (default=yes)."))
144 def configure(conf):
145 version = samba_version.load_version(env=conf.env)
147 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
148 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
149 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
151 if Options.options.developer:
152 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
153 conf.env.DEVELOPER = True
154 # if we are in a git tree without a pre-commit hook, install a
155 # simple default.
156 # we need git for 'waf dist'
157 githooksdir = None
158 conf.find_program('git', var='GIT')
159 if 'GIT' in conf.env:
160 githooksdir = conf.CHECK_COMMAND('%s rev-parse --git-path hooks' % conf.env.GIT[0],
161 msg='Finding githooks directory',
162 define=None,
163 on_target=False)
164 if githooksdir and os.path.isdir(githooksdir):
165 pre_commit_hook = os.path.join(githooksdir, 'pre-commit')
166 if not os.path.exists(pre_commit_hook):
167 Logs.info("Installing script/git-hooks/pre-commit-hook as %s" %
168 pre_commit_hook)
169 shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
170 pre_commit_hook)
172 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
174 conf.env.replace_add_global_pthread = True
175 conf.RECURSE('lib/replace')
177 conf.RECURSE('examples/fuse')
178 conf.RECURSE('examples/winexe')
180 conf.SAMBA_CHECK_PERL(mandatory=True)
181 conf.find_program('xsltproc', var='XSLTPROC')
183 if conf.env.disable_python:
184 if not (Options.options.without_ad_dc):
185 raise Errors.WafError('--disable-python requires --without-ad-dc')
187 conf.SAMBA_CHECK_PYTHON()
188 conf.SAMBA_CHECK_PYTHON_HEADERS()
190 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
191 # Mac OSX needs to have this and it's also needed that the python is compiled with this
192 # otherwise you face errors about common symbols
193 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
194 conf.ADD_CFLAGS('-fno-common')
195 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
196 conf.env.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
198 if sys.platform == 'darwin':
199 conf.ADD_LDFLAGS('-framework CoreFoundation')
201 conf.RECURSE('dynconfig')
202 conf.RECURSE('selftest')
204 conf.PROCESS_SEPARATE_RULE('system_gnutls')
206 conf.CHECK_CFG(package='zlib', minversion='1.2.3',
207 args='--cflags --libs',
208 mandatory=True)
209 conf.CHECK_FUNCS_IN('inflateInit2', 'z')
211 if Options.options.enable_keyring != False:
212 conf.env['WITH_KERNEL_KEYRING'] = 'auto'
213 if Options.options.enable_keyring == True:
214 conf.env['WITH_KERNEL_KEYRING'] = True
215 else:
216 conf.env['WITH_KERNEL_KEYRING'] = False
218 if conf.CHECK_FOR_THIRD_PARTY():
219 conf.RECURSE('third_party')
220 else:
222 if not conf.CHECK_POPT():
223 raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
224 else:
225 conf.define('USING_SYSTEM_POPT', 1)
227 if not conf.CHECK_CMOCKA():
228 raise Errors.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
229 else:
230 conf.define('USING_SYSTEM_CMOCKA', 1)
232 if conf.CONFIG_GET('ENABLE_SELFTEST'):
233 if not conf.CHECK_SOCKET_WRAPPER():
234 raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
235 else:
236 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
238 if not conf.CHECK_NSS_WRAPPER():
239 raise Errors.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
240 else:
241 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
243 if not conf.CHECK_RESOLV_WRAPPER():
244 raise Errors.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
245 else:
246 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
248 if not conf.CHECK_UID_WRAPPER():
249 raise Errors.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
250 else:
251 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
253 if not conf.CHECK_PAM_WRAPPER():
254 raise Errors.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
255 else:
256 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
258 conf.RECURSE('lib/ldb')
260 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
261 conf.env['HAVE_LDWRAP'] = True
262 conf.define('HAVE_LDWRAP', 1)
264 if not (Options.options.without_ad_dc):
265 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
267 # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
268 Logs.info("Checking for flex")
269 conf.find_program('flex', var='FLEX')
270 if conf.env['FLEX']:
271 conf.CHECK_COMMAND('%s --version' % conf.env.FLEX[0],
272 msg='Using flex version',
273 define=None,
274 on_target=False)
275 conf.env.FLEXFLAGS = ['-t']
277 # #line statements in these generated files cause issues for lcov
278 conf.env.FLEXFLAGS += ["--noline"]
280 Logs.info("Checking for bison")
281 bison.configure(conf)
282 if conf.env['BISON']:
283 conf.CHECK_COMMAND('%s --version | head -n1' % conf.env.BISON[0],
284 msg='Using bison version',
285 define=None,
286 on_target=False)
288 # #line statements in these generated files cause issues for lcov
289 conf.env.BISONFLAGS += ["--no-line"]
291 if Options.options.with_system_mitkrb5:
292 if not Options.options.with_experimental_mit_ad_dc and \
293 not Options.options.without_ad_dc:
294 raise Errors.WafError('The MIT Kerberos build of Samba as an AD DC ' +
295 'is experimental. Therefore '
296 '--with-system-mitkrb5 requires either ' +
297 '--with-experimental-mit-ad-dc or ' +
298 '--without-ad-dc')
300 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
302 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
303 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
305 if Options.options.with_system_heimdalkrb5:
306 if Options.options.with_system_mitkrb5:
307 raise Errors.WafError('--with-system-heimdalkrb5 conflicts with ' +
308 '--with-system-mitkrb5')
309 if not Options.options.without_ad_dc:
310 raise Errors.WafError('--with-system-heimdalkrb5 requires ' +
311 '--without-ad-dc')
312 conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
313 'hx509', 'wind', 'gssapi', 'hcrypto',
314 'krb5', 'heimbase', 'asn1_compile',
315 'compile_et', 'kdc', 'hdb', 'heimntlm')
316 conf.PROCESS_SEPARATE_RULE('system_heimdal')
318 if not conf.CONFIG_GET('KRB5_VENDOR'):
319 conf.PROCESS_SEPARATE_RULE('embedded_heimdal')
321 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
322 conf.RECURSE('source4/ntvfs/sysdep')
323 conf.RECURSE('lib/util')
324 conf.RECURSE('lib/util/charset')
325 conf.RECURSE('source4/auth')
326 conf.RECURSE('nsswitch')
327 conf.RECURSE('libcli/smbreadline')
328 conf.RECURSE('lib/crypto')
329 conf.RECURSE('pidl')
330 if conf.CONFIG_GET('ENABLE_SELFTEST'):
331 if not (Options.options.without_ad_dc):
332 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
333 conf.RECURSE('testsuite/unittests')
335 if Options.options.with_pthreadpool:
336 if conf.CONFIG_SET('HAVE_PTHREAD'):
337 conf.DEFINE('WITH_PTHREADPOOL', '1')
338 else:
339 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
340 conf.undefine('WITH_PTHREADPOOL')
342 conf.SET_TARGET_TYPE('jansson', 'EMPTY')
344 if Options.options.with_json != False:
345 if conf.CHECK_CFG(package='jansson', args='--cflags --libs',
346 msg='Checking for jansson'):
347 conf.CHECK_FUNCS_IN('json_object', 'jansson')
349 if not conf.CONFIG_GET('HAVE_JSON_OBJECT'):
350 if Options.options.with_json != False:
351 conf.fatal("Jansson JSON support not found. "
352 "Try installing libjansson-dev or jansson-devel. "
353 "Otherwise, use --without-json to build without "
354 "JSON support. "
355 "JSON support is required for the JSON "
356 "formatted audit log feature, the AD DC, and "
357 "the JSON printers of the net utility")
358 if not Options.options.without_ad_dc:
359 raise Errors.WafError('--without-json requires --without-ad-dc. '
360 'Jansson JSON library is required for '
361 'building the AD DC')
362 Logs.info("Building without Jansson JSON log support")
364 conf.RECURSE('source3')
365 conf.RECURSE('lib/texpect')
366 conf.RECURSE('lib/tsocket')
367 conf.RECURSE('python')
368 if conf.env.with_ctdb:
369 conf.RECURSE('ctdb')
370 conf.RECURSE('lib/socket')
371 conf.RECURSE('lib/mscat')
372 conf.RECURSE('packaging')
373 conf.RECURSE('lib/krb5_wrap')
375 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
377 # gentoo always adds this. We want our normal build to be as
378 # strict as the strictest OS we support, so adding this here
379 # allows us to find problems on our development hosts faster.
380 # It also results in faster load time.
382 if (not Options.options.address_sanitizer
383 and conf.CHECK_LDFLAGS('-Wl,--as-needed')):
384 conf.env.append_unique('LINKFLAGS', '-Wl,--as-needed')
386 if not conf.CHECK_NEED_LC("-lc not needed"):
387 conf.ADD_LDFLAGS('-lc', testflags=False)
389 if not conf.CHECK_CODE('#include "tests/summary.c"',
390 define='SUMMARY_PASSES',
391 addmain=False,
392 msg='Checking configure summary'):
393 raise Errors.WafError('configure summary failed')
395 if Options.options.enable_pie != False:
396 if Options.options.enable_pie == True:
397 need_pie = True
398 else:
399 # not specified, only build PIEs if supported by compiler
400 need_pie = False
401 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
402 msg="Checking compiler for PIE support"):
403 conf.env['ENABLE_PIE'] = True
405 if Options.options.enable_relro != False:
406 if Options.options.enable_relro == True:
407 need_relro = True
408 else:
409 # not specified, only build RELROs if supported by compiler
410 need_relro = False
411 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
412 msg="Checking compiler for full RELRO support"):
413 conf.env['ENABLE_RELRO'] = True
415 if conf.CONFIG_GET('ENABLE_SELFTEST') and \
416 Options.options.with_smb1server == False and \
417 Options.options.without_ad_dc != True:
418 conf.fatal('--without-smb1-server cannot be specified with '
419 '--enable-selftest/--enable-developer if '
420 '--without-ad-dc is NOT set!')
422 if Options.options.with_smb1server != False:
423 conf.DEFINE('WITH_SMB1SERVER', '1')
426 # FreeBSD is broken. It doesn't include 'extern char **environ'
427 # in any shared library, but statically inside crt0.o.
429 # If we're running on a FreeBSD with the GNU linker ld we
430 # can get around this by explicitly telling the linker to
431 # ignore 'environ' as an unresolved symbol in a shared library.
433 # However, the clang linker ld.lld-XX is broken in that it
434 # doesn't have that option.
436 # First try to see if have '-Wl,--ignore-unresolved-symbol,environ'
437 # and just use that if so.
439 # If not, we have to use '-Wl,--allow-shlib-undefined' instead
440 # and remove all instances of '-Wl,-no-undefined'.
442 if sys.platform.startswith('freebsd'):
443 # Do we have Wl,--ignore-unresolved-symbol,environ ?
444 flag_added = conf.ADD_LDFLAGS('-Wl,--ignore-unresolved-symbol,environ', testflags=True)
445 if not flag_added:
446 # No, fall back to -Wl,--allow-shlib-undefined.
447 conf.ADD_LDFLAGS('-Wl,--allow-shlib-undefined', testflags=True)
448 # Remove any uses of '-Wl,-no-undefined'
449 conf.env['EXTRA_LDFLAGS'] = list(filter(('-Wl,-no-undefined').__ne__, conf.env['EXTRA_LDFLAGS']))
450 # And make sure we don't try and remove it again when 'allow_undefined_symbols=true'
451 conf.env.undefined_ldflags = []
453 conf.SAMBA_CONFIG_H('include/config.h')
455 def etags(ctx):
456 '''build TAGS file using etags'''
457 from waflib import Utils
458 source_root = os.path.dirname(Context.g_module.root_path)
459 cmd = r'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
460 print("Running: %s" % cmd)
461 status = os.system(cmd)
462 if os.WEXITSTATUS(status):
463 raise Errors.WafError('etags failed')
465 def ctags(ctx):
466 "build 'tags' file using ctags"
467 from waflib import Utils
468 source_root = os.path.dirname(Context.g_module.root_path)
469 cmd = r'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
470 print("Running: %s" % cmd)
471 status = os.system(cmd)
472 if os.WEXITSTATUS(status):
473 raise Errors.WafError('ctags failed')
476 # putting this here enabled build in the list
477 # of commands in --help
478 def build(bld):
479 '''build all targets'''
480 samba_version.load_version(env=bld.env, is_install=bld.is_install)
483 def pep8(ctx):
484 '''run pep8 validator'''
485 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
486 print("Running: %s" % cmd)
487 status = os.system(cmd)
488 if os.WEXITSTATUS(status):
489 raise Errors.WafError('pep8 failed')
492 def dist():
493 '''makes a tarball for distribution'''
494 sambaversion = samba_version.load_version(env=None)
496 os.system("make -C ctdb manpages")
497 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
499 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + Context.g_module.top + "/release-scripts/build-manpages-nogit")
500 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
502 if sambaversion.IS_SNAPSHOT:
503 # write .distversion file and add to tar
504 if not os.path.isdir(Context.g_module.out):
505 os.makedirs(Context.g_module.out)
506 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=Context.g_module.out)
507 for field in sambaversion.vcs_fields:
508 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
509 distversionf.write(distveroption + '\n')
510 distversionf.flush()
511 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
513 samba_dist.dist()
514 distversionf.close()
515 else:
516 samba_dist.dist()
519 def distcheck():
520 '''test that distribution tarball builds and installs'''
521 samba_version.load_version(env=None)
523 def wildcard_cmd(cmd):
524 '''called on a unknown command'''
525 from samba_wildcard import run_named_build_task
526 run_named_build_task(cmd)
528 def main():
529 from samba_wildcard import wildcard_main
531 wildcard_main(wildcard_cmd)
532 Scripting.main = main
534 def reconfigure(ctx):
535 '''reconfigure if config scripts have changed'''
536 import samba_utils
537 samba_utils.reconfigure(ctx)
540 if os.path.isdir(os.path.join(top, ".git")):
541 # Check if there are submodules that are checked out but out of date.
542 for submodule, status in samba_git.read_submodule_status(top):
543 if status == "out-of-date":
544 raise Errors.WafError("some submodules are out of date. Please run 'git submodule update'")