ldb: Honour --private-library=!ldb as meaning build as a public library
[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 from waflib.Tools import bison
15
16 samba_dist.DIST_DIRS('.')
17 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
18
19 DEFAULT_PRIVATE_LIBS = ["ldb"]
20
21 # install in /usr/local/samba by default
22 default_prefix = Options.default_prefix = '/usr/local/samba'
23
24 # This callback optionally takes a list of paths as arguments:
25 # --with-system_mitkrb5 /path/to/krb5 /another/path
26 def system_mitkrb5_callback(option, opt, value, parser):
27     setattr(parser.values, option.dest, True)
28     value = []
29     for arg in parser.rargs:
30         # stop on --foo like options
31         if arg[:2] == "--" and len(arg) > 2:
32             break
33         value.append(arg)
34     if len(value)>0:
35         del parser.rargs[:len(value)]
36         setattr(parser.values, option.dest, value)
37
38 def options(opt):
39     opt.BUILTIN_DEFAULT('NONE')
40     opt.PRIVATE_EXTENSION_DEFAULT('private-samba')
41     opt.RECURSE('lib/replace')
42     opt.RECURSE('dynconfig')
43     opt.RECURSE('packaging')
44     opt.RECURSE('lib/ldb')
45     opt.RECURSE('selftest')
46     opt.RECURSE('source4/dsdb/samdb/ldb_modules')
47     opt.RECURSE('pidl')
48     opt.RECURSE('source3')
49     opt.RECURSE('lib/util')
50     opt.RECURSE('ctdb')
51
52 # Optional Libraries
53 # ------------------
54 #
55 # Most of the calls to opt.add_option() use default=True for the --with case
56 #
57 # To assist users and distributors to build Samba with the full feature
58 # set, the build system will abort if our dependent libraries and their
59 # header files are not found on the target system.  This will mean for
60 # example, that xattr, acl and ldap headers must be installed for the
61 # default build to complete.  The configure system will check for these
62 # headers, and the error message will indicate the option (such as
63 # --without-acl-support) that can be specified to skip this requirement.
64 #
65 # This will assist users and in particular distributors in building fully
66 # functional packages, while allowing those on systems truly without these
67 # facilities to continue to build Samba after careful consideration.
68 #
69 # It also ensures our container image generation in bootstrap/ is correct
70 # as otherwise a missing package there would just silently work
71
72     opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
73
74     opt.add_option('--with-system-mitkrb5',
75                    help='build Samba with system MIT Kerberos. ' +
76                         'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
77                    action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
78
79     opt.add_option('--with-experimental-mit-ad-dc',
80                    help='Enable the experimental MIT Kerberos-backed AD DC.  ' +
81                    'Note that security patches are not issued for this configuration',
82                    action='store_true',
83                    dest='with_experimental_mit_ad_dc',
84                    default=False)
85
86     opt.add_option('--with-system-mitkdc',
87                    help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
88                    type="string",
89                    dest='with_system_mitkdc',
90                    default=None)
91
92     opt.add_option('--with-system-heimdalkrb5',
93                    help=('build Samba with system Heimdal Kerberos. ' +
94                          'Requires --without-ad-dc' and
95                          'conflicts with --with-system-mitkrb5'),
96                    action='store_true',
97                    dest='with_system_heimdalkrb5',
98                    default=False)
99
100     opt.add_option('--without-ad-dc',
101                    help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
102                    action='store_true', dest='without_ad_dc', default=False)
103
104     opt.add_option('--with-pie',
105                   help=("Build Position Independent Executables " +
106                         "(default if supported by compiler)"),
107                   action="store_true", dest='enable_pie')
108     opt.add_option('--without-pie',
109                   help=("Disable Position Independent Executable builds"),
110                   action="store_false", dest='enable_pie')
111
112     opt.add_option('--with-relro',
113                   help=("Build with full RELocation Read-Only (RELRO)" +
114                         "(default if supported by compiler)"),
115                   action="store_true", dest='enable_relro')
116     opt.add_option('--without-relro',
117                   help=("Disable RELRO builds"),
118                   action="store_false", dest='enable_relro')
119
120     opt.add_option('--with-kernel-keyring',
121                   help=('Enable kernely keyring support for credential storage ' +
122                         '(default if keyutils libraries are available)'),
123                   action='store_true', dest='enable_keyring')
124     opt.add_option('--without-kernel-keyring',
125                   help=('Disable kernely keyring support for credential storage'),
126                   action='store_false', dest='enable_keyring')
127
128     opt.option_group('developer options')
129
130     opt.load('python') # options for disabling pyc or pyo compilation
131     # enable options related to building python extensions
132
133     opt.add_option('--with-json',
134                    action='store_true', dest='with_json',
135                    help=("Build with JSON support (default=True). This "
136                          "requires the jansson development headers."))
137     opt.add_option('--without-json',
138                    action='store_false', dest='with_json',
139                    help=("Build without JSON support."))
140
141     opt.samba_add_onoff_option('smb1-server',
142                                dest='with_smb1server',
143                                help=("Build smbd with SMB1 support (default=yes)."))
144
145 def configure(conf):
146     version = samba_version.load_version(env=conf.env)
147
148     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
149     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
150     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
151
152     if Options.options.developer:
153         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
154         conf.env.DEVELOPER = True
155         # if we are in a git tree without a pre-commit hook, install a
156         # simple default.
157         # we need git for 'waf dist'
158         githooksdir = None
159         conf.find_program('git', var='GIT')
160         if 'GIT' in conf.env:
161             githooksdir = conf.CHECK_COMMAND('%s rev-parse --git-path hooks' % conf.env.GIT[0],
162                                msg='Finding githooks directory',
163                                define=None,
164                                on_target=False)
165         if githooksdir and os.path.isdir(githooksdir):
166             pre_commit_hook = os.path.join(githooksdir, 'pre-commit')
167             if not os.path.exists(pre_commit_hook):
168                 Logs.info("Installing script/git-hooks/pre-commit-hook as %s" %
169                           pre_commit_hook)
170                 shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
171                             pre_commit_hook)
172
173     conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
174
175     conf.env.replace_add_global_pthread = True
176     conf.RECURSE('lib/replace')
177
178     conf.RECURSE('examples/fuse')
179     conf.RECURSE('examples/winexe')
180
181     conf.SAMBA_CHECK_PERL(mandatory=True)
182     conf.find_program('xsltproc', var='XSLTPROC')
183
184     if conf.env.disable_python:
185         if not (Options.options.without_ad_dc):
186             raise Errors.WafError('--disable-python requires --without-ad-dc')
187
188     conf.SAMBA_CHECK_PYTHON()
189     conf.SAMBA_CHECK_PYTHON_HEADERS()
190
191     if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
192         # Mac OSX needs to have this and it's also needed that the python is compiled with this
193         # otherwise you face errors about common symbols
194         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
195             conf.ADD_CFLAGS('-fno-common')
196         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
197             conf.env.append_value('cshlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
198
199     if sys.platform == 'darwin':
200         conf.ADD_LDFLAGS('-framework CoreFoundation')
201
202     conf.RECURSE('dynconfig')
203     conf.RECURSE('selftest')
204
205     conf.PROCESS_SEPARATE_RULE('system_gnutls')
206
207     conf.CHECK_CFG(package='zlib', minversion='1.2.3',
208                    args='--cflags --libs',
209                    mandatory=True)
210     conf.CHECK_FUNCS_IN('inflateInit2', 'z')
211
212     if Options.options.enable_keyring is not False:
213         conf.env['WITH_KERNEL_KEYRING'] = 'auto'
214         if Options.options.enable_keyring is True:
215             conf.env['WITH_KERNEL_KEYRING'] = True
216     else:
217         conf.env['WITH_KERNEL_KEYRING'] = False
218
219     if conf.CHECK_FOR_THIRD_PARTY():
220         conf.RECURSE('third_party')
221     else:
222
223         if not conf.CHECK_POPT():
224             raise Errors.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
225         else:
226             conf.define('USING_SYSTEM_POPT', 1)
227
228         if not conf.CHECK_CMOCKA():
229             raise Errors.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
230         else:
231             conf.define('USING_SYSTEM_CMOCKA', 1)
232
233         if conf.CONFIG_GET('ENABLE_SELFTEST'):
234             if not conf.CHECK_SOCKET_WRAPPER():
235                 raise Errors.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
236             else:
237                 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
238
239             if not conf.CHECK_NSS_WRAPPER():
240                 raise Errors.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
241             else:
242                 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
243
244             if not conf.CHECK_RESOLV_WRAPPER():
245                 raise Errors.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
246             else:
247                 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
248
249             if not conf.CHECK_UID_WRAPPER():
250                 raise Errors.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
251             else:
252                 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
253
254             if not conf.CHECK_PAM_WRAPPER():
255                 raise Errors.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
256             else:
257                 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
258
259     conf.RECURSE('lib/ldb')
260
261     if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
262         conf.env['HAVE_LDWRAP'] = True
263         conf.define('HAVE_LDWRAP', 1)
264
265     if not (Options.options.without_ad_dc):
266         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
267
268     # Check for flex before doing the embedded heimdal checks so we can bail if we don't have it.
269     Logs.info("Checking for flex")
270     conf.find_program('flex', var='FLEX')
271     if conf.env['FLEX']:
272         conf.CHECK_COMMAND('%s --version' % conf.env.FLEX[0],
273                            msg='Using flex version',
274                            define=None,
275                            on_target=False)
276     conf.env.FLEXFLAGS = ['-t']
277
278     # #line statements in these generated files cause issues for lcov
279     conf.env.FLEXFLAGS += ["--noline"]
280
281     Logs.info("Checking for bison")
282     bison.configure(conf)
283     if conf.env['BISON']:
284         conf.CHECK_COMMAND('%s --version  | head -n1' % conf.env.BISON[0],
285                            msg='Using bison version',
286                            define=None,
287                            on_target=False)
288
289     # #line statements in these generated files cause issues for lcov
290     conf.env.BISONFLAGS += ["--no-line"]
291
292     if Options.options.with_system_mitkrb5:
293         if not Options.options.with_experimental_mit_ad_dc and \
294            not Options.options.without_ad_dc:
295             raise Errors.WafError('The MIT Kerberos build of Samba as an AD DC ' +
296                                   'is experimental. Therefore '
297                                   '--with-system-mitkrb5 requires either ' +
298                                   '--with-experimental-mit-ad-dc or ' +
299                                   '--without-ad-dc')
300
301         conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
302
303     if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
304         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
305
306     if Options.options.with_system_heimdalkrb5:
307         if Options.options.with_system_mitkrb5:
308             raise Errors.WafError('--with-system-heimdalkrb5 conflicts with ' +
309                                   '--with-system-mitkrb5')
310         if not Options.options.without_ad_dc:
311             raise Errors.WafError('--with-system-heimdalkrb5 requires ' +
312                                   '--without-ad-dc')
313         conf.env.SYSTEM_LIBS += ('heimdal', 'asn1', 'com_err', 'roken',
314                                  'hx509', 'wind', 'gssapi', 'hcrypto',
315                                  'krb5', 'heimbase', 'asn1_compile',
316                                  'compile_et', 'kdc', 'hdb', 'heimntlm')
317         conf.PROCESS_SEPARATE_RULE('system_heimdal')
318
319     if not conf.CONFIG_GET('KRB5_VENDOR'):
320         conf.PROCESS_SEPARATE_RULE('embedded_heimdal')
321
322     conf.RECURSE('source4/dsdb/samdb/ldb_modules')
323     conf.RECURSE('source4/ntvfs/sysdep')
324     conf.RECURSE('lib/util')
325     conf.RECURSE('lib/util/charset')
326     conf.RECURSE('source4/auth')
327     conf.RECURSE('nsswitch')
328     conf.RECURSE('libcli/smbreadline')
329     conf.RECURSE('pidl')
330     if conf.CONFIG_GET('ENABLE_SELFTEST'):
331         if not (Options.options.without_ad_dc):
332             conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
333         conf.RECURSE('testsuite/unittests')
334
335     if Options.options.with_pthreadpool:
336         if conf.CONFIG_SET('HAVE_PTHREAD'):
337             conf.DEFINE('WITH_PTHREADPOOL', '1')
338         else:
339             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
340             conf.undefine('WITH_PTHREADPOOL')
341
342     conf.SET_TARGET_TYPE('jansson', 'EMPTY')
343
344     if Options.options.with_json is not False:
345         if conf.CHECK_CFG(package='jansson', args='--cflags --libs',
346                           msg='Checking for jansson'):
347             conf.CHECK_FUNCS_IN('json_object', 'jansson')
348
349     if not conf.CONFIG_GET('HAVE_JSON_OBJECT'):
350         if Options.options.with_json is not False:
351             conf.fatal("Jansson JSON support not found. "
352                        "Try installing libjansson-dev or jansson-devel. "
353                        "Otherwise, use --without-json to build without "
354                        "JSON support. "
355                        "JSON support is required for the JSON "
356                        "formatted audit log feature, the AD DC, and "
357                        "the JSON printers of the net utility")
358         if not Options.options.without_ad_dc:
359             raise Errors.WafError('--without-json requires --without-ad-dc. '
360                                  'Jansson JSON library is required for '
361                                  'building the AD DC')
362         Logs.info("Building without Jansson JSON log support")
363
364     conf.RECURSE('source3')
365     conf.RECURSE('lib/texpect')
366     conf.RECURSE('lib/tsocket')
367     conf.RECURSE('python')
368     if conf.env.with_ctdb:
369         conf.RECURSE('ctdb')
370     conf.RECURSE('lib/socket')
371     conf.RECURSE('lib/mscat')
372     conf.RECURSE('packaging')
373     conf.RECURSE('lib/krb5_wrap')
374
375     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
376
377     # gentoo always adds this. We want our normal build to be as
378     # strict as the strictest OS we support, so adding this here
379     # allows us to find problems on our development hosts faster.
380     # It also results in faster load time.
381
382     if (not Options.options.address_sanitizer
383         and conf.CHECK_LDFLAGS('-Wl,--as-needed')):
384         conf.env.append_unique('LINKFLAGS', '-Wl,--as-needed')
385
386     if not conf.CHECK_NEED_LC("-lc not needed"):
387         conf.ADD_LDFLAGS('-lc', testflags=False)
388
389     if not conf.CHECK_CODE('#include "tests/summary.c"',
390                            define='SUMMARY_PASSES',
391                            addmain=False,
392                            msg='Checking configure summary'):
393         raise Errors.WafError('configure summary failed')
394
395     if Options.options.enable_pie is not False:
396         if Options.options.enable_pie is True:
397                 need_pie = True
398         else:
399                 # not specified, only build PIEs if supported by compiler
400                 need_pie = False
401         if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
402                          msg="Checking compiler for PIE support"):
403             conf.env['ENABLE_PIE'] = True
404
405     if Options.options.enable_relro is not False:
406         if Options.options.enable_relro is True:
407             need_relro = True
408         else:
409             # not specified, only build RELROs if supported by compiler
410             need_relro = False
411         if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
412                          msg="Checking compiler for full RELRO support"):
413             conf.env['ENABLE_RELRO'] = True
414
415     if conf.CONFIG_GET('ENABLE_SELFTEST') and \
416        Options.options.with_smb1server is False and \
417        Options.options.without_ad_dc is not True:
418         conf.fatal('--without-smb1-server cannot be specified with '
419                    '--enable-selftest/--enable-developer if '
420                    '--without-ad-dc is NOT set!')
421
422     if Options.options.with_smb1server is not False:
423         conf.DEFINE('WITH_SMB1SERVER', '1')
424
425     #
426     # FreeBSD is broken. It doesn't include 'extern char **environ'
427     # in any shared library, but statically inside crt0.o.
428     #
429     # If we're running on a FreeBSD with the GNU linker ld we
430     # can get around this by explicitly telling the linker to
431     # ignore 'environ' as an unresolved symbol in a shared library.
432     #
433     # However, the clang linker ld.lld-XX is broken in that it
434     # doesn't have that option.
435     #
436     # First try to see if have '-Wl,--ignore-unresolved-symbol,environ'
437     # and just use that if so.
438     #
439     # If not, we have to use '-Wl,--allow-shlib-undefined' instead
440     # and remove all instances of '-Wl,-no-undefined'.
441
442     if sys.platform.startswith('freebsd'):
443         # Do we have Wl,--ignore-unresolved-symbol,environ ?
444         flag_added = conf.ADD_LDFLAGS('-Wl,--ignore-unresolved-symbol,environ', testflags=True)
445         if not flag_added:
446             # No, fall back to -Wl,--allow-shlib-undefined.
447             conf.ADD_LDFLAGS('-Wl,--allow-shlib-undefined', testflags=True)
448             # Remove any uses of '-Wl,-no-undefined'
449             conf.env['EXTRA_LDFLAGS'] = list(filter(('-Wl,-no-undefined').__ne__, conf.env['EXTRA_LDFLAGS']))
450             # And make sure we don't try and remove it again when 'allow_undefined_symbols=true'
451             conf.env.undefined_ldflags = []
452
453     conf.SAMBA_CONFIG_H('include/config.h')
454
455 def etags(ctx):
456     '''build TAGS file using etags'''
457     source_root = os.path.dirname(Context.g_module.root_path)
458     cmd = r'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
459     print("Running: %s" % cmd)
460     status = os.system(cmd)
461     if os.WEXITSTATUS(status):
462         raise Errors.WafError('etags failed')
463
464 def ctags(ctx):
465     "build 'tags' file using ctags"
466     source_root = os.path.dirname(Context.g_module.root_path)
467     cmd = r'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
468     print("Running: %s" % cmd)
469     status = os.system(cmd)
470     if os.WEXITSTATUS(status):
471         raise Errors.WafError('ctags failed')
472
473
474 # putting this here enabled build in the list
475 # of commands in --help
476 def build(bld):
477     '''build all targets'''
478     samba_version.load_version(env=bld.env, is_install=bld.is_install)
479
480
481 def pep8(ctx):
482     '''run pep8 validator'''
483     cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
484     print("Running: %s" % cmd)
485     status = os.system(cmd)
486     if os.WEXITSTATUS(status):
487         raise Errors.WafError('pep8 failed')
488
489
490 def dist():
491     '''makes a tarball for distribution'''
492     sambaversion = samba_version.load_version(env=None)
493
494     os.system("make -C ctdb manpages")
495     samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
496
497     os.system("DOC_VERSION='" + sambaversion.STRING + "' " + Context.g_module.top + "/release-scripts/build-manpages-nogit")
498     samba_dist.DIST_FILES('bin/docs:docs', extend=True)
499
500     if sambaversion.IS_SNAPSHOT:
501         # write .distversion file and add to tar
502         if not os.path.isdir(Context.g_module.out):
503             os.makedirs(Context.g_module.out)
504         distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=Context.g_module.out)
505         for field in sambaversion.vcs_fields:
506             distveroption = field + '=' + str(sambaversion.vcs_fields[field])
507             distversionf.write(distveroption + '\n')
508         distversionf.flush()
509         samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
510
511         samba_dist.dist()
512         distversionf.close()
513     else:
514         samba_dist.dist()
515
516
517 def distcheck():
518     '''test that distribution tarball builds and installs'''
519     samba_version.load_version(env=None)
520
521 def printversion(ctx):
522     '''print version'''
523     ver = samba_version.load_version(env=None)
524     print('Samba Version: ' + ver.STRING_WITH_NICKNAME)
525
526 def wildcard_cmd(cmd):
527     '''called on a unknown command'''
528     from samba_wildcard import run_named_build_task
529     run_named_build_task(cmd)
530
531 def main():
532     from samba_wildcard import wildcard_main
533
534     wildcard_main(wildcard_cmd)
535 Scripting.main = main
536
537 def reconfigure(ctx):
538     '''reconfigure if config scripts have changed'''
539     samba_utils.reconfigure(ctx)
540
541
542 if os.path.isdir(os.path.join(top, ".git")):
543     # Check if there are submodules that are checked out but out of date.
544     for submodule, status in samba_git.read_submodule_status(top):
545         if status == "out-of-date":
546             raise Errors.WafError("some submodules are out of date. Please run 'git submodule update'")