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