VERSION: Disable GIT_SNAPSHOT for the 4.8.9 release.
[Samba.git] / wscript
blobff628df37e72fe272b4fe7e6473ecda9fa65f4a5
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
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/replace')
39 opt.RECURSE('dynconfig')
40 opt.RECURSE('packaging')
41 opt.RECURSE('lib/ldb')
42 opt.RECURSE('selftest')
43 opt.RECURSE('source4/lib/tls')
44 opt.RECURSE('source4/dsdb/samdb/ldb_modules')
45 opt.RECURSE('pidl')
46 opt.RECURSE('source3')
47 opt.RECURSE('lib/util')
48 opt.RECURSE('lib/crypto')
49 opt.RECURSE('ctdb')
52 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
54 opt.add_option('--with-system-mitkrb5',
55 help='build Samba with system MIT Kerberos. ' +
56 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
57 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
59 opt.add_option('--with-experimental-mit-ad-dc',
60 help='Enable the experimental MIT Kerberos-backed AD DC. ' +
61 'Note that security patches are not issued for this configuration',
62 action='store_true',
63 dest='with_experimental_mit_ad_dc',
64 default=False)
66 opt.add_option('--with-system-mitkdc',
67 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
68 type="string",
69 dest='with_system_mitkdc',
70 default=None)
72 opt.add_option('--without-ad-dc',
73 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
74 action='store_true', dest='without_ad_dc', default=False)
76 opt.add_option('--with-ntvfs-fileserver',
77 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',
78 action='store_true', dest='with_ntvfs_fileserver')
80 opt.add_option('--without-ntvfs-fileserver',
81 help='disable the deprecated NTVFS file server from the original Samba4 branch',
82 action='store_false', dest='with_ntvfs_fileserver')
84 opt.add_option('--with-pie',
85 help=("Build Position Independent Executables " +
86 "(default if supported by compiler)"),
87 action="store_true", dest='enable_pie')
88 opt.add_option('--without-pie',
89 help=("Disable Position Independent Executable builds"),
90 action="store_false", dest='enable_pie')
92 opt.add_option('--with-relro',
93 help=("Build with full RELocation Read-Only (RELRO)" +
94 "(default if supported by compiler)"),
95 action="store_true", dest='enable_relro')
96 opt.add_option('--without-relro',
97 help=("Disable RELRO builds"),
98 action="store_false", dest='enable_relro')
100 gr = opt.option_group('developer options')
102 opt.tool_options('python') # options for disabling pyc or pyo compilation
103 # enable options related to building python extensions
106 def configure(conf):
107 version = samba_version.load_version(env=conf.env)
109 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
110 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
111 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
113 if Options.options.developer:
114 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
115 conf.env.DEVELOPER = True
117 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
119 conf.env.replace_add_global_pthread = True
120 conf.RECURSE('lib/replace')
122 conf.RECURSE('examples/fuse')
124 conf.SAMBA_CHECK_PERL(mandatory=True)
125 conf.find_program('xsltproc', var='XSLTPROC')
127 if conf.env.disable_python:
128 if not (Options.options.without_ad_dc):
129 raise Utils.WafError('--disable-python requires --without-ad-dc')
131 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
132 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
134 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
135 # Mac OSX needs to have this and it's also needed that the python is compiled with this
136 # otherwise you face errors about common symbols
137 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
138 conf.ADD_CFLAGS('-fno-common')
139 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
140 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
142 if sys.platform == 'darwin':
143 conf.ADD_LDFLAGS('-framework CoreFoundation')
145 if int(conf.env['PYTHON_VERSION'][0]) >= 3:
146 raise Utils.WafError('Python version 3.x is not supported by Samba yet')
148 conf.RECURSE('dynconfig')
149 conf.RECURSE('selftest')
151 if conf.CHECK_FOR_THIRD_PARTY():
152 conf.RECURSE('third_party')
153 else:
154 if not conf.CHECK_ZLIB():
155 raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
156 else:
157 conf.define('USING_SYSTEM_ZLIB',1)
159 if not conf.CHECK_POPT():
160 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
161 else:
162 conf.define('USING_SYSTEM_POPT', 1)
164 if not conf.CHECK_CMOCKA():
165 raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
166 else:
167 conf.define('USING_SYSTEM_CMOCKA', 1)
169 if conf.CONFIG_GET('ENABLE_SELFTEST'):
170 if not conf.CHECK_SOCKET_WRAPPER():
171 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
172 else:
173 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
175 if not conf.CHECK_NSS_WRAPPER():
176 raise Utils.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
177 else:
178 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
180 if not conf.CHECK_RESOLV_WRAPPER():
181 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
182 else:
183 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
185 if not conf.CHECK_UID_WRAPPER():
186 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
187 else:
188 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
190 if not conf.CHECK_PAM_WRAPPER():
191 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
192 else:
193 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
195 conf.RECURSE('lib/ldb')
197 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
198 conf.env['HAVE_LDWRAP'] = True
199 conf.define('HAVE_LDWRAP', 1)
201 if not (Options.options.without_ad_dc):
202 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
204 if Options.options.with_system_mitkrb5:
205 if not Options.options.with_experimental_mit_ad_dc and \
206 not Options.options.without_ad_dc:
207 raise Utils.WafError('The MIT Kerberos build of Samba as an AD DC ' +
208 'is experimental. Therefore '
209 '--with-system-mitkrb5 requires either ' +
210 '--with-experimental-mit-ad-dc or ' +
211 '--without-ad-dc')
213 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
215 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
216 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
218 # Only process heimdal_build for non-MIT KRB5 builds
219 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
220 # to the lowcased output of 'krb5-config --vendor'.
221 # If it is not set or the output is 'heimdal', we are dealing with
222 # system-provided or embedded Heimdal build
223 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
224 conf.RECURSE('source4/heimdal_build')
225 conf.RECURSE('source4/lib/tls')
226 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
227 conf.RECURSE('source4/ntvfs/sysdep')
228 conf.RECURSE('lib/util')
229 conf.RECURSE('lib/util/charset')
230 conf.RECURSE('source4/auth')
231 conf.RECURSE('nsswitch')
232 conf.RECURSE('libcli/smbreadline')
233 conf.RECURSE('lib/crypto')
234 conf.RECURSE('pidl')
235 if conf.CONFIG_GET('ENABLE_SELFTEST'):
236 if Options.options.with_ntvfs_fileserver != False:
237 if not (Options.options.without_ad_dc):
238 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
239 if Options.options.with_ntvfs_fileserver == False:
240 if not (Options.options.without_ad_dc):
241 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
242 conf.RECURSE('testsuite/unittests')
244 if Options.options.with_ntvfs_fileserver == True:
245 if Options.options.without_ad_dc:
246 raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
247 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
249 if Options.options.with_pthreadpool:
250 if conf.CONFIG_SET('HAVE_PTHREAD'):
251 conf.DEFINE('WITH_PTHREADPOOL', '1')
252 else:
253 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
254 conf.undefine('WITH_PTHREADPOOL')
256 conf.RECURSE('source3')
257 conf.RECURSE('lib/texpect')
258 conf.RECURSE('python')
259 if conf.env.with_ctdb:
260 conf.RECURSE('ctdb')
261 conf.RECURSE('lib/socket')
262 conf.RECURSE('auth')
263 conf.RECURSE('packaging')
265 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
267 # gentoo always adds this. We want our normal build to be as
268 # strict as the strictest OS we support, so adding this here
269 # allows us to find problems on our development hosts faster.
270 # It also results in faster load time.
272 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
274 if not conf.CHECK_NEED_LC("-lc not needed"):
275 conf.ADD_LDFLAGS('-lc', testflags=False)
277 if not conf.CHECK_CODE('#include "tests/summary.c"',
278 define='SUMMARY_PASSES',
279 addmain=False,
280 msg='Checking configure summary'):
281 raise Utils.WafError('configure summary failed')
283 if Options.options.enable_pie != False:
284 if Options.options.enable_pie == True:
285 need_pie = True
286 else:
287 # not specified, only build PIEs if supported by compiler
288 need_pie = False
289 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
290 msg="Checking compiler for PIE support"):
291 conf.env['ENABLE_PIE'] = True
293 if Options.options.enable_relro != False:
294 if Options.options.enable_relro == True:
295 need_relro = True
296 else:
297 # not specified, only build RELROs if supported by compiler
298 need_relro = False
299 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
300 msg="Checking compiler for full RELRO support"):
301 conf.env['ENABLE_RELRO'] = True
303 conf.SAMBA_CONFIG_H('include/config.h')
305 def etags(ctx):
306 '''build TAGS file using etags'''
307 import Utils
308 source_root = os.path.dirname(Utils.g_module.root_path)
309 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
310 print("Running: %s" % cmd)
311 status = os.system(cmd)
312 if os.WEXITSTATUS(status):
313 raise Utils.WafError('etags failed')
315 def ctags(ctx):
316 "build 'tags' file using ctags"
317 import Utils
318 source_root = os.path.dirname(Utils.g_module.root_path)
319 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
320 print("Running: %s" % cmd)
321 status = os.system(cmd)
322 if os.WEXITSTATUS(status):
323 raise Utils.WafError('ctags failed')
326 # putting this here enabled build in the list
327 # of commands in --help
328 def build(bld):
329 '''build all targets'''
330 samba_version.load_version(env=bld.env, is_install=bld.is_install)
333 def pydoctor(ctx):
334 '''build python apidocs'''
335 bp = os.path.abspath('bin/python')
336 mpaths = {}
337 modules = ['talloc', 'tdb', 'ldb']
338 for m in modules:
339 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
340 try:
341 mpaths[m] = f.read().strip()
342 finally:
343 f.close()
344 mpaths['main'] = bp
345 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
346 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
347 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
348 cmd = cmd % mpaths
349 print("Running: %s" % cmd)
350 status = os.system(cmd)
351 if os.WEXITSTATUS(status):
352 raise Utils.WafError('pydoctor failed')
355 def pep8(ctx):
356 '''run pep8 validator'''
357 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
358 print("Running: %s" % cmd)
359 status = os.system(cmd)
360 if os.WEXITSTATUS(status):
361 raise Utils.WafError('pep8 failed')
364 def wafdocs(ctx):
365 '''build wafsamba apidocs'''
366 from samba_utils import recursive_dirlist
367 os.system('pwd')
368 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
370 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
371 print(list)
372 for f in list:
373 cmd += ' --add-module %s' % f
374 print("Running: %s" % cmd)
375 status = os.system(cmd)
376 if os.WEXITSTATUS(status):
377 raise Utils.WafError('wafdocs failed')
380 def dist():
381 '''makes a tarball for distribution'''
382 sambaversion = samba_version.load_version(env=None)
384 os.system("make -C ctdb manpages")
385 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
387 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
388 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
390 if sambaversion.IS_SNAPSHOT:
391 # write .distversion file and add to tar
392 if not os.path.isdir(blddir):
393 os.makedirs(blddir)
394 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
395 for field in sambaversion.vcs_fields:
396 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
397 distversionf.write(distveroption + '\n')
398 distversionf.flush()
399 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
401 samba_dist.dist()
402 distversionf.close()
403 else:
404 samba_dist.dist()
407 def distcheck():
408 '''test that distribution tarball builds and installs'''
409 samba_version.load_version(env=None)
410 import Scripting
411 d = Scripting.distcheck
414 def wildcard_cmd(cmd):
415 '''called on a unknown command'''
416 from samba_wildcard import run_named_build_task
417 run_named_build_task(cmd)
419 def main():
420 from samba_wildcard import wildcard_main
422 wildcard_main(wildcard_cmd)
423 Scripting.main = main
425 def reconfigure(ctx):
426 '''reconfigure if config scripts have changed'''
427 import samba_utils
428 samba_utils.reconfigure(ctx)
431 if os.path.isdir(os.path.join(srcdir, ".git")):
432 # Check if there are submodules that are checked out but out of date.
433 for submodule, status in samba_git.read_submodule_status(srcdir):
434 if status == "out-of-date":
435 raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")