third_party:build: Test for the flags, recognized by Clang.
[amitay/samba.git] / wscript
1 #!/usr/bin/env python
2
3 srcdir = '.'
4 blddir = 'bin'
5
6 APPNAME='samba'
7 VERSION=None
8
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
13 import shutil
14
15 samba_dist.DIST_DIRS('.')
16 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
17
18 # install in /usr/local/samba by default
19 default_prefix = Options.default_prefix = '/usr/local/samba'
20
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)
34
35 def set_options(opt):
36     opt.BUILTIN_DEFAULT('NONE')
37     opt.PRIVATE_EXTENSION_DEFAULT('samba4')
38     opt.RECURSE('lib/audit_logging')
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')
51
52
53     opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
54
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)
64
65     opt.add_option('--with-system-heimdalkrb5',
66                    help=('build Samba with system Heimdal Kerberos. ' +
67                          'Requires --without-ad-dc' and
68                          'conflicts with --with-system-mitkrb5'),
69                    action='store_true',
70                    dest='with_system_heimdalkrb5',
71                    default=False)
72
73     opt.add_option('--without-ad-dc',
74                    help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
75                    action='store_true', dest='without_ad_dc', default=False)
76
77     opt.add_option('--with-ntvfs-fileserver',
78                    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',
79                    action='store_true', dest='with_ntvfs_fileserver')
80
81     opt.add_option('--without-ntvfs-fileserver',
82                    help='disable the deprecated NTVFS file server from the original Samba4 branch',
83                    action='store_false', dest='with_ntvfs_fileserver')
84
85     opt.add_option('--with-pie',
86                   help=("Build Position Independent Executables " +
87                         "(default if supported by compiler)"),
88                   action="store_true", dest='enable_pie')
89     opt.add_option('--without-pie',
90                   help=("Disable Position Independent Executable builds"),
91                   action="store_false", dest='enable_pie')
92
93     opt.add_option('--with-relro',
94                   help=("Build with full RELocation Read-Only (RELRO)" +
95                         "(default if supported by compiler)"),
96                   action="store_true", dest='enable_relro')
97     opt.add_option('--without-relro',
98                   help=("Disable RELRO builds"),
99                   action="store_false", dest='enable_relro')
100
101     gr = opt.option_group('developer options')
102
103     opt.tool_options('python') # options for disabling pyc or pyo compilation
104     # enable options related to building python extensions
105
106
107 def configure(conf):
108     version = samba_version.load_version(env=conf.env)
109
110     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
111     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
112     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
113
114     if Options.options.developer:
115         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
116         conf.env.DEVELOPER = True
117         # if we are in a git tree without a pre-commit hook, install a
118         # simple default.
119         pre_commit_hook = os.path.join(srcdir, '.git/hooks/pre-commit')
120         if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
121             not os.path.exists(pre_commit_hook)):
122             shutil.copy(os.path.join(srcdir, 'script/git-hooks/pre-commit-hook'),
123                         pre_commit_hook)
124
125     conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
126
127     conf.env.replace_add_global_pthread = True
128     conf.RECURSE('lib/replace')
129
130     conf.RECURSE('examples/fuse')
131
132     conf.SAMBA_CHECK_PERL(mandatory=True)
133     conf.find_program('xsltproc', var='XSLTPROC')
134
135     if conf.env.disable_python:
136         if not (Options.options.without_ad_dc):
137             raise Utils.WafError('--disable-python requires --without-ad-dc')
138
139     conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
140     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
141
142     if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
143         # Mac OSX needs to have this and it's also needed that the python is compiled with this
144         # otherwise you face errors about common symbols
145         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
146             conf.ADD_CFLAGS('-fno-common')
147         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
148             conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
149
150     if sys.platform == 'darwin':
151         conf.ADD_LDFLAGS('-framework CoreFoundation')
152
153     if int(conf.env['PYTHON_VERSION'][0]) >= 3:
154         raise Utils.WafError('Python version 3.x is not supported by Samba yet')
155
156     conf.RECURSE('dynconfig')
157     conf.RECURSE('selftest')
158
159     if conf.CHECK_FOR_THIRD_PARTY():
160         conf.RECURSE('third_party')
161     else:
162         if not conf.CHECK_ZLIB():
163             raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
164         else:
165             conf.define('USING_SYSTEM_ZLIB',1)
166
167         if not conf.CHECK_POPT():
168             raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
169         else:
170             conf.define('USING_SYSTEM_POPT', 1)
171
172         if not conf.CHECK_CMOCKA():
173             raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
174         else:
175             conf.define('USING_SYSTEM_CMOCKA', 1)
176
177         if conf.CONFIG_GET('ENABLE_SELFTEST'):
178             if not conf.CHECK_SOCKET_WRAPPER():
179                 raise Utils.WafError('socket_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_SOCKET_WRAPPER', 1)
182
183             if not conf.CHECK_NSS_WRAPPER():
184                 raise Utils.WafError('nss_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_NSS_WRAPPER', 1)
187
188             if not conf.CHECK_RESOLV_WRAPPER():
189                 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
190             else:
191                 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
192
193             if not conf.CHECK_UID_WRAPPER():
194                 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
195             else:
196                 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
197
198             if not conf.CHECK_PAM_WRAPPER():
199                 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
200             else:
201                 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
202
203     conf.RECURSE('lib/ldb')
204
205     if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
206         conf.env['HAVE_LDWRAP'] = True
207         conf.define('HAVE_LDWRAP', 1)
208
209     if not (Options.options.without_ad_dc):
210         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
211
212     if Options.options.with_system_mitkrb5:
213         conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
214     if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
215         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
216
217     if Options.options.with_system_heimdalkrb5:
218         if Options.options.with_system_mitkrb5:
219             raise Utils.WafError('--with-system-heimdalkrb5 conflicts with ' +
220                                  '--with-system-mitkrb5')
221         if not Options.options.without_ad_dc:
222             raise Utils.WafError('--with-system-heimdalkrb5 requires ' +
223                                  '--without-ad-dc')
224         conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
225                                  'hx509', 'wind', 'gssapi', 'hcrypto',
226                                  'krb5', 'heimbase', 'asn1_compile',
227                                  'compile_et', 'kdc', 'hdb', 'heimntlm')
228
229     # Only process heimdal_build for non-MIT KRB5 builds
230     # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
231     # to the lowcased output of 'krb5-config --vendor'.
232     # If it is not set or the output is 'heimdal', we are dealing with
233     # system-provided or embedded Heimdal build
234     if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
235         conf.RECURSE('source4/heimdal_build')
236     conf.RECURSE('lib/audit_logging')
237     conf.RECURSE('source4/lib/tls')
238     conf.RECURSE('source4/dsdb/samdb/ldb_modules')
239     conf.RECURSE('source4/ntvfs/sysdep')
240     conf.RECURSE('lib/util')
241     conf.RECURSE('lib/util/charset')
242     conf.RECURSE('source4/auth')
243     conf.RECURSE('nsswitch')
244     conf.RECURSE('libcli/smbreadline')
245     conf.RECURSE('lib/crypto')
246     conf.RECURSE('pidl')
247     if conf.CONFIG_GET('ENABLE_SELFTEST'):
248         if Options.options.with_ntvfs_fileserver != False:
249             if not (Options.options.without_ad_dc):
250                 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
251         if Options.options.with_ntvfs_fileserver == False:
252             if not (Options.options.without_ad_dc):
253                 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
254         conf.RECURSE('testsuite/unittests')
255
256     if Options.options.with_ntvfs_fileserver == True:
257         if Options.options.without_ad_dc:
258             raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
259         conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
260
261     if Options.options.with_pthreadpool:
262         if conf.CONFIG_SET('HAVE_PTHREAD') and \
263            conf.CONFIG_SET('HAVE___THREAD') and \
264            conf.CONFIG_SET('HAVE_ATOMIC_THREAD_FENCE_SUPPORT'):
265             conf.DEFINE('WITH_PTHREADPOOL', '1')
266         else:
267             if not conf.CONFIG_SET('HAVE_PTHREAD'):
268                 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
269             if not conf.CONFIG_SET('HAVE_ATOMIC_THREAD_FENCE_SUPPORT'):
270                 Logs.warn("""pthreadpool support cannot be enabled when there is
271                           no support for atomic_thead_fence()""")
272             if not conf.CONFIG_SET('HAVE___THREAD'):
273                 Logs.warn("pthreadpool support cannot be enabled when __thread support was not found")
274             conf.undefine('WITH_PTHREADPOOL')
275
276     conf.RECURSE('source3')
277     conf.RECURSE('lib/texpect')
278     conf.RECURSE('python')
279     if conf.env.with_ctdb:
280         conf.RECURSE('ctdb')
281     conf.RECURSE('lib/socket')
282     conf.RECURSE('lib/mscat')
283     conf.RECURSE('packaging')
284
285     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
286
287     # gentoo always adds this. We want our normal build to be as
288     # strict as the strictest OS we support, so adding this here
289     # allows us to find problems on our development hosts faster.
290     # It also results in faster load time.
291
292     conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
293
294     if not conf.CHECK_NEED_LC("-lc not needed"):
295         conf.ADD_LDFLAGS('-lc', testflags=False)
296
297     if not conf.CHECK_CODE('#include "tests/summary.c"',
298                            define='SUMMARY_PASSES',
299                            addmain=False,
300                            msg='Checking configure summary'):
301         raise Utils.WafError('configure summary failed')
302
303     if Options.options.enable_pie != False:
304         if Options.options.enable_pie == True:
305                 need_pie = True
306         else:
307                 # not specified, only build PIEs if supported by compiler
308                 need_pie = False
309         if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
310                          msg="Checking compiler for PIE support"):
311             conf.env['ENABLE_PIE'] = True
312
313     if Options.options.enable_relro != False:
314         if Options.options.enable_relro == True:
315             need_relro = True
316         else:
317             # not specified, only build RELROs if supported by compiler
318             need_relro = False
319         if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
320                          msg="Checking compiler for full RELRO support"):
321             conf.env['ENABLE_RELRO'] = True
322
323     conf.SAMBA_CONFIG_H('include/config.h')
324
325 def etags(ctx):
326     '''build TAGS file using etags'''
327     import Utils
328     source_root = os.path.dirname(Utils.g_module.root_path)
329     cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
330     print("Running: %s" % cmd)
331     status = os.system(cmd)
332     if os.WEXITSTATUS(status):
333         raise Utils.WafError('etags failed')
334
335 def ctags(ctx):
336     "build 'tags' file using ctags"
337     import Utils
338     source_root = os.path.dirname(Utils.g_module.root_path)
339     cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
340     print("Running: %s" % cmd)
341     status = os.system(cmd)
342     if os.WEXITSTATUS(status):
343         raise Utils.WafError('ctags failed')
344
345
346 # putting this here enabled build in the list
347 # of commands in --help
348 def build(bld):
349     '''build all targets'''
350     samba_version.load_version(env=bld.env, is_install=bld.is_install)
351
352
353 def pydoctor(ctx):
354     '''build python apidocs'''
355     bp = os.path.abspath('bin/python')
356     mpaths = {}
357     modules = ['talloc', 'tdb', 'ldb']
358     for m in modules:
359         f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
360         try:
361             mpaths[m] = f.read().strip()
362         finally:
363             f.close()
364     mpaths['main'] = bp
365     cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
366            '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
367            '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
368     cmd = cmd % mpaths
369     print("Running: %s" % cmd)
370     status = os.system(cmd)
371     if os.WEXITSTATUS(status):
372         raise Utils.WafError('pydoctor failed')
373
374
375 def pep8(ctx):
376     '''run pep8 validator'''
377     cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
378     print("Running: %s" % cmd)
379     status = os.system(cmd)
380     if os.WEXITSTATUS(status):
381         raise Utils.WafError('pep8 failed')
382
383
384 def wafdocs(ctx):
385     '''build wafsamba apidocs'''
386     from samba_utils import recursive_dirlist
387     os.system('pwd')
388     list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
389
390     cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
391     print(list)
392     for f in list:
393         cmd += ' --add-module %s' % f
394     print("Running: %s" % cmd)
395     status = os.system(cmd)
396     if os.WEXITSTATUS(status):
397         raise Utils.WafError('wafdocs failed')
398
399
400 def dist():
401     '''makes a tarball for distribution'''
402     sambaversion = samba_version.load_version(env=None)
403
404     os.system("make -C ctdb manpages")
405     samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
406
407     os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
408     samba_dist.DIST_FILES('bin/docs:docs', extend=True)
409
410     if sambaversion.IS_SNAPSHOT:
411         # write .distversion file and add to tar
412         if not os.path.isdir(blddir):
413             os.makedirs(blddir)
414         distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
415         for field in sambaversion.vcs_fields:
416             distveroption = field + '=' + str(sambaversion.vcs_fields[field])
417             distversionf.write(distveroption + '\n')
418         distversionf.flush()
419         samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
420
421         samba_dist.dist()
422         distversionf.close()
423     else:
424         samba_dist.dist()
425
426
427 def distcheck():
428     '''test that distribution tarball builds and installs'''
429     samba_version.load_version(env=None)
430     import Scripting
431     d = Scripting.distcheck
432     d()
433
434 def wildcard_cmd(cmd):
435     '''called on a unknown command'''
436     from samba_wildcard import run_named_build_task
437     run_named_build_task(cmd)
438
439 def main():
440     from samba_wildcard import wildcard_main
441
442     wildcard_main(wildcard_cmd)
443 Scripting.main = main
444
445 def reconfigure(ctx):
446     '''reconfigure if config scripts have changed'''
447     import samba_utils
448     samba_utils.reconfigure(ctx)
449
450
451 if os.path.isdir(os.path.join(srcdir, ".git")):
452     # Check if there are submodules that are checked out but out of date.
453     for submodule, status in samba_git.read_submodule_status(srcdir):
454         if status == "out-of-date":
455             raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")