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