smbdotconf: add client ldap sasl wrapping = {starttls,ldaps}
[samba.git] / buildtools / wafsamba / wscript
blobe18bc4fd7416462cf8c4687a6382e708bf4669c3
1 #!/usr/bin/env python
3 # this is a base set of waf rules that everything else pulls in first
5 import os, sys
6 from waflib import Configure, Logs, Options, Utils, Context, Errors
7 import wafsamba
8 from samba_utils import symlink
9 from optparse import SUPPRESS_HELP
11 phs = os.environ.get("PYTHONHASHSEED", None)
12 if phs != "1":
13 raise Errors.WafError('''PYTHONHASHSEED=1 missing! Don't use waf directly, use ./configure and make!''')
15 # this forces configure to be re-run if any of the configure
16 # sections of the build scripts change. We have to check
17 # for this in sys.argv as options have not yet been parsed when
18 # we need to set this. This is off by default until some issues
19 # are resolved related to WAFCACHE. It will need a lot of testing
20 # before it is enabled by default.
21 if '--enable-auto-reconfigure' in sys.argv:
22 Configure.autoconfig = 'clobber'
24 def default_value(option, default=''):
25 if option in Options.options.__dict__:
26 return Options.options.__dict__[option]
27 return default
29 def options(opt):
30 opt.load('compiler_cc')
32 opt.load('gnu_dirs')
34 gr = opt.option_group('library handling options')
36 gr.add_option('--bundled-libraries',
37 help=(f'''comma separated list of bundled libraries.
39 {Context.g_module.APPNAME} includes copies of externally maintained
40 system libraries (such as popt, cmocka) as well as Samba-maintained
41 libraries that can be found on the system already (such as talloc,
42 tdb).
44 This option, most useful for packagers, controls if each library
45 should be forced to be obtained from inside Samba (bundled), forced to
46 be obtained from the system (bundling disabled, ensuing that
47 dependency errors are not silently missed) or if that choice should be
48 automatic (best for end users).
50 May include !LIBNAME to disable bundling a library.
52 Can be 'NONE' or 'ALL' [auto]'''),
53 action="store", dest='BUNDLED_LIBS', default='')
55 gr.add_option('--private-libraries',
56 help=(f'''comma separated list of normally public libraries to build instead as private libraries.
58 By default {Context.g_module.APPNAME} will publish a number of public
59 libraries for use by other software. For Samba this would include
60 libwbclient, libsmbclient and others.
62 This allows that to be disabled, to ensure that other software does
63 not use these libraries and they are placed in a private filesystem
64 prefix.
66 Likewise, it allows the value of DEFAULT (currently {','.join(Context.g_module.DEFAULT_PRIVATE_LIBS) if getattr(Context.g_module, 'DEFAULT_PRIVATE_LIBS', False) else "''"})
67 to be overridden, allowing a private-by-default library to be exposed.
69 May include !LIBNAME to disable making a library private in order to
70 limit the effect of 'ALL' and 'DEFAULT'.'''),
71 action="store", dest='PRIVATE_LIBS', default='DEFAULT')
73 extension_default = default_value('PRIVATE_EXTENSION_DEFAULT')
74 gr.add_option('--private-library-extension',
75 help=("name extension for private libraries [%s]" % extension_default),
76 action="store", dest='PRIVATE_EXTENSION', default=extension_default)
78 extension_exception = default_value('PRIVATE_EXTENSION_EXCEPTION')
79 gr.add_option('--private-extension-exception',
80 help=("comma separated list of libraries to not apply extension to [%s]" % extension_exception),
81 action="store", dest='PRIVATE_EXTENSION_EXCEPTION', default=extension_exception)
83 builtin_default = default_value('BUILTIN_LIBRARIES_DEFAULT')
84 gr.add_option('--builtin-libraries', help=(
85 f'''comma separated list of libraries to build directly into binaries.
87 By default {Context.g_module.APPNAME} will build a large number of
88 shared libraries, to reduce binary size. This overrides this
89 behaviour and essentially statically links the specified libraries into
90 each binary [{builtin_default}]'''),
91 action="store",
92 dest='BUILTIN_LIBRARIES', default=builtin_default)
94 gr.add_option('--minimum-library-version',
95 help=(
96 f'''list of minimum system library versions for otherwise bundled
97 libraries.
99 {Context.g_module.APPNAME} by default requires that, in order to match
100 what is tested in our continuous integration (CI) test-suite, that the
101 versions of libraries that we include match that found on the system,
102 before we will select not to 'bundle'.
104 This option, possibly useful for packagers, allows that specified
105 version to be overridden (say, if it is absolutely known that the
106 newer version included in this tarball has no relevant changes).
108 Use this with extreme care
110 (LIBNAME1:version,LIBNAME2:version)'''),
111 action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
113 gr.add_option('--disable-rpath',
114 help=("Disable use of rpath for build binaries"),
115 action="store_true", dest='disable_rpath_build', default=False)
116 gr.add_option('--disable-rpath-install',
117 help=("Disable use of rpath for library path in installed files"),
118 action="store_true", dest='disable_rpath_install', default=False)
119 gr.add_option('--disable-rpath-private-install',
120 help=("Disable use of rpath for private library path in installed files"),
121 action="store_true", dest='disable_rpath_private_install', default=False)
122 gr.add_option('--nonshared-binary',
123 help=(
124 f'''Disable use of shared libraries internal to {Context.g_module.APPNAME} for the listed binaries.
126 The resulting binaries are 'statically linked' with regard to components provided by
127 {Context.g_module.APPNAME}, but remain dynamically linked to (eg) libc.so and libgnutls.so
129 Currently the only tested value is 'smbtorture,smbd/smbd' for Samba'''),
130 action="store", dest='NONSHARED_BINARIES', default='')
131 gr.add_option('--disable-symbol-versions',
132 help=("Disable use of the --version-script linker option"),
133 action="store_true", dest='disable_symbol_versions', default=False)
135 opt.add_option('--with-modulesdir',
136 help=("modules directory [PREFIX/modules]"),
137 action="store", dest='MODULESDIR', default='${PREFIX}/modules')
139 opt.add_option('--with-privatelibdir',
140 help=("private library directory [PREFIX/lib/%s]" % Context.g_module.APPNAME),
141 action="store", dest='PRIVATELIBDIR', default=None)
143 opt.add_option('--with-libiconv',
144 help='additional directory to search for libiconv',
145 action='store', dest='iconv_open', default='/usr/local',
146 match = ['Checking for library iconv', 'Checking for iconv_open', 'Checking for header iconv.h'])
147 opt.add_option('--without-gettext',
148 help=("Disable use of gettext"),
149 action="store_true", dest='disable_gettext', default=False)
151 gr = opt.option_group('developer options')
153 gr.add_option('-C',
154 help='enable configure caching',
155 action='store_true', dest='enable_configure_cache')
156 gr.add_option('--enable-auto-reconfigure',
157 help='enable automatic reconfigure on build',
158 action='store_true', dest='enable_auto_reconfigure')
159 gr.add_option('--enable-debug',
160 help=("Turn on debugging symbols"),
161 action="store_true", dest='debug', default=False)
162 gr.add_option('--enable-developer',
163 help=("Turn on developer warnings and debugging"),
164 action="store_true", dest='developer', default=False)
165 gr.add_option('--pidl-developer',
166 help=("annotate PIDL-generated code for developers"),
167 action="store_true", dest='pidl_developer', default=False)
168 gr.add_option('--disable-warnings-as-errors',
169 help=("Do not treat all warnings as errors (disable -Werror)"),
170 action="store_true", dest='disable_warnings_as_errors', default=False)
171 opt.add_option('--enable-coverage',
172 help=("enable options necessary for code coverage "
173 "reporting on selftest (default=no)"),
174 action="store_true", dest='enable_coverage', default=False)
175 gr.add_option('--fatal-errors',
176 help=("Stop compilation on first error (enable -Wfatal-errors)"),
177 action="store_true", dest='fatal_errors', default=False)
178 gr.add_option('--enable-gccdeps',
179 help=("Enable use of gcc -MD dependency module"),
180 action="store_true", dest='enable_gccdeps', default=True)
181 gr.add_option('--pedantic',
182 help=("Enable even more compiler warnings"),
183 action='store_true', dest='pedantic', default=False)
184 gr.add_option('--git-local-changes',
185 help=("mark version with + if local git changes"),
186 action='store_true', dest='GIT_LOCAL_CHANGES', default=False)
187 gr.add_option('--address-sanitizer',
188 help=("Enable address sanitizer compile and linker flags"),
189 action="store_true", dest='address_sanitizer', default=False)
190 gr.add_option('--undefined-sanitizer',
191 help=("Enable undefined behaviour sanitizer compile and linker flags"),
192 action="store_true",
193 dest='undefined_sanitizer',
194 default=False)
195 gr.add_option('--memory-sanitizer',
196 help=("Enable memory behaviour sanitizer compile and linker flags"),
197 action="store_true",
198 dest='memory_sanitizer',
199 default=False)
200 gr.add_option('--enable-libfuzzer',
201 help=("Build fuzzing binaries (use ADDITIONAL_CFLAGS to specify compiler options for libFuzzer or use CC=honggfuzz/hfuzz-cc)"),
202 action="store_true", dest='enable_libfuzzer', default=False)
203 gr.add_option('--enable-afl-fuzzer',
204 help=("Build fuzzing binaries AFL-style (typically use with CC=afl-gcc)"),
205 action="store_true", dest='enable_afl_fuzzer', default=False)
207 # Fuzz targets may need additional LDFLAGS that we can't use on
208 # internal binaries like asn1_compile
210 gr.add_option('--fuzz-target-ldflags',
211 help=("Linker flags to be used when building fuzz targets"),
212 action="store", dest='FUZZ_TARGET_LDFLAGS', default='')
214 gr.add_option('--abi-check',
215 help=("Check ABI signatures for libraries"),
216 action='store_true', dest='ABI_CHECK', default=False)
217 gr.add_option('--abi-check-disable',
218 help=("Disable ABI checking (used with --enable-developer)"),
219 action='store_true', dest='ABI_CHECK_DISABLE', default=False)
220 gr.add_option('--abi-update',
221 help=("Update ABI signature files for libraries"),
222 action='store_true', dest='ABI_UPDATE', default=False)
224 gr.add_option('--show-deps',
225 help=("Show dependency tree for the given target"),
226 dest='SHOWDEPS', default='')
228 gr.add_option('--symbol-check',
229 help=("check symbols in object files against project rules"),
230 action='store_true', dest='SYMBOLCHECK', default=False)
232 gr.add_option('--dup-symbol-check',
233 help=("check for duplicate symbols in object files and system libs (must be configured with --enable-developer)"),
234 action='store_true', dest='DUP_SYMBOLCHECK', default=False)
236 gr.add_option('--why-needed',
237 help=("TARGET:DEPENDENCY check why TARGET needs DEPENDENCY"),
238 action='store', type='str', dest='WHYNEEDED', default=None)
240 gr.add_option('--show-duplicates',
241 help=("Show objects which are included in multiple binaries or libraries"),
242 action='store_true', dest='SHOW_DUPLICATES', default=False)
244 gr = opt.add_option_group('cross compilation options')
246 gr.add_option('--cross-compile',
247 help=("configure for cross-compilation"),
248 action='store_true', dest='CROSS_COMPILE', default=False)
249 gr.add_option('--cross-execute',
250 help=("command prefix to use for cross-execution in configure"),
251 action='store', dest='CROSS_EXECUTE', default='')
252 gr.add_option('--cross-answers',
253 help=("answers to cross-compilation configuration (auto modified)"),
254 action='store', dest='CROSS_ANSWERS', default='')
255 gr.add_option('--hostcc',
256 help=("set host compiler when cross compiling"),
257 action='store', dest='HOSTCC', default=False)
259 # we use SUPPRESS_HELP for these, as they are ignored, and are there only
260 # to allow existing RPM spec files to work
261 opt.add_option('--build',
262 help=SUPPRESS_HELP,
263 action='store', dest='AUTOCONF_BUILD', default='')
264 opt.add_option('--host',
265 help=SUPPRESS_HELP,
266 action='store', dest='AUTOCONF_HOST', default='')
267 opt.add_option('--target',
268 help=SUPPRESS_HELP,
269 action='store', dest='AUTOCONF_TARGET', default='')
270 opt.add_option('--program-prefix',
271 help=SUPPRESS_HELP,
272 action='store', dest='AUTOCONF_PROGRAM_PREFIX', default='')
273 opt.add_option('--disable-dependency-tracking',
274 help=SUPPRESS_HELP,
275 action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
276 opt.add_option('--disable-silent-rules',
277 help=SUPPRESS_HELP,
278 action='store_true', dest='AUTOCONF_DISABLE_SILENT_RULES', default=False)
280 gr = opt.option_group('dist options')
281 gr.add_option('--sign-release',
282 help='sign the release tarball created by waf dist',
283 action='store_true', dest='SIGN_RELEASE')
284 gr.add_option('--tag',
285 help='tag release in git at the same time',
286 type='string', action='store', dest='TAG_RELEASE')
288 opt.add_option('--disable-python',
289 help='do not generate python modules',
290 action='store_true', dest='disable_python', default=False)
293 @Utils.run_once
294 def configure(conf):
295 conf.env.hlist = []
296 conf.env.srcdir = conf.srcnode.abspath()
298 conf.define('SRCDIR', conf.env['srcdir'])
300 conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
302 # load our local waf extensions
303 conf.load('gnu_dirs')
304 conf.load('wafsamba')
306 conf.CHECK_CC_ENV()
308 conf.load('compiler_c')
310 conf.CHECK_STANDARD_LIBPATH()
312 # we need git for 'waf dist'
313 conf.find_program('git', var='GIT')
315 # older gcc versions (< 4.4) does not work with gccdeps, so we have to see if the .d file is generated
316 if Options.options.enable_gccdeps:
317 # stale file removal - the configuration may pick up the old .pyc file
318 p = os.path.join(conf.env.srcdir, 'buildtools/wafsamba/gccdeps.pyc')
319 if os.path.exists(p):
320 os.remove(p)
321 conf.load('gccdeps')
323 # make the install paths available in environment
324 conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
325 conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
326 conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
327 conf.env.MODULESDIR = Options.options.MODULESDIR
328 conf.env.PRIVATELIBDIR = Options.options.PRIVATELIBDIR
329 conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
330 conf.env.SYSTEM_LIBS = ()
332 if getattr(Context.g_module, 'DEFAULT_PRIVATE_LIBS', False):
333 conf.env.DEFAULT_PRIVATE_LIBS = Context.g_module.DEFAULT_PRIVATE_LIBS
335 conf.env.PRIVATE_LIBS = Options.options.PRIVATE_LIBS.split(',')
336 conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
337 conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
339 conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
340 conf.env.PRIVATE_EXTENSION_EXCEPTION = Options.options.PRIVATE_EXTENSION_EXCEPTION.split(',')
341 conf.env.PRIVATE_VERSION = "%s_%s_%s" % (Context.g_module.APPNAME,
342 Context.g_module.VERSION, conf.env.PRIVATE_EXTENSION)
344 conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
345 conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
346 conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
347 conf.env.HOSTCC = Options.options.HOSTCC
349 conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
350 conf.env.AUTOCONF_HOST = Options.options.AUTOCONF_HOST
351 conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
353 conf.env.disable_python = Options.options.disable_python
355 if (conf.env.AUTOCONF_HOST and
356 conf.env.AUTOCONF_BUILD and
357 conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST):
358 Logs.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
359 sys.exit(1)
360 if conf.env.AUTOCONF_PROGRAM_PREFIX:
361 Logs.error('ERROR: --program-prefix not supported')
362 sys.exit(1)
364 # enable ABI checking for developers
365 conf.env.ABI_CHECK = Options.options.ABI_CHECK or Options.options.developer
366 if Options.options.ABI_CHECK_DISABLE:
367 conf.env.ABI_CHECK = False
368 try:
369 conf.find_program('gdb', mandatory=True)
370 except:
371 conf.env.ABI_CHECK = False
373 conf.env.enable_coverage = Options.options.enable_coverage
374 if conf.env.enable_coverage:
375 conf.ADD_LDFLAGS('-lgcov', testflags=True)
376 conf.ADD_CFLAGS('--coverage', testflags=True)
377 # disable abi check for coverage, otherwise ld will fail
378 conf.env.ABI_CHECK = False
380 conf.env.GIT_LOCAL_CHANGES = Options.options.GIT_LOCAL_CHANGES
382 conf.CHECK_UNAME()
384 # see if we can compile and run a simple C program
385 conf.CHECK_CODE('printf("hello world")',
386 define='HAVE_SIMPLE_C_PROG',
387 mandatory=True,
388 execute=not conf.env.CROSS_COMPILE,
389 headers='stdio.h',
390 msg='Checking simple C program')
392 # Try to find the right extra flags for -Werror behaviour
393 for f in ["-Werror", # GCC
394 "-errwarn=%all", # Sun Studio
395 "-qhalt=w", # IBM xlc
396 "-w2", # Tru64
398 if conf.CHECK_CFLAGS([f]):
399 if not 'WERROR_CFLAGS' in conf.env:
400 conf.env['WERROR_CFLAGS'] = []
401 conf.env['WERROR_CFLAGS'].extend([f])
402 break
404 # check which compiler/linker flags are needed for rpath support
405 if conf.CHECK_LDFLAGS(['-Wl,-rpath,.']):
406 conf.env['RPATH_ST'] = '-Wl,-rpath,%s'
407 elif conf.CHECK_LDFLAGS(['-Wl,-R,.']):
408 conf.env['RPATH_ST'] = '-Wl,-R,%s'
410 # check for rpath
411 if conf.CHECK_LIBRARY_SUPPORT(rpath=True):
412 support_rpath = True
413 conf.env.RPATH_ON_BUILD = not Options.options.disable_rpath_build
414 conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
415 not Options.options.disable_rpath_install)
416 if not conf.env.PRIVATELIBDIR:
417 conf.env.PRIVATELIBDIR = '%s/%s' % (conf.env.LIBDIR, Context.g_module.APPNAME)
418 conf.env.RPATH_ON_INSTALL_PRIVATE = (
419 not Options.options.disable_rpath_private_install)
420 else:
421 support_rpath = False
422 conf.env.RPATH_ON_INSTALL = False
423 conf.env.RPATH_ON_BUILD = False
424 conf.env.RPATH_ON_INSTALL_PRIVATE = False
425 if not conf.env.PRIVATELIBDIR:
426 # rpath is not possible so there is no sense in having a
427 # private library directory by default.
428 # the user can of course always override it.
429 conf.env.PRIVATELIBDIR = conf.env.LIBDIR
431 if (not Options.options.disable_symbol_versions and
432 conf.CHECK_LIBRARY_SUPPORT(rpath=support_rpath,
433 version_script=True,
434 msg='-Wl,--version-script support')):
435 conf.env.HAVE_LD_VERSION_SCRIPT = True
436 else:
437 conf.env.HAVE_LD_VERSION_SCRIPT = False
439 if conf.CHECK_CFLAGS(['-fvisibility=hidden']):
440 conf.env.VISIBILITY_CFLAGS = '-fvisibility=hidden'
441 conf.CHECK_CODE('''int main(void) { return 0; }
442 __attribute__((visibility("default"))) void vis_foo2(void) {}\n''',
443 cflags=conf.env.VISIBILITY_CFLAGS,
444 strict=True,
445 define='HAVE_VISIBILITY_ATTR', addmain=False)
447 # check HAVE_CONSTRUCTOR_ATTRIBUTE
448 conf.CHECK_CODE('''
449 void test_constructor_attribute(void) __attribute__ ((constructor));
451 void test_constructor_attribute(void)
453 return;
456 int main(void) {
457 return 0;
459 ''',
460 'HAVE_CONSTRUCTOR_ATTRIBUTE',
461 addmain=False,
462 strict=True,
463 msg='Checking for library constructor support')
465 # check HAVE_PRAGMA_INIT alternatively
466 if not conf.env.HAVE_CONSTRUCTOR_ATTRIBUTE:
467 conf.CHECK_CODE('''
468 #pragma init (test_init)
470 void test_init(void)
472 return;
475 int main(void) {
476 return 0;
478 ''',
479 'HAVE_PRAGMA_INIT',
480 addmain=False,
481 strict=True,
482 msg='Checking for pragma init support')
484 # check HAVE_DESTRUCTOR_ATTRIBUTE
485 conf.CHECK_CODE('''
486 void test_destructor_attribute(void) __attribute__ ((destructor));
488 void test_destructor_attribute(void)
490 return;
493 int main(void) {
494 return 0;
496 ''',
497 'HAVE_DESTRUCTOR_ATTRIBUTE',
498 addmain=False,
499 strict=True,
500 msg='Checking for library destructor support')
502 # check HAVE_PRAGMA_FINI alternatively
503 if not conf.env.HAVE_DESTRUCTOR_ATTRIBUTE:
504 conf.CHECK_CODE('''
505 #pragma fini (test_fini)
507 void test_fini(void)
509 return;
512 int main(void) {
513 return 0;
515 ''',
516 'HAVE_PRAGMA_FINI',
517 addmain=False,
518 strict=True,
519 msg='Checking for pragma fini support')
521 conf.CHECK_CODE('''
522 void test_attribute(void) __attribute__ (());
524 void test_attribute(void)
526 return;
529 int main(void) {
530 return 0;
532 ''',
533 'HAVE___ATTRIBUTE__',
534 addmain=False,
535 strict=True,
536 msg='Checking for __attribute__')
538 # Solaris by default uses draft versions of some functions unless you set
539 # _POSIX_PTHREAD_SEMANTICS
540 if sys.platform.startswith('sunos'):
541 conf.DEFINE('_POSIX_PTHREAD_SEMANTICS', 1)
543 if sys.platform.startswith('aix'):
544 conf.DEFINE('_ALL_SOURCE', 1, add_to_cflags=True)
545 # Might not be needed if ALL_SOURCE is defined
546 # conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
548 # we should use the PIC options in waf instead
549 # Some compiler didn't support -fPIC but just print a warning
550 if conf.env['COMPILER_CC'] == "suncc":
551 conf.ADD_CFLAGS('-KPIC', testflags=True)
552 # we really want define here as we need to have this
553 # define even during the tests otherwise detection of
554 # boolean is broken
555 conf.DEFINE('_STDC_C99', 1, add_to_cflags=True)
556 conf.DEFINE('_XPG6', 1, add_to_cflags=True)
557 else:
558 conf.ADD_CFLAGS('-fPIC', testflags=True)
560 # On Solaris 8 with suncc (at least) the flags for the linker to define the name of the
561 # library are not always working (if the command line is very very long and with a lot
562 # of files)
564 if conf.env['COMPILER_CC'] == "suncc":
565 save = conf.env['SONAME_ST']
566 conf.env['SONAME_ST'] = '-Wl,-h,%s'
567 if not conf.CHECK_SHLIB_INTRASINC_NAME_FLAGS("Checking if flags %s are ok" % conf.env['SONAME_ST']):
568 conf.env['SONAME_ST'] = save
570 conf.CHECK_INLINE()
572 # check for pkgconfig
573 conf.CHECK_CFG(atleast_pkgconfig_version='0.0.0')
575 conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
576 conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
579 # Needs to be defined before std*.h and string*.h are included
580 # As Python.h already brings string.h we need it in CFLAGS.
581 # See memset_s() details here:
582 # https://en.cppreference.com/w/c/string/byte/memset
584 if conf.CHECK_CFLAGS(['-D__STDC_WANT_LIB_EXT1__=1']):
585 conf.ADD_CFLAGS('-D__STDC_WANT_LIB_EXT1__=1')
587 # on Tru64 certain features are only available with _OSF_SOURCE set to 1
588 # and _XOPEN_SOURCE set to 600
589 if conf.env['SYSTEM_UNAME_SYSNAME'] == 'OSF1':
590 conf.DEFINE('_OSF_SOURCE', 1, add_to_cflags=True)
591 conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
593 # SCM_RIGHTS is only avail if _XOPEN_SOURCE iѕ defined on IRIX
594 if conf.env['SYSTEM_UNAME_SYSNAME'] == 'IRIX':
595 conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
596 conf.DEFINE('_BSD_TYPES', 1, add_to_cflags=True)
598 # Try to find the right extra flags for C99 initialisers
599 for f in ["", "-AC99", "-qlanglvl=extc99", "-qlanglvl=stdc99", "-c99"]:
600 if conf.CHECK_CFLAGS([f], '''
601 struct foo {int x;char y;};
602 struct foo bar = { .y = 'X', .x = 1 };
603 '''):
604 if f != "":
605 conf.ADD_CFLAGS(f)
606 break
608 # get the base headers we'll use for the rest of the tests
609 conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
610 add_headers=True)
611 conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
612 conf.CHECK_HEADERS('ctype.h', add_headers=True)
614 if sys.platform == 'darwin':
615 conf.DEFINE('_DARWIN_C_SOURCE', 1, add_to_cflags=True)
616 conf.DEFINE('_DARWIN_UNLIMITED_GETGROUPS', 1, add_to_cflags=True)
617 else:
618 conf.CHECK_HEADERS('standards.h', add_headers=True)
620 conf.CHECK_HEADERS('stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
621 conf.CHECK_HEADERS('limits.h assert.h')
623 # see if we need special largefile flags
624 if not conf.CHECK_LARGEFILE():
625 raise Errors.WafError('Samba requires large file support, but not available on this platform: sizeof(off_t) < 8')
627 if conf.env.HAVE_STDDEF_H and conf.env.HAVE_STDLIB_H:
628 conf.DEFINE('STDC_HEADERS', 1)
630 conf.CHECK_HEADERS('sys/time.h time.h', together=True)
632 if conf.env.HAVE_SYS_TIME_H and conf.env.HAVE_TIME_H:
633 conf.DEFINE('TIME_WITH_SYS_TIME', 1)
635 # cope with different extensions for libraries
636 (root, ext) = os.path.splitext(conf.env.cshlib_PATTERN)
637 if ext[0] == '.':
638 conf.define('SHLIBEXT', ext[1:], quote=True)
639 else:
640 conf.define('SHLIBEXT', "so", quote=True)
642 # First try a header check for cross-compile friendliness
643 conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
644 #define B __BYTE_ORDER
645 #elif defined(BYTE_ORDER)
646 #define B BYTE_ORDER
647 #endif
649 #ifdef __LITTLE_ENDIAN
650 #define LITTLE __LITTLE_ENDIAN
651 #elif defined(LITTLE_ENDIAN)
652 #define LITTLE LITTLE_ENDIAN
653 #endif
655 #if !defined(LITTLE) || !defined(B) || LITTLE != B
656 #error Not little endian.
657 #endif
658 int main(void) { return 0; }\n""",
659 addmain=False,
660 headers="endian.h sys/endian.h",
661 define="HAVE_LITTLE_ENDIAN")
662 conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
663 #define B __BYTE_ORDER
664 #elif defined(BYTE_ORDER)
665 #define B BYTE_ORDER
666 #endif
668 #ifdef __BIG_ENDIAN
669 #define BIG __BIG_ENDIAN
670 #elif defined(BIG_ENDIAN)
671 #define BIG BIG_ENDIAN
672 #endif
674 #if !defined(BIG) || !defined(B) || BIG != B
675 #error Not big endian.
676 #endif
677 int main(void) { return 0; }\n""",
678 addmain=False,
679 headers="endian.h sys/endian.h",
680 define="HAVE_BIG_ENDIAN")
682 if not conf.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
683 # That didn't work! Do runtime test.
684 conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
685 u.i = 0x01020304;
686 return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
687 addmain=True, execute=True,
688 define='HAVE_LITTLE_ENDIAN',
689 msg="Checking for HAVE_LITTLE_ENDIAN - runtime")
690 conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
691 u.i = 0x01020304;
692 return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
693 addmain=True, execute=True,
694 define='HAVE_BIG_ENDIAN',
695 msg="Checking for HAVE_BIG_ENDIAN - runtime")
697 # Extra sanity check.
698 if conf.CONFIG_SET("HAVE_BIG_ENDIAN") == conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
699 Logs.error("Failed endian determination. The PDP-11 is back?")
700 sys.exit(1)
701 else:
702 if conf.CONFIG_SET("HAVE_BIG_ENDIAN"):
703 conf.DEFINE('WORDS_BIGENDIAN', 1)
705 # check if signal() takes a void function
706 if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
707 define='RETSIGTYPE_INT',
708 execute=False,
709 headers='signal.h',
710 msg='Checking if signal handlers return int'):
711 conf.DEFINE('RETSIGTYPE', 'int')
712 else:
713 conf.DEFINE('RETSIGTYPE', 'void')
715 conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
717 conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
718 define="HAVE_VA_COPY",
719 msg="Checking for va_copy")
721 conf.env.enable_fuzzing = False
723 conf.env.enable_libfuzzer = Options.options.enable_libfuzzer
724 conf.env.enable_afl_fuzzer = Options.options.enable_afl_fuzzer
725 if conf.env.enable_libfuzzer or conf.env.enable_afl_fuzzer:
726 conf.env.enable_fuzzing = True
727 conf.DEFINE('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
728 conf.env.FUZZ_TARGET_LDFLAGS = Options.options.FUZZ_TARGET_LDFLAGS
730 conf.SAMBA_BUILD_ENV()
733 def build(bld):
734 # give a more useful message if the source directory has moved
735 curdir = bld.path.abspath()
736 srcdir = bld.srcnode.abspath()
737 relpath = os.path.relpath(curdir, srcdir)
738 if relpath.find('../') != -1:
739 Logs.error('bld.path %s is not a child of %s' % (curdir, srcdir))
740 raise Errors.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
742 bld.SETUP_BUILD_GROUPS()
743 bld.ENFORCE_GROUP_ORDERING()
744 bld.CHECK_PROJECT_RULES()