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)
26 for arg in parser.rargs:
27 # stop on --foo like options
28 if arg[:2] == "--" and len(arg) > 2:
32 del parser.rargs[:len(value)]
33 setattr(parser.values, option.dest, value)
36 opt.BUILTIN_DEFAULT('NONE')
37 opt.PRIVATE_EXTENSION_DEFAULT('samba4')
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('libcli/smb')
48 opt.RECURSE('source3')
49 opt.RECURSE('lib/util')
50 opt.RECURSE('lib/crypto')
54 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
56 opt.add_option('--with-system-mitkrb5',
57 help='build Samba with system MIT Kerberos. ' +
58 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
59 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
60 opt.add_option('--with-system-mitkdc',
61 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
63 dest='with_system_mitkdc',
66 opt.add_option('--without-ad-dc',
67 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
68 action='store_true', dest='without_ad_dc', default=False)
70 opt.add_option('--with-ntvfs-fileserver',
71 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',
72 action='store_true', dest='with_ntvfs_fileserver')
74 opt.add_option('--without-ntvfs-fileserver',
75 help='disable the deprecated NTVFS file server from the original Samba4 branch',
76 action='store_false', dest='with_ntvfs_fileserver')
78 opt.add_option('--with-pie',
79 help=("Build Position Independent Executables " +
80 "(default if supported by compiler)"),
81 action="store_true", dest='enable_pie')
82 opt.add_option('--without-pie',
83 help=("Disable Position Independent Executable builds"),
84 action="store_false", dest='enable_pie')
86 opt.add_option('--with-relro',
87 help=("Build with full RELocation Read-Only (RELRO)" +
88 "(default if supported by compiler)"),
89 action="store_true", dest='enable_relro')
90 opt.add_option('--without-relro',
91 help=("Disable RELRO builds"),
92 action="store_false", dest='enable_relro')
94 gr = opt.option_group('developer options')
96 opt.tool_options('python') # options for disabling pyc or pyo compilation
97 # enable options related to building python extensions
101 version = samba_version.load_version(env=conf.env)
103 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
104 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
105 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
107 if Options.options.developer:
108 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
109 conf.env.DEVELOPER = True
110 # if we are in a git tree without a pre-commit hook, install a
112 pre_commit_hook = os.path.join(srcdir, '.git/hooks/pre-commit')
113 if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
114 not os.path.exists(pre_commit_hook)):
115 shutil.copy(os.path.join(srcdir, 'script/git-hooks/pre-commit-hook'),
118 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
120 conf.env.replace_add_global_pthread = True
121 conf.RECURSE('lib/replace')
123 conf.RECURSE('examples/fuse')
125 conf.SAMBA_CHECK_PERL(mandatory=True)
126 conf.find_program('xsltproc', var='XSLTPROC')
128 if conf.env.disable_python:
129 if not (Options.options.without_ad_dc):
130 raise Utils.WafError('--disable-python requires --without-ad-dc')
132 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
133 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
135 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
136 # Mac OSX needs to have this and it's also needed that the python is compiled with this
137 # otherwise you face errors about common symbols
138 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
139 conf.ADD_CFLAGS('-fno-common')
140 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
141 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
143 if sys.platform == 'darwin':
144 conf.ADD_LDFLAGS('-framework CoreFoundation')
146 if int(conf.env['PYTHON_VERSION'][0]) >= 3:
147 raise Utils.WafError('Python version 3.x is not supported by Samba yet')
149 conf.RECURSE('dynconfig')
150 conf.RECURSE('selftest')
152 if conf.CHECK_FOR_THIRD_PARTY():
153 conf.RECURSE('third_party')
155 if not conf.CHECK_ZLIB():
156 raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
158 conf.define('USING_SYSTEM_ZLIB',1)
160 if not conf.CHECK_POPT():
161 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
163 conf.define('USING_SYSTEM_POPT', 1)
165 if not conf.CHECK_CMOCKA():
166 raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
168 conf.define('USING_SYSTEM_CMOCKA', 1)
170 if conf.CONFIG_GET('ENABLE_SELFTEST'):
171 if not conf.CHECK_SOCKET_WRAPPER():
172 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
174 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
176 if not conf.CHECK_NSS_WRAPPER():
177 raise Utils.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
179 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
181 if not conf.CHECK_RESOLV_WRAPPER():
182 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
184 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
186 if not conf.CHECK_UID_WRAPPER():
187 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
189 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
191 if not conf.CHECK_PAM_WRAPPER():
192 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
194 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
196 conf.RECURSE('lib/ldb')
198 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
199 conf.env['HAVE_LDWRAP'] = True
200 conf.define('HAVE_LDWRAP', 1)
202 if not (Options.options.without_ad_dc):
203 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
205 if Options.options.with_system_mitkrb5:
206 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
207 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
208 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
210 # Only process heimdal_build for non-MIT KRB5 builds
211 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
212 # to the lowcased output of 'krb5-config --vendor'.
213 # If it is not set or the output is 'heimdal', we are dealing with
214 # system-provided or embedded Heimdal build
215 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
216 conf.RECURSE('source4/heimdal_build')
218 conf.RECURSE('source4/lib/tls')
219 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
220 conf.RECURSE('source4/ntvfs/sysdep')
221 conf.RECURSE('lib/util')
222 conf.RECURSE('lib/util/charset')
223 conf.RECURSE('source4/auth')
224 conf.RECURSE('nsswitch')
225 conf.RECURSE('libcli/smbreadline')
226 conf.RECURSE('lib/crypto')
227 conf.RECURSE('libcli/smb')
229 if conf.CONFIG_GET('ENABLE_SELFTEST'):
230 if Options.options.with_ntvfs_fileserver != False:
231 if not (Options.options.without_ad_dc):
232 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
233 if Options.options.with_ntvfs_fileserver == False:
234 if not (Options.options.without_ad_dc):
235 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
236 conf.RECURSE('testsuite/unittests')
238 if Options.options.with_ntvfs_fileserver == True:
239 if Options.options.without_ad_dc:
240 raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
241 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
243 if Options.options.with_pthreadpool:
244 if conf.CONFIG_SET('HAVE_PTHREAD'):
245 conf.DEFINE('WITH_PTHREADPOOL', '1')
247 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
248 conf.undefine('WITH_PTHREADPOOL')
250 conf.RECURSE('source3')
251 conf.RECURSE('lib/texpect')
252 conf.RECURSE('python')
253 if conf.env.with_ctdb:
255 conf.RECURSE('lib/socket')
257 conf.RECURSE('packaging')
259 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
261 # gentoo always adds this. We want our normal build to be as
262 # strict as the strictest OS we support, so adding this here
263 # allows us to find problems on our development hosts faster.
264 # It also results in faster load time.
266 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
268 if not conf.CHECK_NEED_LC("-lc not needed"):
269 conf.ADD_LDFLAGS('-lc', testflags=False)
271 if not conf.CHECK_CODE('#include "tests/summary.c"',
272 define='SUMMARY_PASSES',
274 msg='Checking configure summary'):
275 raise Utils.WafError('configure summary failed')
277 if Options.options.enable_pie != False:
278 if Options.options.enable_pie == True:
281 # not specified, only build PIEs if supported by compiler
283 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
284 msg="Checking compiler for PIE support"):
285 conf.env['ENABLE_PIE'] = True
287 if Options.options.enable_relro != False:
288 if Options.options.enable_relro == True:
291 # not specified, only build RELROs if supported by compiler
293 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
294 msg="Checking compiler for full RELRO support"):
295 conf.env['ENABLE_RELRO'] = True
297 conf.SAMBA_CONFIG_H('include/config.h')
300 '''build TAGS file using etags'''
302 source_root = os.path.dirname(Utils.g_module.root_path)
303 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
304 print("Running: %s" % cmd)
305 status = os.system(cmd)
306 if os.WEXITSTATUS(status):
307 raise Utils.WafError('etags failed')
310 "build 'tags' file using ctags"
312 source_root = os.path.dirname(Utils.g_module.root_path)
313 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
314 print("Running: %s" % cmd)
315 status = os.system(cmd)
316 if os.WEXITSTATUS(status):
317 raise Utils.WafError('ctags failed')
320 # putting this here enabled build in the list
321 # of commands in --help
323 '''build all targets'''
324 samba_version.load_version(env=bld.env, is_install=bld.is_install)
328 '''build python apidocs'''
329 bp = os.path.abspath('bin/python')
331 modules = ['talloc', 'tdb', 'ldb']
333 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
335 mpaths[m] = f.read().strip()
339 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
340 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
341 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
343 print("Running: %s" % cmd)
344 status = os.system(cmd)
345 if os.WEXITSTATUS(status):
346 raise Utils.WafError('pydoctor failed')
350 '''run pep8 validator'''
351 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
352 print("Running: %s" % cmd)
353 status = os.system(cmd)
354 if os.WEXITSTATUS(status):
355 raise Utils.WafError('pep8 failed')
359 '''build wafsamba apidocs'''
360 from samba_utils import recursive_dirlist
362 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
364 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
367 cmd += ' --add-module %s' % f
368 print("Running: %s" % cmd)
369 status = os.system(cmd)
370 if os.WEXITSTATUS(status):
371 raise Utils.WafError('wafdocs failed')
375 '''makes a tarball for distribution'''
376 sambaversion = samba_version.load_version(env=None)
378 os.system("make -C ctdb manpages")
379 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
381 os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
382 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
384 if sambaversion.IS_SNAPSHOT:
385 # write .distversion file and add to tar
386 if not os.path.isdir(blddir):
388 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
389 for field in sambaversion.vcs_fields:
390 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
391 distversionf.write(distveroption + '\n')
393 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
402 '''test that distribution tarball builds and installs'''
403 samba_version.load_version(env=None)
405 d = Scripting.distcheck
408 def wildcard_cmd(cmd):
409 '''called on a unknown command'''
410 from samba_wildcard import run_named_build_task
411 run_named_build_task(cmd)
414 from samba_wildcard import wildcard_main
416 wildcard_main(wildcard_cmd)
417 Scripting.main = main
419 def reconfigure(ctx):
420 '''reconfigure if config scripts have changed'''
422 samba_utils.reconfigure(ctx)
425 if os.path.isdir(os.path.join(srcdir, ".git")):
426 # Check if there are submodules that are checked out but out of date.
427 for submodule, status in samba_git.read_submodule_status(srcdir):
428 if status == "out-of-date":
429 raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")