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