netapi: Use dom_sid_str_buf
[Samba.git] / wscript
blobda4254efde49b5b4d3d4e4529f75c53788117fcc
1 #!/usr/bin/env python
3 top = '.'
4 out = 'bin'
6 APPNAME='samba'
7 VERSION=None
9 import sys, os, tempfile
10 sys.path.insert(0, top+"/buildtools/wafsamba")
11 import shutil
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)
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 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('--with-system-heimdalkrb5',
73 help=('build Samba with system Heimdal Kerberos. ' +
74 'Requires --without-ad-dc' and
75 'conflicts with --with-system-mitkrb5'),
76 action='store_true',
77 dest='with_system_heimdalkrb5',
78 default=False)
80 opt.add_option('--without-ad-dc',
81 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
82 action='store_true', dest='without_ad_dc', default=False)
84 opt.add_option('--with-ntvfs-fileserver',
85 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',
86 action='store_true', dest='with_ntvfs_fileserver')
88 opt.add_option('--without-ntvfs-fileserver',
89 help='disable the deprecated NTVFS file server from the original Samba4 branch',
90 action='store_false', dest='with_ntvfs_fileserver')
92 opt.add_option('--with-pie',
93 help=("Build Position Independent Executables " +
94 "(default if supported by compiler)"),
95 action="store_true", dest='enable_pie')
96 opt.add_option('--without-pie',
97 help=("Disable Position Independent Executable builds"),
98 action="store_false", dest='enable_pie')
100 opt.add_option('--with-relro',
101 help=("Build with full RELocation Read-Only (RELRO)" +
102 "(default if supported by compiler)"),
103 action="store_true", dest='enable_relro')
104 opt.add_option('--without-relro',
105 help=("Disable RELRO builds"),
106 action="store_false", dest='enable_relro')
108 gr = opt.option_group('developer options')
110 opt.load('python') # options for disabling pyc or pyo compilation
111 # enable options related to building python extensions
113 opt.add_option('--with-json',
114 action='store_true', dest='with_json',
115 help=("Build with JSON support (default=True). This "
116 "requires the jansson development headers."))
117 opt.add_option('--without-json',
118 action='store_false', dest='with_json',
119 help=("Build without JSON support."))
121 def configure(conf):
122 version = samba_version.load_version(env=conf.env)
124 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
125 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
126 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
128 if Options.options.developer:
129 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
130 conf.env.DEVELOPER = True
131 # if we are in a git tree without a pre-commit hook, install a
132 # simple default.
133 pre_commit_hook = os.path.join(Context.g_module.top, '.git/hooks/pre-commit')
134 if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
135 not os.path.exists(pre_commit_hook)):
136 shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
137 pre_commit_hook)
139 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
141 conf.env.replace_add_global_pthread = True
142 conf.RECURSE('lib/replace')
144 conf.RECURSE('examples/fuse')
145 conf.RECURSE('examples/winexe')
147 conf.SAMBA_CHECK_PERL(mandatory=True)
148 conf.find_program('xsltproc', var='XSLTPROC')
150 if conf.env.disable_python:
151 if not (Options.options.without_ad_dc):
152 raise Errors.WafError('--disable-python requires --without-ad-dc')
154 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
155 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
157 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
158 # Mac OSX needs to have this and it's also needed that the python is compiled with this
159 # otherwise you face errors about common symbols
160 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
161 conf.ADD_CFLAGS('-fno-common')
162 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
163 conf.env.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
165 if sys.platform == 'darwin':
166 conf.ADD_LDFLAGS('-framework CoreFoundation')
168 conf.RECURSE('dynconfig')
169 conf.RECURSE('selftest')
171 if conf.CHECK_FOR_THIRD_PARTY():
172 conf.RECURSE('third_party')
173 else:
174 if not conf.CHECK_ZLIB():
175 raise Errors.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
176 else:
177 conf.define('USING_SYSTEM_ZLIB',1)
179 if not conf.CHECK_POPT():
180 raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
181 else:
182 conf.define('USING_SYSTEM_POPT', 1)
184 if not conf.CHECK_CMOCKA():
185 raise Errors.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
186 else:
187 conf.define('USING_SYSTEM_CMOCKA', 1)
189 if conf.CONFIG_GET('ENABLE_SELFTEST'):
190 if not conf.CHECK_SOCKET_WRAPPER():
191 raise Errors.WafError('socket_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_SOCKET_WRAPPER', 1)
195 if not conf.CHECK_NSS_WRAPPER():
196 raise Errors.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
197 else:
198 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
200 if not conf.CHECK_RESOLV_WRAPPER():
201 raise Errors.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
202 else:
203 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
205 if not conf.CHECK_UID_WRAPPER():
206 raise Errors.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
207 else:
208 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
210 if not conf.CHECK_PAM_WRAPPER():
211 raise Errors.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
212 else:
213 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
215 conf.RECURSE('lib/ldb')
217 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
218 conf.env['HAVE_LDWRAP'] = True
219 conf.define('HAVE_LDWRAP', 1)
221 if not (Options.options.without_ad_dc):
222 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
224 if Options.options.with_system_mitkrb5:
225 if not Options.options.with_experimental_mit_ad_dc and \
226 not Options.options.without_ad_dc:
227 raise Errors.WafError('The MIT Kerberos build of Samba as an AD DC ' +
228 'is experimental. Therefore '
229 '--with-system-mitkrb5 requires either ' +
230 '--with-experimental-mit-ad-dc or ' +
231 '--without-ad-dc')
233 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
235 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
236 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
238 if Options.options.with_system_heimdalkrb5:
239 if Options.options.with_system_mitkrb5:
240 raise Errors.WafError('--with-system-heimdalkrb5 conflicts with ' +
241 '--with-system-mitkrb5')
242 if not Options.options.without_ad_dc:
243 raise Errors.WafError('--with-system-heimdalkrb5 requires ' +
244 '--without-ad-dc')
245 conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
246 'hx509', 'wind', 'gssapi', 'hcrypto',
247 'krb5', 'heimbase', 'asn1_compile',
248 'compile_et', 'kdc', 'hdb', 'heimntlm')
250 # Only process heimdal_build for non-MIT KRB5 builds
251 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
252 # to the lowcased output of 'krb5-config --vendor'.
253 # If it is not set or the output is 'heimdal', we are dealing with
254 # system-provided or embedded Heimdal build
255 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
256 conf.RECURSE('source4/heimdal_build')
257 conf.RECURSE('source4/lib/tls')
258 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
259 conf.RECURSE('source4/ntvfs/sysdep')
260 conf.RECURSE('lib/util')
261 conf.RECURSE('lib/util/charset')
262 conf.RECURSE('source4/auth')
263 conf.RECURSE('nsswitch')
264 conf.RECURSE('libcli/smbreadline')
265 conf.RECURSE('lib/crypto')
266 conf.RECURSE('pidl')
267 if conf.CONFIG_GET('ENABLE_SELFTEST'):
268 if Options.options.with_ntvfs_fileserver != False:
269 if not (Options.options.without_ad_dc):
270 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
271 if Options.options.with_ntvfs_fileserver == False:
272 if not (Options.options.without_ad_dc):
273 raise Errors.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
274 conf.RECURSE('testsuite/unittests')
276 if Options.options.with_ntvfs_fileserver == True:
277 if Options.options.without_ad_dc:
278 raise Errors.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
279 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
281 if Options.options.with_pthreadpool:
282 if conf.CONFIG_SET('HAVE_PTHREAD') and \
283 conf.CONFIG_SET('HAVE___THREAD') and \
284 conf.CONFIG_SET('HAVE_ATOMIC_THREAD_FENCE_SUPPORT'):
285 conf.DEFINE('WITH_PTHREADPOOL', '1')
286 else:
287 if not conf.CONFIG_SET('HAVE_PTHREAD'):
288 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
289 if not conf.CONFIG_SET('HAVE_ATOMIC_THREAD_FENCE_SUPPORT'):
290 Logs.warn("""pthreadpool support cannot be enabled when there is
291 no support for atomic_thead_fence()""")
292 if not conf.CONFIG_SET('HAVE___THREAD'):
293 Logs.warn("pthreadpool support cannot be enabled when __thread support was not found")
294 conf.undefine('WITH_PTHREADPOOL')
296 conf.SET_TARGET_TYPE('jansson', 'EMPTY')
298 if Options.options.with_json != False:
299 if conf.CHECK_CFG(package='jansson', args='--cflags --libs',
300 msg='Checking for jansson'):
301 conf.CHECK_FUNCS_IN('json_object', 'jansson')
303 if not conf.CONFIG_GET('HAVE_JSON_OBJECT'):
304 if Options.options.with_json != False:
305 conf.fatal("Jansson JSON support not found. "
306 "Try installing libjansson-dev or jansson-devel. "
307 "Otherwise, use --without-json to build without "
308 "JSON support. "
309 "JSON support is required for the JSON "
310 "formatted audit log feature, the AD DC, and "
311 "the JSON printers of the net utility")
312 if not Options.options.without_ad_dc:
313 raise Errors.WafError('--without-json requires --without-ad-dc. '
314 'Jansson JSON library is required for '
315 'building the AD DC')
316 Logs.info("Building without Jansson JSON log support")
318 conf.RECURSE('source3')
319 conf.RECURSE('lib/texpect')
320 conf.RECURSE('python')
321 if conf.env.with_ctdb:
322 conf.RECURSE('ctdb')
323 conf.RECURSE('lib/socket')
324 conf.RECURSE('lib/mscat')
325 conf.RECURSE('packaging')
327 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
329 # gentoo always adds this. We want our normal build to be as
330 # strict as the strictest OS we support, so adding this here
331 # allows us to find problems on our development hosts faster.
332 # It also results in faster load time.
334 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
336 if not conf.CHECK_NEED_LC("-lc not needed"):
337 conf.ADD_LDFLAGS('-lc', testflags=False)
339 if not conf.CHECK_CODE('#include "tests/summary.c"',
340 define='SUMMARY_PASSES',
341 addmain=False,
342 msg='Checking configure summary'):
343 raise Errors.WafError('configure summary failed')
345 if Options.options.enable_pie != False:
346 if Options.options.enable_pie == True:
347 need_pie = True
348 else:
349 # not specified, only build PIEs if supported by compiler
350 need_pie = False
351 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
352 msg="Checking compiler for PIE support"):
353 conf.env['ENABLE_PIE'] = True
355 if Options.options.enable_relro != False:
356 if Options.options.enable_relro == True:
357 need_relro = True
358 else:
359 # not specified, only build RELROs if supported by compiler
360 need_relro = False
361 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
362 msg="Checking compiler for full RELRO support"):
363 conf.env['ENABLE_RELRO'] = True
365 conf.SAMBA_CONFIG_H('include/config.h')
367 def etags(ctx):
368 '''build TAGS file using etags'''
369 from waflib import Utils
370 source_root = os.path.dirname(Context.g_module.root_path)
371 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
372 print("Running: %s" % cmd)
373 status = os.system(cmd)
374 if os.WEXITSTATUS(status):
375 raise Errors.WafError('etags failed')
377 def ctags(ctx):
378 "build 'tags' file using ctags"
379 from waflib import Utils
380 source_root = os.path.dirname(Context.g_module.root_path)
381 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
382 print("Running: %s" % cmd)
383 status = os.system(cmd)
384 if os.WEXITSTATUS(status):
385 raise Errors.WafError('ctags failed')
388 # putting this here enabled build in the list
389 # of commands in --help
390 def build(bld):
391 '''build all targets'''
392 samba_version.load_version(env=bld.env, is_install=bld.is_install)
395 def pydoctor(ctx):
396 '''build python apidocs'''
397 bp = os.path.abspath('bin/python')
398 mpaths = {}
399 modules = ['talloc', 'tdb', 'ldb']
400 for m in modules:
401 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
402 try:
403 mpaths[m] = f.read().strip()
404 finally:
405 f.close()
406 mpaths['main'] = bp
407 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
408 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
409 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
410 cmd = cmd % mpaths
411 print("Running: %s" % cmd)
412 status = os.system(cmd)
413 if os.WEXITSTATUS(status):
414 raise Errors.WafError('pydoctor failed')
417 def pep8(ctx):
418 '''run pep8 validator'''
419 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
420 print("Running: %s" % cmd)
421 status = os.system(cmd)
422 if os.WEXITSTATUS(status):
423 raise Errors.WafError('pep8 failed')
426 def wafdocs(ctx):
427 '''build wafsamba apidocs'''
428 from samba_utils import recursive_dirlist
429 os.system('pwd')
430 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
432 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
433 print(list)
434 for f in list:
435 cmd += ' --add-module %s' % f
436 print("Running: %s" % cmd)
437 status = os.system(cmd)
438 if os.WEXITSTATUS(status):
439 raise Errors.WafError('wafdocs failed')
442 def dist():
443 '''makes a tarball for distribution'''
444 sambaversion = samba_version.load_version(env=None)
446 os.system("make -C ctdb manpages")
447 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
449 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + Context.g_module.top + "/release-scripts/build-manpages-nogit")
450 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
452 if sambaversion.IS_SNAPSHOT:
453 # write .distversion file and add to tar
454 if not os.path.isdir(Context.g_module.out):
455 os.makedirs(Context.g_module.out)
456 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=Context.g_module.out)
457 for field in sambaversion.vcs_fields:
458 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
459 distversionf.write(distveroption + '\n')
460 distversionf.flush()
461 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
463 samba_dist.dist()
464 distversionf.close()
465 else:
466 samba_dist.dist()
469 def distcheck():
470 '''test that distribution tarball builds and installs'''
471 samba_version.load_version(env=None)
473 def wildcard_cmd(cmd):
474 '''called on a unknown command'''
475 from samba_wildcard import run_named_build_task
476 run_named_build_task(cmd)
478 def main():
479 from samba_wildcard import wildcard_main
481 wildcard_main(wildcard_cmd)
482 Scripting.main = main
484 def reconfigure(ctx):
485 '''reconfigure if config scripts have changed'''
486 import samba_utils
487 samba_utils.reconfigure(ctx)
490 if os.path.isdir(os.path.join(top, ".git")):
491 # Check if there are submodules that are checked out but out of date.
492 for submodule, status in samba_git.read_submodule_status(top):
493 if status == "out-of-date":
494 raise Errors.WafError("some submodules are out of date. Please run 'git submodule update'")