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