VERSION: Bump version up to 4.9.4.
[Samba.git] / wscript
blob7c265e7befb36472e2b73f80f21e7b3f3bd168d5
1 #!/usr/bin/env python
3 srcdir = '.'
4 blddir = 'bin'
6 APPNAME='samba'
7 VERSION=None
9 import sys, os, tempfile
10 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
11 import wafsamba, Options, samba_dist, samba_git, Scripting, Utils, samba_version
12 import Logs, samba_utils
13 import shutil
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)
25 value = []
26 for arg in parser.rargs:
27 # stop on --foo like options
28 if arg[:2] == "--" and len(arg) > 2:
29 break
30 value.append(arg)
31 if len(value)>0:
32 del parser.rargs[:len(value)]
33 setattr(parser.values, option.dest, value)
35 def set_options(opt):
36 opt.BUILTIN_DEFAULT('NONE')
37 opt.PRIVATE_EXTENSION_DEFAULT('samba4')
38 opt.RECURSE('lib/audit_logging')
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/lib/tls')
45 opt.RECURSE('source4/dsdb/samdb/ldb_modules')
46 opt.RECURSE('pidl')
47 opt.RECURSE('source3')
48 opt.RECURSE('lib/util')
49 opt.RECURSE('lib/crypto')
50 opt.RECURSE('ctdb')
53 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
55 opt.add_option('--with-system-mitkrb5',
56 help='build Samba with system MIT Kerberos. ' +
57 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
58 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
60 opt.add_option('--with-experimental-mit-ad-dc',
61 help='Enable the experimental MIT Kerberos-backed AD DC. ' +
62 'Note that security patches are not issued for this configuration',
63 action='store_true',
64 dest='with_experimental_mit_ad_dc',
65 default=False)
67 opt.add_option('--with-system-mitkdc',
68 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
69 type="string",
70 dest='with_system_mitkdc',
71 default=None)
73 opt.add_option('--with-system-heimdalkrb5',
74 help=('build Samba with system Heimdal Kerberos. ' +
75 'Requires --without-ad-dc' and
76 'conflicts with --with-system-mitkrb5'),
77 action='store_true',
78 dest='with_system_heimdalkrb5',
79 default=False)
81 opt.add_option('--without-ad-dc',
82 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
83 action='store_true', dest='without_ad_dc', default=False)
85 opt.add_option('--with-ntvfs-fileserver',
86 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',
87 action='store_true', dest='with_ntvfs_fileserver')
89 opt.add_option('--without-ntvfs-fileserver',
90 help='disable the deprecated NTVFS file server from the original Samba4 branch',
91 action='store_false', dest='with_ntvfs_fileserver')
93 opt.add_option('--with-pie',
94 help=("Build Position Independent Executables " +
95 "(default if supported by compiler)"),
96 action="store_true", dest='enable_pie')
97 opt.add_option('--without-pie',
98 help=("Disable Position Independent Executable builds"),
99 action="store_false", dest='enable_pie')
101 opt.add_option('--with-relro',
102 help=("Build with full RELocation Read-Only (RELRO)" +
103 "(default if supported by compiler)"),
104 action="store_true", dest='enable_relro')
105 opt.add_option('--without-relro',
106 help=("Disable RELRO builds"),
107 action="store_false", dest='enable_relro')
109 gr = opt.option_group('developer options')
111 opt.tool_options('python') # options for disabling pyc or pyo compilation
112 # enable options related to building python extensions
115 def configure(conf):
116 version = samba_version.load_version(env=conf.env)
118 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
119 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
120 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
122 if Options.options.developer:
123 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
124 conf.env.DEVELOPER = True
125 # if we are in a git tree without a pre-commit hook, install a
126 # simple default.
127 pre_commit_hook = os.path.join(srcdir, '.git/hooks/pre-commit')
128 if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
129 not os.path.exists(pre_commit_hook)):
130 shutil.copy(os.path.join(srcdir, 'script/git-hooks/pre-commit-hook'),
131 pre_commit_hook)
133 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
135 conf.env.replace_add_global_pthread = True
136 conf.RECURSE('lib/replace')
138 conf.RECURSE('examples/fuse')
140 conf.SAMBA_CHECK_PERL(mandatory=True)
141 conf.find_program('xsltproc', var='XSLTPROC')
143 if conf.env.disable_python:
144 if not (Options.options.without_ad_dc):
145 raise Utils.WafError('--disable-python requires --without-ad-dc')
147 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
148 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
150 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
151 # Mac OSX needs to have this and it's also needed that the python is compiled with this
152 # otherwise you face errors about common symbols
153 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
154 conf.ADD_CFLAGS('-fno-common')
155 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
156 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
158 if sys.platform == 'darwin':
159 conf.ADD_LDFLAGS('-framework CoreFoundation')
161 if int(conf.env['PYTHON_VERSION'][0]) >= 3:
162 raise Utils.WafError('Python version 3.x is not supported by Samba yet')
164 conf.RECURSE('dynconfig')
165 conf.RECURSE('selftest')
167 if conf.CHECK_FOR_THIRD_PARTY():
168 conf.RECURSE('third_party')
169 else:
170 if not conf.CHECK_ZLIB():
171 raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
172 else:
173 conf.define('USING_SYSTEM_ZLIB',1)
175 if not conf.CHECK_POPT():
176 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
177 else:
178 conf.define('USING_SYSTEM_POPT', 1)
180 if not conf.CHECK_CMOCKA():
181 raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
182 else:
183 conf.define('USING_SYSTEM_CMOCKA', 1)
185 if conf.CONFIG_GET('ENABLE_SELFTEST'):
186 if not conf.CHECK_SOCKET_WRAPPER():
187 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
188 else:
189 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
191 if not conf.CHECK_NSS_WRAPPER():
192 raise Utils.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
193 else:
194 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
196 if not conf.CHECK_RESOLV_WRAPPER():
197 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
198 else:
199 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
201 if not conf.CHECK_UID_WRAPPER():
202 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
203 else:
204 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
206 if not conf.CHECK_PAM_WRAPPER():
207 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
208 else:
209 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
211 conf.RECURSE('lib/ldb')
213 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
214 conf.env['HAVE_LDWRAP'] = True
215 conf.define('HAVE_LDWRAP', 1)
217 if not (Options.options.without_ad_dc):
218 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
220 if Options.options.with_system_mitkrb5:
221 if not Options.options.with_experimental_mit_ad_dc and \
222 not Options.options.without_ad_dc:
223 raise Utils.WafError('The MIT Kerberos build of Samba as an AD DC ' +
224 'is experimental. Therefore '
225 '--with-system-mitkrb5 requires either ' +
226 '--with-experimental-mit-ad-dc or ' +
227 '--without-ad-dc')
229 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
231 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
232 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
234 if Options.options.with_system_heimdalkrb5:
235 if Options.options.with_system_mitkrb5:
236 raise Utils.WafError('--with-system-heimdalkrb5 conflicts with ' +
237 '--with-system-mitkrb5')
238 if not Options.options.without_ad_dc:
239 raise Utils.WafError('--with-system-heimdalkrb5 requires ' +
240 '--without-ad-dc')
241 conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
242 'hx509', 'wind', 'gssapi', 'hcrypto',
243 'krb5', 'heimbase', 'asn1_compile',
244 'compile_et', 'kdc', 'hdb', 'heimntlm')
246 # Only process heimdal_build for non-MIT KRB5 builds
247 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
248 # to the lowcased output of 'krb5-config --vendor'.
249 # If it is not set or the output is 'heimdal', we are dealing with
250 # system-provided or embedded Heimdal build
251 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
252 conf.RECURSE('source4/heimdal_build')
253 conf.RECURSE('lib/audit_logging')
254 conf.RECURSE('source4/lib/tls')
255 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
256 conf.RECURSE('source4/ntvfs/sysdep')
257 conf.RECURSE('lib/util')
258 conf.RECURSE('lib/util/charset')
259 conf.RECURSE('source4/auth')
260 conf.RECURSE('nsswitch')
261 conf.RECURSE('libcli/smbreadline')
262 conf.RECURSE('lib/crypto')
263 conf.RECURSE('pidl')
264 if conf.CONFIG_GET('ENABLE_SELFTEST'):
265 if Options.options.with_ntvfs_fileserver != False:
266 if not (Options.options.without_ad_dc):
267 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
268 if Options.options.with_ntvfs_fileserver == False:
269 if not (Options.options.without_ad_dc):
270 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
271 conf.RECURSE('testsuite/unittests')
273 if Options.options.with_ntvfs_fileserver == True:
274 if Options.options.without_ad_dc:
275 raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
276 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
278 if Options.options.with_pthreadpool:
279 if conf.CONFIG_SET('HAVE_PTHREAD'):
280 conf.DEFINE('WITH_PTHREADPOOL', '1')
281 else:
282 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
283 conf.undefine('WITH_PTHREADPOOL')
285 conf.RECURSE('source3')
286 conf.RECURSE('lib/texpect')
287 conf.RECURSE('python')
288 if conf.env.with_ctdb:
289 conf.RECURSE('ctdb')
290 conf.RECURSE('lib/socket')
291 conf.RECURSE('packaging')
293 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
295 # gentoo always adds this. We want our normal build to be as
296 # strict as the strictest OS we support, so adding this here
297 # allows us to find problems on our development hosts faster.
298 # It also results in faster load time.
300 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
302 if not conf.CHECK_NEED_LC("-lc not needed"):
303 conf.ADD_LDFLAGS('-lc', testflags=False)
305 if not conf.CHECK_CODE('#include "tests/summary.c"',
306 define='SUMMARY_PASSES',
307 addmain=False,
308 msg='Checking configure summary'):
309 raise Utils.WafError('configure summary failed')
311 if Options.options.enable_pie != False:
312 if Options.options.enable_pie == True:
313 need_pie = True
314 else:
315 # not specified, only build PIEs if supported by compiler
316 need_pie = False
317 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
318 msg="Checking compiler for PIE support"):
319 conf.env['ENABLE_PIE'] = True
321 if Options.options.enable_relro != False:
322 if Options.options.enable_relro == True:
323 need_relro = True
324 else:
325 # not specified, only build RELROs if supported by compiler
326 need_relro = False
327 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
328 msg="Checking compiler for full RELRO support"):
329 conf.env['ENABLE_RELRO'] = True
331 conf.SAMBA_CONFIG_H('include/config.h')
333 def etags(ctx):
334 '''build TAGS file using etags'''
335 import Utils
336 source_root = os.path.dirname(Utils.g_module.root_path)
337 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
338 print("Running: %s" % cmd)
339 status = os.system(cmd)
340 if os.WEXITSTATUS(status):
341 raise Utils.WafError('etags failed')
343 def ctags(ctx):
344 "build 'tags' file using ctags"
345 import Utils
346 source_root = os.path.dirname(Utils.g_module.root_path)
347 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
348 print("Running: %s" % cmd)
349 status = os.system(cmd)
350 if os.WEXITSTATUS(status):
351 raise Utils.WafError('ctags failed')
354 # putting this here enabled build in the list
355 # of commands in --help
356 def build(bld):
357 '''build all targets'''
358 samba_version.load_version(env=bld.env, is_install=bld.is_install)
361 def pydoctor(ctx):
362 '''build python apidocs'''
363 bp = os.path.abspath('bin/python')
364 mpaths = {}
365 modules = ['talloc', 'tdb', 'ldb']
366 for m in modules:
367 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
368 try:
369 mpaths[m] = f.read().strip()
370 finally:
371 f.close()
372 mpaths['main'] = bp
373 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
374 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
375 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
376 cmd = cmd % mpaths
377 print("Running: %s" % cmd)
378 status = os.system(cmd)
379 if os.WEXITSTATUS(status):
380 raise Utils.WafError('pydoctor failed')
383 def pep8(ctx):
384 '''run pep8 validator'''
385 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
386 print("Running: %s" % cmd)
387 status = os.system(cmd)
388 if os.WEXITSTATUS(status):
389 raise Utils.WafError('pep8 failed')
392 def wafdocs(ctx):
393 '''build wafsamba apidocs'''
394 from samba_utils import recursive_dirlist
395 os.system('pwd')
396 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
398 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
399 print(list)
400 for f in list:
401 cmd += ' --add-module %s' % f
402 print("Running: %s" % cmd)
403 status = os.system(cmd)
404 if os.WEXITSTATUS(status):
405 raise Utils.WafError('wafdocs failed')
408 def dist():
409 '''makes a tarball for distribution'''
410 sambaversion = samba_version.load_version(env=None)
412 os.system("make -C ctdb manpages")
413 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
415 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
416 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
418 if sambaversion.IS_SNAPSHOT:
419 # write .distversion file and add to tar
420 if not os.path.isdir(blddir):
421 os.makedirs(blddir)
422 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
423 for field in sambaversion.vcs_fields:
424 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
425 distversionf.write(distveroption + '\n')
426 distversionf.flush()
427 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
429 samba_dist.dist()
430 distversionf.close()
431 else:
432 samba_dist.dist()
435 def distcheck():
436 '''test that distribution tarball builds and installs'''
437 samba_version.load_version(env=None)
438 import Scripting
439 d = Scripting.distcheck
442 def wildcard_cmd(cmd):
443 '''called on a unknown command'''
444 from samba_wildcard import run_named_build_task
445 run_named_build_task(cmd)
447 def main():
448 from samba_wildcard import wildcard_main
450 wildcard_main(wildcard_cmd)
451 Scripting.main = main
453 def reconfigure(ctx):
454 '''reconfigure if config scripts have changed'''
455 import samba_utils
456 samba_utils.reconfigure(ctx)
459 if os.path.isdir(os.path.join(srcdir, ".git")):
460 # Check if there are submodules that are checked out but out of date.
461 for submodule, status in samba_git.read_submodule_status(srcdir):
462 if status == "out-of-date":
463 raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")