s3:messages: check tevent_fd_get_flags() == 0 before using stale event context pointer
[Samba.git] / wscript
blobb45146c31b2dfbb61d4b1fc5a84e73b309d0c1aa
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('auth')
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)
59 opt.add_option('--with-system-mitkdc',
60 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
61 type="string",
62 dest='with_system_mitkdc',
63 default=None)
65 opt.add_option('--without-ad-dc',
66 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
67 action='store_true', dest='without_ad_dc', default=False)
69 opt.add_option('--with-ntvfs-fileserver',
70 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',
71 action='store_true', dest='with_ntvfs_fileserver')
73 opt.add_option('--without-ntvfs-fileserver',
74 help='disable the deprecated NTVFS file server from the original Samba4 branch',
75 action='store_false', dest='with_ntvfs_fileserver')
77 opt.add_option('--with-pie',
78 help=("Build Position Independent Executables " +
79 "(default if supported by compiler)"),
80 action="store_true", dest='enable_pie')
81 opt.add_option('--without-pie',
82 help=("Disable Position Independent Executable builds"),
83 action="store_false", dest='enable_pie')
85 opt.add_option('--with-relro',
86 help=("Build with full RELocation Read-Only (RELRO)" +
87 "(default if supported by compiler)"),
88 action="store_true", dest='enable_relro')
89 opt.add_option('--without-relro',
90 help=("Disable RELRO builds"),
91 action="store_false", dest='enable_relro')
93 gr = opt.option_group('developer options')
95 opt.tool_options('python') # options for disabling pyc or pyo compilation
96 # enable options related to building python extensions
99 def configure(conf):
100 version = samba_version.load_version(env=conf.env)
102 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
103 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
104 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
106 if Options.options.developer:
107 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
108 conf.env.DEVELOPER = True
110 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
112 conf.env.replace_add_global_pthread = True
113 conf.RECURSE('lib/replace')
115 conf.RECURSE('examples/fuse')
117 conf.SAMBA_CHECK_PERL(mandatory=True)
118 conf.find_program('xsltproc', var='XSLTPROC')
120 if conf.env.disable_python:
121 if not (Options.options.without_ad_dc):
122 raise Utils.WafError('--disable-python requires --without-ad-dc')
124 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
125 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
127 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
128 # Mac OSX needs to have this and it's also needed that the python is compiled with this
129 # otherwise you face errors about common symbols
130 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
131 conf.ADD_CFLAGS('-fno-common')
132 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
133 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
135 if sys.platform == 'darwin':
136 conf.ADD_LDFLAGS('-framework CoreFoundation')
138 if int(conf.env['PYTHON_VERSION'][0]) >= 3:
139 raise Utils.WafError('Python version 3.x is not supported by Samba yet')
141 conf.RECURSE('dynconfig')
142 conf.RECURSE('selftest')
144 if conf.CHECK_FOR_THIRD_PARTY():
145 conf.RECURSE('third_party')
146 else:
147 if not conf.CHECK_ZLIB():
148 raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
149 else:
150 conf.define('USING_SYSTEM_ZLIB',1)
152 if not conf.CHECK_POPT():
153 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
154 else:
155 conf.define('USING_SYSTEM_POPT', 1)
157 if not conf.CHECK_CMOCKA():
158 raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
159 else:
160 conf.define('USING_SYSTEM_CMOCKA', 1)
162 if conf.CONFIG_GET('ENABLE_SELFTEST'):
163 if not conf.CHECK_SOCKET_WRAPPER():
164 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
165 else:
166 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
168 if not conf.CHECK_NSS_WRAPPER():
169 raise Utils.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
170 else:
171 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
173 if not conf.CHECK_RESOLV_WRAPPER():
174 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
175 else:
176 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
178 if not conf.CHECK_UID_WRAPPER():
179 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
180 else:
181 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
183 if not conf.CHECK_PAM_WRAPPER():
184 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
185 else:
186 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
188 conf.RECURSE('lib/ldb')
190 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
191 conf.env['HAVE_LDWRAP'] = True
192 conf.define('HAVE_LDWRAP', 1)
194 if not (Options.options.without_ad_dc):
195 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
197 if Options.options.with_system_mitkrb5:
198 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
199 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
200 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
202 # Only process heimdal_build for non-MIT KRB5 builds
203 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
204 # to the lowcased output of 'krb5-config --vendor'.
205 # If it is not set or the output is 'heimdal', we are dealing with
206 # system-provided or embedded Heimdal build
207 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
208 conf.RECURSE('source4/heimdal_build')
209 conf.RECURSE('auth')
210 conf.RECURSE('source4/lib/tls')
211 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
212 conf.RECURSE('source4/ntvfs/sysdep')
213 conf.RECURSE('lib/util')
214 conf.RECURSE('lib/util/charset')
215 conf.RECURSE('source4/auth')
216 conf.RECURSE('nsswitch')
217 conf.RECURSE('libcli/smbreadline')
218 conf.RECURSE('lib/crypto')
219 conf.RECURSE('pidl')
220 if conf.CONFIG_GET('ENABLE_SELFTEST'):
221 if Options.options.with_ntvfs_fileserver != False:
222 if not (Options.options.without_ad_dc):
223 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
224 if Options.options.with_ntvfs_fileserver == False:
225 if not (Options.options.without_ad_dc):
226 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
227 conf.RECURSE('testsuite/unittests')
229 if Options.options.with_ntvfs_fileserver == True:
230 if Options.options.without_ad_dc:
231 raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
232 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
234 if Options.options.with_pthreadpool:
235 if conf.CONFIG_SET('HAVE_PTHREAD'):
236 conf.DEFINE('WITH_PTHREADPOOL', '1')
237 else:
238 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
239 conf.undefine('WITH_PTHREADPOOL')
241 conf.RECURSE('source3')
242 conf.RECURSE('lib/texpect')
243 conf.RECURSE('python')
244 if conf.env.with_ctdb:
245 conf.RECURSE('ctdb')
246 conf.RECURSE('lib/socket')
247 conf.RECURSE('auth')
248 conf.RECURSE('packaging')
250 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
252 # gentoo always adds this. We want our normal build to be as
253 # strict as the strictest OS we support, so adding this here
254 # allows us to find problems on our development hosts faster.
255 # It also results in faster load time.
257 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
259 if not conf.CHECK_NEED_LC("-lc not needed"):
260 conf.ADD_LDFLAGS('-lc', testflags=False)
262 if not conf.CHECK_CODE('#include "tests/summary.c"',
263 define='SUMMARY_PASSES',
264 addmain=False,
265 msg='Checking configure summary'):
266 raise Utils.WafError('configure summary failed')
268 if Options.options.enable_pie != False:
269 if Options.options.enable_pie == True:
270 need_pie = True
271 else:
272 # not specified, only build PIEs if supported by compiler
273 need_pie = False
274 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
275 msg="Checking compiler for PIE support"):
276 conf.env['ENABLE_PIE'] = True
278 if Options.options.enable_relro != False:
279 if Options.options.enable_relro == True:
280 need_relro = True
281 else:
282 # not specified, only build RELROs if supported by compiler
283 need_relro = False
284 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
285 msg="Checking compiler for full RELRO support"):
286 conf.env['ENABLE_RELRO'] = True
288 conf.SAMBA_CONFIG_H('include/config.h')
290 def etags(ctx):
291 '''build TAGS file using etags'''
292 import Utils
293 source_root = os.path.dirname(Utils.g_module.root_path)
294 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
295 print("Running: %s" % cmd)
296 status = os.system(cmd)
297 if os.WEXITSTATUS(status):
298 raise Utils.WafError('etags failed')
300 def ctags(ctx):
301 "build 'tags' file using ctags"
302 import Utils
303 source_root = os.path.dirname(Utils.g_module.root_path)
304 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
305 print("Running: %s" % cmd)
306 status = os.system(cmd)
307 if os.WEXITSTATUS(status):
308 raise Utils.WafError('ctags failed')
311 # putting this here enabled build in the list
312 # of commands in --help
313 def build(bld):
314 '''build all targets'''
315 samba_version.load_version(env=bld.env, is_install=bld.is_install)
318 def pydoctor(ctx):
319 '''build python apidocs'''
320 bp = os.path.abspath('bin/python')
321 mpaths = {}
322 modules = ['talloc', 'tdb', 'ldb']
323 for m in modules:
324 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
325 try:
326 mpaths[m] = f.read().strip()
327 finally:
328 f.close()
329 mpaths['main'] = bp
330 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
331 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
332 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
333 cmd = cmd % mpaths
334 print("Running: %s" % cmd)
335 status = os.system(cmd)
336 if os.WEXITSTATUS(status):
337 raise Utils.WafError('pydoctor failed')
340 def pep8(ctx):
341 '''run pep8 validator'''
342 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
343 print("Running: %s" % cmd)
344 status = os.system(cmd)
345 if os.WEXITSTATUS(status):
346 raise Utils.WafError('pep8 failed')
349 def wafdocs(ctx):
350 '''build wafsamba apidocs'''
351 from samba_utils import recursive_dirlist
352 os.system('pwd')
353 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
355 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
356 print(list)
357 for f in list:
358 cmd += ' --add-module %s' % f
359 print("Running: %s" % cmd)
360 status = os.system(cmd)
361 if os.WEXITSTATUS(status):
362 raise Utils.WafError('wafdocs failed')
365 def dist():
366 '''makes a tarball for distribution'''
367 sambaversion = samba_version.load_version(env=None)
369 os.system("make -C ctdb manpages")
370 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
372 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
373 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
375 if sambaversion.IS_SNAPSHOT:
376 # write .distversion file and add to tar
377 if not os.path.isdir(blddir):
378 os.makedirs(blddir)
379 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
380 for field in sambaversion.vcs_fields:
381 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
382 distversionf.write(distveroption + '\n')
383 distversionf.flush()
384 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
386 samba_dist.dist()
387 distversionf.close()
388 else:
389 samba_dist.dist()
392 def distcheck():
393 '''test that distribution tarball builds and installs'''
394 samba_version.load_version(env=None)
395 import Scripting
396 d = Scripting.distcheck
399 def wildcard_cmd(cmd):
400 '''called on a unknown command'''
401 from samba_wildcard import run_named_build_task
402 run_named_build_task(cmd)
404 def main():
405 from samba_wildcard import wildcard_main
407 wildcard_main(wildcard_cmd)
408 Scripting.main = main
410 def reconfigure(ctx):
411 '''reconfigure if config scripts have changed'''
412 import samba_utils
413 samba_utils.reconfigure(ctx)
416 if os.path.isdir(os.path.join(srcdir, ".git")):
417 # Check if there are submodules that are checked out but out of date.
418 for submodule, status in samba_git.read_submodule_status(srcdir):
419 if status == "out-of-date":
420 raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")