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
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)
26 for arg
in parser
.rargs
:
27 # stop on --foo like options
28 if arg
[:2] == "--" and len(arg
) > 2:
32 del parser
.rargs
[:len(value
)]
33 setattr(parser
.values
, option
.dest
, value
)
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')
45 opt
.RECURSE('source3')
46 opt
.RECURSE('lib/util')
47 opt
.RECURSE('lib/crypto')
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-ntvfs-fileserver',
103 help='enable the deprecated NTVFS file server from the original Samba4 branch (default if --enable-selftest specified). Conflicts with --with-system-mitkrb5 and --without-ad-dc',
104 action
='store_true', dest
='with_ntvfs_fileserver')
106 opt
.add_option('--without-ntvfs-fileserver',
107 help='disable the deprecated NTVFS file server from the original Samba4 branch',
108 action
='store_false', dest
='with_ntvfs_fileserver')
110 opt
.add_option('--with-pie',
111 help=("Build Position Independent Executables " +
112 "(default if supported by compiler)"),
113 action
="store_true", dest
='enable_pie')
114 opt
.add_option('--without-pie',
115 help=("Disable Position Independent Executable builds"),
116 action
="store_false", dest
='enable_pie')
118 opt
.add_option('--with-relro',
119 help=("Build with full RELocation Read-Only (RELRO)" +
120 "(default if supported by compiler)"),
121 action
="store_true", dest
='enable_relro')
122 opt
.add_option('--without-relro',
123 help=("Disable RELRO builds"),
124 action
="store_false", dest
='enable_relro')
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."))
140 version
= samba_version
.load_version(env
=conf
.env
)
142 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
143 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
144 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
146 if Options
.options
.developer
:
147 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
148 conf
.env
.DEVELOPER
= True
149 # if we are in a git tree without a pre-commit hook, install a
151 pre_commit_hook
= os
.path
.join(Context
.g_module
.top
, '.git/hooks/pre-commit')
152 if (os
.path
.isdir(os
.path
.dirname(pre_commit_hook
)) and
153 not os
.path
.exists(pre_commit_hook
)):
154 shutil
.copy(os
.path
.join(Context
.g_module
.top
, 'script/git-hooks/pre-commit-hook'),
157 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
159 conf
.env
.replace_add_global_pthread
= True
160 conf
.RECURSE('lib/replace')
162 conf
.RECURSE('examples/fuse')
163 conf
.RECURSE('examples/winexe')
165 conf
.SAMBA_CHECK_PERL(mandatory
=True)
166 conf
.find_program('xsltproc', var
='XSLTPROC')
168 if conf
.env
.disable_python
:
169 if not (Options
.options
.without_ad_dc
):
170 raise Errors
.WafError('--disable-python requires --without-ad-dc')
172 conf
.SAMBA_CHECK_PYTHON()
173 conf
.SAMBA_CHECK_PYTHON_HEADERS()
175 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
176 # Mac OSX needs to have this and it's also needed that the python is compiled with this
177 # otherwise you face errors about common symbols
178 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
179 conf
.ADD_CFLAGS('-fno-common')
180 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
181 conf
.env
.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
183 if sys
.platform
== 'darwin':
184 conf
.ADD_LDFLAGS('-framework CoreFoundation')
186 conf
.RECURSE('dynconfig')
187 conf
.RECURSE('selftest')
189 conf
.CHECK_CFG(package
='zlib', minversion
='1.2.3',
190 args
='--cflags --libs',
192 conf
.CHECK_FUNCS_IN('inflateInit2', 'z')
194 if conf
.CHECK_FOR_THIRD_PARTY():
195 conf
.RECURSE('third_party')
198 if not conf
.CHECK_POPT():
199 raise Errors
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
201 conf
.define('USING_SYSTEM_POPT', 1)
203 if not conf
.CHECK_CMOCKA():
204 raise Errors
.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
206 conf
.define('USING_SYSTEM_CMOCKA', 1)
208 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
209 if not conf
.CHECK_SOCKET_WRAPPER():
210 raise Errors
.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
212 conf
.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
214 if not conf
.CHECK_NSS_WRAPPER():
215 raise Errors
.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
217 conf
.define('USING_SYSTEM_NSS_WRAPPER', 1)
219 if not conf
.CHECK_RESOLV_WRAPPER():
220 raise Errors
.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
222 conf
.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
224 if not conf
.CHECK_UID_WRAPPER():
225 raise Errors
.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
227 conf
.define('USING_SYSTEM_UID_WRAPPER', 1)
229 if not conf
.CHECK_PAM_WRAPPER():
230 raise Errors
.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
232 conf
.define('USING_SYSTEM_PAM_WRAPPER', 1)
234 conf
.RECURSE('lib/ldb')
236 if conf
.CHECK_LDFLAGS(['-Wl,--wrap=test']):
237 conf
.env
['HAVE_LDWRAP'] = True
238 conf
.define('HAVE_LDWRAP', 1)
240 if not (Options
.options
.without_ad_dc
):
241 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
243 if Options
.options
.with_system_mitkrb5
:
244 if not Options
.options
.with_experimental_mit_ad_dc
and \
245 not Options
.options
.without_ad_dc
:
246 raise Errors
.WafError('The MIT Kerberos build of Samba as an AD DC ' +
247 'is experimental. Therefore '
248 '--with-system-mitkrb5 requires either ' +
249 '--with-experimental-mit-ad-dc or ' +
252 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
254 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
255 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
257 if Options
.options
.with_system_heimdalkrb5
:
258 if Options
.options
.with_system_mitkrb5
:
259 raise Errors
.WafError('--with-system-heimdalkrb5 conflicts with ' +
260 '--with-system-mitkrb5')
261 if not Options
.options
.without_ad_dc
:
262 raise Errors
.WafError('--with-system-heimdalkrb5 requires ' +
264 conf
.env
.SYSTEM_LIBS
+= ('heimdal', 'asn1', 'com_err', 'roken',
265 'hx509', 'wind', 'gssapi', 'hcrypto',
266 'krb5', 'heimbase', 'asn1_compile',
267 'compile_et', 'kdc', 'hdb', 'heimntlm')
268 conf
.PROCESS_SEPARATE_RULE('system_heimdal')
270 if not conf
.CONFIG_GET('KRB5_VENDOR'):
271 conf
.PROCESS_SEPARATE_RULE('embedded_heimdal')
273 conf
.PROCESS_SEPARATE_RULE('system_gnutls')
275 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
276 conf
.RECURSE('source4/ntvfs/sysdep')
277 conf
.RECURSE('lib/util')
278 conf
.RECURSE('lib/util/charset')
279 conf
.RECURSE('source4/auth')
280 conf
.RECURSE('nsswitch')
281 conf
.RECURSE('libcli/smbreadline')
282 conf
.RECURSE('lib/crypto')
284 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
285 if Options
.options
.with_ntvfs_fileserver
!= False:
286 if not (Options
.options
.without_ad_dc
):
287 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
288 if Options
.options
.with_ntvfs_fileserver
== False:
289 if not (Options
.options
.without_ad_dc
):
290 raise Errors
.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
291 conf
.RECURSE('testsuite/unittests')
293 if Options
.options
.with_ntvfs_fileserver
== True:
294 if Options
.options
.without_ad_dc
:
295 raise Errors
.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
296 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
298 if Options
.options
.with_pthreadpool
:
299 if conf
.CONFIG_SET('HAVE_PTHREAD'):
300 conf
.DEFINE('WITH_PTHREADPOOL', '1')
302 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
303 conf
.undefine('WITH_PTHREADPOOL')
305 conf
.SET_TARGET_TYPE('jansson', 'EMPTY')
307 if Options
.options
.with_json
!= False:
308 if conf
.CHECK_CFG(package
='jansson', args
='--cflags --libs',
309 msg
='Checking for jansson'):
310 conf
.CHECK_FUNCS_IN('json_object', 'jansson')
312 if not conf
.CONFIG_GET('HAVE_JSON_OBJECT'):
313 if Options
.options
.with_json
!= False:
314 conf
.fatal("Jansson JSON support not found. "
315 "Try installing libjansson-dev or jansson-devel. "
316 "Otherwise, use --without-json to build without "
318 "JSON support is required for the JSON "
319 "formatted audit log feature, the AD DC, and "
320 "the JSON printers of the net utility")
321 if not Options
.options
.without_ad_dc
:
322 raise Errors
.WafError('--without-json requires --without-ad-dc. '
323 'Jansson JSON library is required for '
324 'building the AD DC')
325 Logs
.info("Building without Jansson JSON log support")
327 conf
.RECURSE('source3')
328 conf
.RECURSE('lib/texpect')
329 conf
.RECURSE('python')
330 if conf
.env
.with_ctdb
:
332 conf
.RECURSE('lib/socket')
333 conf
.RECURSE('lib/mscat')
334 conf
.RECURSE('packaging')
336 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
338 # gentoo always adds this. We want our normal build to be as
339 # strict as the strictest OS we support, so adding this here
340 # allows us to find problems on our development hosts faster.
341 # It also results in faster load time.
343 if conf
.CHECK_LDFLAGS('-Wl,--as-needed'):
344 conf
.env
.append_unique('LINKFLAGS', '-Wl,--as-needed')
346 if not conf
.CHECK_NEED_LC("-lc not needed"):
347 conf
.ADD_LDFLAGS('-lc', testflags
=False)
349 if not conf
.CHECK_CODE('#include "tests/summary.c"',
350 define
='SUMMARY_PASSES',
352 msg
='Checking configure summary'):
353 raise Errors
.WafError('configure summary failed')
355 if Options
.options
.enable_pie
!= False:
356 if Options
.options
.enable_pie
== True:
359 # not specified, only build PIEs if supported by compiler
361 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
362 msg
="Checking compiler for PIE support"):
363 conf
.env
['ENABLE_PIE'] = True
365 if Options
.options
.enable_relro
!= False:
366 if Options
.options
.enable_relro
== True:
369 # not specified, only build RELROs if supported by compiler
371 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
372 msg
="Checking compiler for full RELRO support"):
373 conf
.env
['ENABLE_RELRO'] = True
375 conf
.SAMBA_CONFIG_H('include/config.h')
378 '''build TAGS file using etags'''
379 from waflib
import Utils
380 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
381 cmd
= 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
382 print("Running: %s" % cmd
)
383 status
= os
.system(cmd
)
384 if os
.WEXITSTATUS(status
):
385 raise Errors
.WafError('etags failed')
388 "build 'tags' file using ctags"
389 from waflib
import Utils
390 source_root
= os
.path
.dirname(Context
.g_module
.root_path
)
391 cmd
= 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root
, source_root
)
392 print("Running: %s" % cmd
)
393 status
= os
.system(cmd
)
394 if os
.WEXITSTATUS(status
):
395 raise Errors
.WafError('ctags failed')
398 # putting this here enabled build in the list
399 # of commands in --help
401 '''build all targets'''
402 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
406 '''build python apidocs'''
407 bp
= os
.path
.abspath('bin/python')
409 modules
= ['talloc', 'tdb', 'ldb']
411 f
= os
.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp
, m
, m
), 'r')
413 mpaths
[m
] = f
.read().strip()
417 cmd
= ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
418 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
419 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n
for n
in modules
))
421 print("Running: %s" % cmd
)
422 status
= os
.system(cmd
)
423 if os
.WEXITSTATUS(status
):
424 raise Errors
.WafError('pydoctor failed')
428 '''run pep8 validator'''
429 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
430 print("Running: %s" % cmd
)
431 status
= os
.system(cmd
)
432 if os
.WEXITSTATUS(status
):
433 raise Errors
.WafError('pep8 failed')
437 '''build wafsamba apidocs'''
438 from samba_utils
import recursive_dirlist
440 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern
='*.py')
443 cmd
='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext' +\
444 "".join(' --add-module %s' % f
for f
in list)
445 print("Running: %s" % cmd
)
446 status
= os
.system(cmd
)
447 if os
.WEXITSTATUS(status
):
448 raise Errors
.WafError('wafdocs failed')
452 '''makes a tarball for distribution'''
453 sambaversion
= samba_version
.load_version(env
=None)
455 os
.system("make -C ctdb manpages")
456 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
458 os
.system("DOC_VERSION='" + sambaversion
.STRING
+ "' " + Context
.g_module
.top
+ "/release-scripts/build-manpages-nogit")
459 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
461 if sambaversion
.IS_SNAPSHOT
:
462 # write .distversion file and add to tar
463 if not os
.path
.isdir(Context
.g_module
.out
):
464 os
.makedirs(Context
.g_module
.out
)
465 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=Context
.g_module
.out
)
466 for field
in sambaversion
.vcs_fields
:
467 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
468 distversionf
.write(distveroption
+ '\n')
470 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
479 '''test that distribution tarball builds and installs'''
480 samba_version
.load_version(env
=None)
482 def wildcard_cmd(cmd
):
483 '''called on a unknown command'''
484 from samba_wildcard
import run_named_build_task
485 run_named_build_task(cmd
)
488 from samba_wildcard
import wildcard_main
490 wildcard_main(wildcard_cmd
)
491 Scripting
.main
= main
493 def reconfigure(ctx
):
494 '''reconfigure if config scripts have changed'''
496 samba_utils
.reconfigure(ctx
)
499 if os
.path
.isdir(os
.path
.join(top
, ".git")):
500 # Check if there are submodules that are checked out but out of date.
501 for submodule
, status
in samba_git
.read_submodule_status(top
):
502 if status
== "out-of-date":
503 raise Errors
.WafError("some submodules are out of date. Please run 'git submodule update'")