9 import sys
, os
, tempfile
10 sys
.path
.insert(0, top
+"/buildtools/wafsamba")
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)
27 for arg
in parser
.rargs
:
28 # stop on --foo like options
29 if arg
[:2] == "--" and len(arg
) > 2:
33 del parser
.rargs
[:len(value
)]
34 setattr(parser
.values
, option
.dest
, value
)
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')
46 opt
.RECURSE('source3')
47 opt
.RECURSE('lib/util')
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',
81 dest
='with_experimental_mit_ad_dc',
84 opt
.add_option('--with-system-mitkdc',
85 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
87 dest
='with_system_mitkdc',
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'),
95 dest
='with_system_heimdalkrb5',
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 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)."))
144 version
= samba_version
.load_version(env
=conf
.env
)
146 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
147 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
148 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
150 if Options
.options
.developer
:
151 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
152 conf
.env
.DEVELOPER
= True
153 # if we are in a git tree without a pre-commit hook, install a
155 # we need git for 'waf dist'
157 conf
.find_program('git', var
='GIT')
158 if 'GIT' in conf
.env
:
159 githooksdir
= conf
.CHECK_COMMAND('%s rev-parse --git-path hooks' % conf
.env
.GIT
[0],
160 msg
='Finding githooks directory',
163 if githooksdir
and os
.path
.isdir(githooksdir
):
164 pre_commit_hook
= os
.path
.join(githooksdir
, 'pre-commit')
165 if not os
.path
.exists(pre_commit_hook
):
166 Logs
.info("Installing script/git-hooks/pre-commit-hook as %s" %
168 shutil
.copy(os
.path
.join(Context
.g_module
.top
, 'script/git-hooks/pre-commit-hook'),
171 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
173 conf
.env
.replace_add_global_pthread
= True
174 conf
.RECURSE('lib/replace')
176 conf
.RECURSE('examples/fuse')
177 conf
.RECURSE('examples/winexe')
179 conf
.SAMBA_CHECK_PERL(mandatory
=True)
180 conf
.find_program('xsltproc', var
='XSLTPROC')
182 if conf
.env
.disable_python
:
183 if not (Options
.options
.without_ad_dc
):
184 raise Errors
.WafError('--disable-python requires --without-ad-dc')
186 conf
.SAMBA_CHECK_PYTHON()
187 conf
.SAMBA_CHECK_PYTHON_HEADERS()
189 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
190 # Mac OSX needs to have this and it's also needed that the python is compiled with this
191 # otherwise you face errors about common symbols
192 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
193 conf
.ADD_CFLAGS('-fno-common')
194 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
195 conf
.env
.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
197 if sys
.platform
== 'darwin':
198 conf
.ADD_LDFLAGS('-framework CoreFoundation')
200 conf
.RECURSE('dynconfig')
201 conf
.RECURSE('selftest')
203 conf
.PROCESS_SEPARATE_RULE('system_gnutls')
205 conf
.CHECK_CFG(package
='zlib', minversion
='1.2.3',
206 args
='--cflags --libs',
208 conf
.CHECK_FUNCS_IN('inflateInit2', 'z')
210 if Options
.options
.enable_keyring
is not False:
211 conf
.env
['WITH_KERNEL_KEYRING'] = 'auto'
212 if Options
.options
.enable_keyring
is True:
213 conf
.env
['WITH_KERNEL_KEYRING'] = True
215 conf
.env
['WITH_KERNEL_KEYRING'] = False
217 if conf
.CHECK_FOR_THIRD_PARTY():
218 conf
.RECURSE('third_party')
221 if not conf
.CHECK_POPT():
222 raise Errors
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
224 conf
.define('USING_SYSTEM_POPT', 1)
226 if not conf
.CHECK_CMOCKA():
227 raise Errors
.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
229 conf
.define('USING_SYSTEM_CMOCKA', 1)
231 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
232 if not conf
.CHECK_SOCKET_WRAPPER():
233 raise Errors
.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
235 conf
.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
237 if not conf
.CHECK_NSS_WRAPPER():
238 raise Errors
.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
240 conf
.define('USING_SYSTEM_NSS_WRAPPER', 1)
242 if not conf
.CHECK_RESOLV_WRAPPER():
243 raise Errors
.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
245 conf
.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
247 if not conf
.CHECK_UID_WRAPPER():
248 raise Errors
.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
250 conf
.define('USING_SYSTEM_UID_WRAPPER', 1)
252 if not conf
.CHECK_PAM_WRAPPER():
253 raise Errors
.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
255 conf
.define('USING_SYSTEM_PAM_WRAPPER', 1)
257 conf
.RECURSE('lib/ldb')
259 if conf
.CHECK_LDFLAGS(['-Wl,--wrap=test']):
260 conf
.env
['HAVE_LDWRAP'] = True
261 conf
.define('HAVE_LDWRAP', 1)
263 if not (Options
.options
.without_ad_dc
):
264 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
266 # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
267 Logs
.info("Checking for flex")
268 conf
.find_program('flex', var
='FLEX')
270 conf
.CHECK_COMMAND('%s --version' % conf
.env
.FLEX
[0],
271 msg
='Using flex version',
274 conf
.env
.FLEXFLAGS
= ['-t']
276 # #line statements in these generated files cause issues for lcov
277 conf
.env
.FLEXFLAGS
+= ["--noline"]
279 Logs
.info("Checking for bison")
280 bison
.configure(conf
)
281 if conf
.env
['BISON']:
282 conf
.CHECK_COMMAND('%s --version | head -n1' % conf
.env
.BISON
[0],
283 msg
='Using bison version',
287 # #line statements in these generated files cause issues for lcov
288 conf
.env
.BISONFLAGS
+= ["--no-line"]
290 if Options
.options
.with_system_mitkrb5
:
291 if not Options
.options
.with_experimental_mit_ad_dc
and \
292 not Options
.options
.without_ad_dc
:
293 raise Errors
.WafError('The MIT Kerberos build of Samba as an AD DC ' +
294 'is experimental. Therefore '
295 '--with-system-mitkrb5 requires either ' +
296 '--with-experimental-mit-ad-dc or ' +
299 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
301 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
302 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
304 if Options
.options
.with_system_heimdalkrb5
:
305 if Options
.options
.with_system_mitkrb5
:
306 raise Errors
.WafError('--with-system-heimdalkrb5 conflicts with ' +
307 '--with-system-mitkrb5')
308 if not Options
.options
.without_ad_dc
:
309 raise Errors
.WafError('--with-system-heimdalkrb5 requires ' +
311 conf
.env
.SYSTEM_LIBS
+= ('heimdal', 'asn1', 'com_err', 'roken',
312 'hx509', 'wind', 'gssapi', 'hcrypto',
313 'krb5', 'heimbase', 'asn1_compile',
314 'compile_et', 'kdc', 'hdb', 'heimntlm')
315 conf
.PROCESS_SEPARATE_RULE('system_heimdal')
317 if not conf
.CONFIG_GET('KRB5_VENDOR'):
318 conf
.PROCESS_SEPARATE_RULE('embedded_heimdal')
320 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
321 conf
.RECURSE('source4/ntvfs/sysdep')
322 conf
.RECURSE('lib/util')
323 conf
.RECURSE('lib/util/charset')
324 conf
.RECURSE('source4/auth')
325 conf
.RECURSE('nsswitch')
326 conf
.RECURSE('libcli/smbreadline')
328 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
329 if not (Options
.options
.without_ad_dc
):
330 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
331 conf
.RECURSE('testsuite/unittests')
333 if Options
.options
.with_pthreadpool
:
334 if conf
.CONFIG_SET('HAVE_PTHREAD'):
335 conf
.DEFINE('WITH_PTHREADPOOL', '1')
337 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
338 conf
.undefine('WITH_PTHREADPOOL')
340 conf
.SET_TARGET_TYPE('jansson', 'EMPTY')
342 if Options
.options
.with_json
is not False:
343 if conf
.CHECK_CFG(package
='jansson', args
='--cflags --libs',
344 msg
='Checking for jansson'):
345 conf
.CHECK_FUNCS_IN('json_object', 'jansson')
347 if not conf
.CONFIG_GET('HAVE_JSON_OBJECT'):
348 if Options
.options
.with_json
is not False:
349 conf
.fatal("Jansson JSON support not found. "
350 "Try installing libjansson-dev or jansson-devel. "
351 "Otherwise, use --without-json to build without "
353 "JSON support is required for the JSON "
354 "formatted audit log feature, the AD DC, and "
355 "the JSON printers of the net utility")
356 if not Options
.options
.without_ad_dc
:
357 raise Errors
.WafError('--without-json requires --without-ad-dc. '
358 'Jansson JSON library is required for '
359 'building the AD DC')
360 Logs
.info("Building without Jansson JSON log support")
362 conf
.RECURSE('source3')
363 conf
.RECURSE('lib/texpect')
364 conf
.RECURSE('lib/tsocket')
365 conf
.RECURSE('python')
366 if conf
.env
.with_ctdb
:
368 conf
.RECURSE('lib/socket')
369 conf
.RECURSE('lib/mscat')
370 conf
.RECURSE('packaging')
371 conf
.RECURSE('lib/krb5_wrap')
373 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
375 # gentoo always adds this. We want our normal build to be as
376 # strict as the strictest OS we support, so adding this here
377 # allows us to find problems on our development hosts faster.
378 # It also results in faster load time.
380 if (not Options
.options
.address_sanitizer
381 and conf
.CHECK_LDFLAGS('-Wl,--as-needed')):
382 conf
.env
.append_unique('LINKFLAGS', '-Wl,--as-needed')
384 if not conf
.CHECK_NEED_LC("-lc not needed"):
385 conf
.ADD_LDFLAGS('-lc', testflags
=False)
387 if not conf
.CHECK_CODE('#include "tests/summary.c"',
388 define
='SUMMARY_PASSES',
390 msg
='Checking configure summary'):
391 raise Errors
.WafError('configure summary failed')
393 if Options
.options
.enable_pie
is not False:
394 if Options
.options
.enable_pie
is True:
397 # not specified, only build PIEs if supported by compiler
399 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
400 msg
="Checking compiler for PIE support"):
401 conf
.env
['ENABLE_PIE'] = True
403 if Options
.options
.enable_relro
is not False:
404 if Options
.options
.enable_relro
is True:
407 # not specified, only build RELROs if supported by compiler
409 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
410 msg
="Checking compiler for full RELRO support"):
411 conf
.env
['ENABLE_RELRO'] = True
413 if conf
.CONFIG_GET('ENABLE_SELFTEST') and \
414 Options
.options
.with_smb1server
is False and \
415 Options
.options
.without_ad_dc
is not True:
416 conf
.fatal('--without-smb1-server cannot be specified with '
417 '--enable-selftest/--enable-developer if '
418 '--without-ad-dc is NOT set!')
420 if Options
.options
.with_smb1server
is not False:
421 conf
.DEFINE('WITH_SMB1SERVER', '1')
424 # FreeBSD is broken. It doesn't include 'extern char **environ'
425 # in any shared library, but statically inside crt0.o.
427 # If we're running on a FreeBSD with the GNU linker ld we
428 # can get around this by explicitly telling the linker to
429 # ignore 'environ' as an unresolved symbol in a shared library.
431 # However, the clang linker ld.lld-XX is broken in that it
432 # doesn't have that option.
434 # First try to see if have '-Wl,--ignore-unresolved-symbol,environ'
435 # and just use that if so.
437 # If not, we have to use '-Wl,--allow-shlib-undefined' instead
438 # and remove all instances of '-Wl,-no-undefined'.
440 if sys
.platform
.startswith('freebsd'):
441 # Do we have Wl,--ignore-unresolved-symbol,environ ?
442 flag_added
= conf
.ADD_LDFLAGS('-Wl,--ignore-unresolved-symbol,environ', testflags
=True)
444 # No, fall back to -Wl,--allow-shlib-undefined.
445 conf
.ADD_LDFLAGS('-Wl,--allow-shlib-undefined', testflags
=True)
446 # Remove any uses of '-Wl,-no-undefined'
447 conf
.env
['EXTRA_LDFLAGS'] = list(filter(('-Wl,-no-undefined').__ne
__, conf
.env
['EXTRA_LDFLAGS']))
448 # And make sure we don't try and remove it again when 'allow_undefined_symbols=true'
449 conf
.env
.undefined_ldflags
= []
451 conf
.SAMBA_CONFIG_H('include/config.h')
454 '''build TAGS file using etags'''
455 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
456 cmd
= r
'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
457 print("Running: %s" % cmd
)
458 status
= os
.system(cmd
)
459 if os
.WEXITSTATUS(status
):
460 raise Errors
.WafError('etags failed')
463 "build 'tags' file using ctags"
464 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
465 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
)
466 print("Running: %s" % cmd
)
467 status
= os
.system(cmd
)
468 if os
.WEXITSTATUS(status
):
469 raise Errors
.WafError('ctags failed')
472 # putting this here enabled build in the list
473 # of commands in --help
475 '''build all targets'''
476 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
480 '''run pep8 validator'''
481 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
482 print("Running: %s" % cmd
)
483 status
= os
.system(cmd
)
484 if os
.WEXITSTATUS(status
):
485 raise Errors
.WafError('pep8 failed')
489 '''makes a tarball for distribution'''
490 sambaversion
= samba_version
.load_version(env
=None)
492 os
.system("make -C ctdb manpages")
493 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
495 os
.system("DOC_VERSION='" + sambaversion
.STRING
+ "' " + Context
.g_module
.top
+ "/release-scripts/build-manpages-nogit")
496 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
498 if sambaversion
.IS_SNAPSHOT
:
499 # write .distversion file and add to tar
500 if not os
.path
.isdir(Context
.g_module
.out
):
501 os
.makedirs(Context
.g_module
.out
)
502 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=Context
.g_module
.out
)
503 for field
in sambaversion
.vcs_fields
:
504 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
505 distversionf
.write(distveroption
+ '\n')
507 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
516 '''test that distribution tarball builds and installs'''
517 samba_version
.load_version(env
=None)
519 def printversion(ctx
):
521 ver
= samba_version
.load_version(env
=None)
522 print('Samba Version: ' + ver
.STRING_WITH_NICKNAME
)
524 def wildcard_cmd(cmd
):
525 '''called on a unknown command'''
526 from samba_wildcard
import run_named_build_task
527 run_named_build_task(cmd
)
530 from samba_wildcard
import wildcard_main
532 wildcard_main(wildcard_cmd
)
533 Scripting
.main
= main
535 def reconfigure(ctx
):
536 '''reconfigure if config scripts have changed'''
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'")