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')
48 opt
.RECURSE('lib/crypto')
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',
82 dest
='with_experimental_mit_ad_dc',
85 opt
.add_option('--with-system-mitkdc',
86 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
88 dest
='with_system_mitkdc',
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'),
96 dest
='with_system_heimdalkrb5',
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 opt
.samba_add_onoff_option('smb1-server',
133 dest
='with_smb1server',
134 help=("Build smbd with SMB1 support (default=yes)."))
137 version
= samba_version
.load_version(env
=conf
.env
)
139 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
140 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
141 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
143 if Options
.options
.developer
:
144 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
145 conf
.env
.DEVELOPER
= True
146 # if we are in a git tree without a pre-commit hook, install a
148 # we need git for 'waf dist'
150 conf
.find_program('git', var
='GIT')
151 if 'GIT' in conf
.env
:
152 githooksdir
= conf
.CHECK_COMMAND('%s rev-parse --git-path hooks' % conf
.env
.GIT
[0],
153 msg
='Finding githooks directory',
156 if githooksdir
and os
.path
.isdir(githooksdir
):
157 pre_commit_hook
= os
.path
.join(githooksdir
, 'pre-commit')
158 if not os
.path
.exists(pre_commit_hook
):
159 Logs
.info("Installing script/git-hooks/pre-commit-hook as %s" %
161 shutil
.copy(os
.path
.join(Context
.g_module
.top
, 'script/git-hooks/pre-commit-hook'),
164 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
166 conf
.env
.replace_add_global_pthread
= True
167 conf
.RECURSE('lib/replace')
169 conf
.RECURSE('examples/fuse')
170 conf
.RECURSE('examples/winexe')
172 conf
.SAMBA_CHECK_PERL(mandatory
=True)
173 conf
.find_program('xsltproc', var
='XSLTPROC')
175 if conf
.env
.disable_python
:
176 if not (Options
.options
.without_ad_dc
):
177 raise Errors
.WafError('--disable-python requires --without-ad-dc')
179 conf
.SAMBA_CHECK_PYTHON()
180 conf
.SAMBA_CHECK_PYTHON_HEADERS()
182 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
183 # Mac OSX needs to have this and it's also needed that the python is compiled with this
184 # otherwise you face errors about common symbols
185 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
186 conf
.ADD_CFLAGS('-fno-common')
187 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
188 conf
.env
.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
190 if sys
.platform
== 'darwin':
191 conf
.ADD_LDFLAGS('-framework CoreFoundation')
193 conf
.RECURSE('dynconfig')
194 conf
.RECURSE('selftest')
196 conf
.PROCESS_SEPARATE_RULE('system_gnutls')
198 conf
.CHECK_CFG(package
='zlib', minversion
='1.2.3',
199 args
='--cflags --libs',
201 conf
.CHECK_FUNCS_IN('inflateInit2', 'z')
203 if conf
.CHECK_FOR_THIRD_PARTY():
204 conf
.RECURSE('third_party')
207 if not conf
.CHECK_POPT():
208 raise Errors
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
210 conf
.define('USING_SYSTEM_POPT', 1)
212 if not conf
.CHECK_CMOCKA():
213 raise Errors
.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
215 conf
.define('USING_SYSTEM_CMOCKA', 1)
217 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
218 if not conf
.CHECK_SOCKET_WRAPPER():
219 raise Errors
.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
221 conf
.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
223 if not conf
.CHECK_NSS_WRAPPER():
224 raise Errors
.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
226 conf
.define('USING_SYSTEM_NSS_WRAPPER', 1)
228 if not conf
.CHECK_RESOLV_WRAPPER():
229 raise Errors
.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
231 conf
.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
233 if not conf
.CHECK_UID_WRAPPER():
234 raise Errors
.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
236 conf
.define('USING_SYSTEM_UID_WRAPPER', 1)
238 if not conf
.CHECK_PAM_WRAPPER():
239 raise Errors
.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
241 conf
.define('USING_SYSTEM_PAM_WRAPPER', 1)
243 conf
.RECURSE('lib/ldb')
245 if conf
.CHECK_LDFLAGS(['-Wl,--wrap=test']):
246 conf
.env
['HAVE_LDWRAP'] = True
247 conf
.define('HAVE_LDWRAP', 1)
249 if not (Options
.options
.without_ad_dc
):
250 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
252 # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
253 Logs
.info("Checking for flex")
254 conf
.find_program('flex', var
='FLEX')
256 conf
.CHECK_COMMAND('%s --version' % conf
.env
.FLEX
[0],
257 msg
='Using flex version',
260 conf
.env
.FLEXFLAGS
= ['-t']
262 # #line statements in these generated files cause issues for lcov
263 conf
.env
.FLEXFLAGS
+= ["--noline"]
265 Logs
.info("Checking for bison")
266 bison
.configure(conf
)
267 if conf
.env
['BISON']:
268 conf
.CHECK_COMMAND('%s --version | head -n1' % conf
.env
.BISON
[0],
269 msg
='Using bison version',
273 # #line statements in these generated files cause issues for lcov
274 conf
.env
.BISONFLAGS
+= ["--no-line"]
276 if Options
.options
.with_system_mitkrb5
:
277 if not Options
.options
.with_experimental_mit_ad_dc
and \
278 not Options
.options
.without_ad_dc
:
279 raise Errors
.WafError('The MIT Kerberos build of Samba as an AD DC ' +
280 'is experimental. Therefore '
281 '--with-system-mitkrb5 requires either ' +
282 '--with-experimental-mit-ad-dc or ' +
285 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
287 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
288 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
290 if Options
.options
.with_system_heimdalkrb5
:
291 if Options
.options
.with_system_mitkrb5
:
292 raise Errors
.WafError('--with-system-heimdalkrb5 conflicts with ' +
293 '--with-system-mitkrb5')
294 if not Options
.options
.without_ad_dc
:
295 raise Errors
.WafError('--with-system-heimdalkrb5 requires ' +
297 conf
.env
.SYSTEM_LIBS
+= ('heimdal', 'asn1', 'com_err', 'roken',
298 'hx509', 'wind', 'gssapi', 'hcrypto',
299 'krb5', 'heimbase', 'asn1_compile',
300 'compile_et', 'kdc', 'hdb', 'heimntlm')
301 conf
.PROCESS_SEPARATE_RULE('system_heimdal')
303 if not conf
.CONFIG_GET('KRB5_VENDOR'):
304 conf
.PROCESS_SEPARATE_RULE('embedded_heimdal')
306 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
307 conf
.RECURSE('source4/ntvfs/sysdep')
308 conf
.RECURSE('lib/util')
309 conf
.RECURSE('lib/util/charset')
310 conf
.RECURSE('source4/auth')
311 conf
.RECURSE('nsswitch')
312 conf
.RECURSE('libcli/smbreadline')
313 conf
.RECURSE('lib/crypto')
315 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
316 if not (Options
.options
.without_ad_dc
):
317 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
318 conf
.RECURSE('testsuite/unittests')
320 if Options
.options
.with_pthreadpool
:
321 if conf
.CONFIG_SET('HAVE_PTHREAD'):
322 conf
.DEFINE('WITH_PTHREADPOOL', '1')
324 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
325 conf
.undefine('WITH_PTHREADPOOL')
327 conf
.SET_TARGET_TYPE('jansson', 'EMPTY')
329 if Options
.options
.with_json
!= False:
330 if conf
.CHECK_CFG(package
='jansson', args
='--cflags --libs',
331 msg
='Checking for jansson'):
332 conf
.CHECK_FUNCS_IN('json_object', 'jansson')
334 if not conf
.CONFIG_GET('HAVE_JSON_OBJECT'):
335 if Options
.options
.with_json
!= False:
336 conf
.fatal("Jansson JSON support not found. "
337 "Try installing libjansson-dev or jansson-devel. "
338 "Otherwise, use --without-json to build without "
340 "JSON support is required for the JSON "
341 "formatted audit log feature, the AD DC, and "
342 "the JSON printers of the net utility")
343 if not Options
.options
.without_ad_dc
:
344 raise Errors
.WafError('--without-json requires --without-ad-dc. '
345 'Jansson JSON library is required for '
346 'building the AD DC')
347 Logs
.info("Building without Jansson JSON log support")
349 conf
.RECURSE('source3')
350 conf
.RECURSE('lib/texpect')
351 conf
.RECURSE('python')
352 if conf
.env
.with_ctdb
:
354 conf
.RECURSE('lib/socket')
355 conf
.RECURSE('lib/mscat')
356 conf
.RECURSE('packaging')
358 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
360 # gentoo always adds this. We want our normal build to be as
361 # strict as the strictest OS we support, so adding this here
362 # allows us to find problems on our development hosts faster.
363 # It also results in faster load time.
365 if (not Options
.options
.address_sanitizer
366 and conf
.CHECK_LDFLAGS('-Wl,--as-needed')):
367 conf
.env
.append_unique('LINKFLAGS', '-Wl,--as-needed')
369 if not conf
.CHECK_NEED_LC("-lc not needed"):
370 conf
.ADD_LDFLAGS('-lc', testflags
=False)
372 if not conf
.CHECK_CODE('#include "tests/summary.c"',
373 define
='SUMMARY_PASSES',
375 msg
='Checking configure summary'):
376 raise Errors
.WafError('configure summary failed')
378 if Options
.options
.enable_pie
!= False:
379 if Options
.options
.enable_pie
== True:
382 # not specified, only build PIEs if supported by compiler
384 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
385 msg
="Checking compiler for PIE support"):
386 conf
.env
['ENABLE_PIE'] = True
388 if Options
.options
.enable_relro
!= False:
389 if Options
.options
.enable_relro
== True:
392 # not specified, only build RELROs if supported by compiler
394 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
395 msg
="Checking compiler for full RELRO support"):
396 conf
.env
['ENABLE_RELRO'] = True
398 if conf
.CONFIG_GET('ENABLE_SELFTEST') and \
399 Options
.options
.with_smb1server
== False and \
400 Options
.options
.without_ad_dc
!= True:
401 conf
.fatal('--without-smb1-server cannot be specified with '
402 '--enable-selftest/--enable-developer if '
403 '--without-ad-dc is NOT set!')
405 if Options
.options
.with_smb1server
!= False:
406 conf
.DEFINE('WITH_SMB1SERVER', '1')
409 # FreeBSD is broken. It doesn't include 'extern char **environ'
410 # in any shared library, but statically inside crt0.o.
412 # If we're running on a FreeBSD with the GNU linker ld we
413 # can get around this by explicitly telling the linker to
414 # ignore 'environ' as an unresolved symbol in a shared library.
416 # However, the clang linker ld.lld-XX is broken in that it
417 # doesn't have that option.
419 # First try to see if have '-Wl,--ignore-unresolved-symbol,environ'
420 # and just use that if so.
422 # If not, we have to use '-Wl,--allow-shlib-undefined' instead
423 # and remove all instances of '-Wl,-no-undefined'.
425 if sys
.platform
.startswith('freebsd'):
426 # Do we have Wl,--ignore-unresolved-symbol,environ ?
427 flag_added
= conf
.ADD_LDFLAGS('-Wl,--ignore-unresolved-symbol,environ', testflags
=True)
429 # No, fall back to -Wl,--allow-shlib-undefined.
430 conf
.ADD_LDFLAGS('-Wl,--allow-shlib-undefined', testflags
=True)
431 # Remove any uses of '-Wl,-no-undefined'
432 conf
.env
['EXTRA_LDFLAGS'] = list(filter(('-Wl,-no-undefined').__ne
__, conf
.env
['EXTRA_LDFLAGS']))
433 # And make sure we don't try and remove it again when 'allow_undefined_symbols=true'
434 conf
.env
.undefined_ldflags
= []
436 conf
.SAMBA_CONFIG_H('include/config.h')
439 '''build TAGS file using etags'''
440 from waflib
import Utils
441 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
442 cmd
= 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
443 print("Running: %s" % cmd
)
444 status
= os
.system(cmd
)
445 if os
.WEXITSTATUS(status
):
446 raise Errors
.WafError('etags failed')
449 "build 'tags' file using ctags"
450 from waflib
import Utils
451 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
452 cmd
= 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root
, source_root
)
453 print("Running: %s" % cmd
)
454 status
= os
.system(cmd
)
455 if os
.WEXITSTATUS(status
):
456 raise Errors
.WafError('ctags failed')
459 # putting this here enabled build in the list
460 # of commands in --help
462 '''build all targets'''
463 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
467 '''build python apidocs'''
468 bp
= os
.path
.abspath('bin/python')
470 modules
= ['talloc', 'tdb', 'ldb']
472 f
= os
.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp
, m
, m
), 'r')
474 mpaths
[m
] = f
.read().strip()
478 cmd
= ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
479 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
480 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n
for n
in modules
))
482 print("Running: %s" % cmd
)
483 status
= os
.system(cmd
)
484 if os
.WEXITSTATUS(status
):
485 raise Errors
.WafError('pydoctor failed')
489 '''run pep8 validator'''
490 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
491 print("Running: %s" % cmd
)
492 status
= os
.system(cmd
)
493 if os
.WEXITSTATUS(status
):
494 raise Errors
.WafError('pep8 failed')
498 '''build wafsamba apidocs'''
499 from samba_utils
import recursive_dirlist
501 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern
='*.py')
504 cmd
='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext' +\
505 "".join(' --add-module %s' % f
for f
in list)
506 print("Running: %s" % cmd
)
507 status
= os
.system(cmd
)
508 if os
.WEXITSTATUS(status
):
509 raise Errors
.WafError('wafdocs failed')
513 '''makes a tarball for distribution'''
514 sambaversion
= samba_version
.load_version(env
=None)
516 os
.system("make -C ctdb manpages")
517 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
519 os
.system("DOC_VERSION='" + sambaversion
.STRING
+ "' " + Context
.g_module
.top
+ "/release-scripts/build-manpages-nogit")
520 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
522 if sambaversion
.IS_SNAPSHOT
:
523 # write .distversion file and add to tar
524 if not os
.path
.isdir(Context
.g_module
.out
):
525 os
.makedirs(Context
.g_module
.out
)
526 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=Context
.g_module
.out
)
527 for field
in sambaversion
.vcs_fields
:
528 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
529 distversionf
.write(distveroption
+ '\n')
531 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
540 '''test that distribution tarball builds and installs'''
541 samba_version
.load_version(env
=None)
543 def wildcard_cmd(cmd
):
544 '''called on a unknown command'''
545 from samba_wildcard
import run_named_build_task
546 run_named_build_task(cmd
)
549 from samba_wildcard
import wildcard_main
551 wildcard_main(wildcard_cmd
)
552 Scripting
.main
= main
554 def reconfigure(ctx
):
555 '''reconfigure if config scripts have changed'''
557 samba_utils
.reconfigure(ctx
)
560 if os
.path
.isdir(os
.path
.join(top
, ".git")):
561 # Check if there are submodules that are checked out but out of date.
562 for submodule
, status
in samba_git
.read_submodule_status(top
):
563 if status
== "out-of-date":
564 raise Errors
.WafError("some submodules are out of date. Please run 'git submodule update'")