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