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