waf: use _POSIX_PTHREAD_SEMANTIC on Solaris
[Samba.git] / buildtools / wafsamba / wscript
blobf68f46e03ec7b7341e4a80bebe3a44904a441d8b
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 # this forces configure to be re-run if any of the configure
12 # sections of the build scripts change. We have to check
13 # for this in sys.argv as options have not yet been parsed when
14 # we need to set this. This is off by default until some issues
15 # are resolved related to WAFCACHE. It will need a lot of testing
16 # before it is enabled by default.
17 if '--enable-auto-reconfigure' in sys.argv:
18 Configure.autoconfig = 'clobber'
20 def default_value(option, default=''):
21 if option in Options.options.__dict__:
22 return Options.options.__dict__[option]
23 return default
25 def options(opt):
26 opt.load('compiler_cc')
28 opt.load('gnu_dirs')
30 gr = opt.option_group('library handling options')
32 gr.add_option('--bundled-libraries',
33 help=("comma separated list of bundled libraries. May include !LIBNAME to disable bundling a library. Can be 'NONE' or 'ALL' [auto]"),
34 action="store", dest='BUNDLED_LIBS', default='')
36 gr.add_option('--private-libraries',
37 help=("comma separated list of normally public libraries to build instead as private libraries. May include !LIBNAME to disable making a library private. Can be 'NONE' or 'ALL' [auto]"),
38 action="store", dest='PRIVATE_LIBS', default='')
40 extension_default = default_value('PRIVATE_EXTENSION_DEFAULT')
41 gr.add_option('--private-library-extension',
42 help=("name extension for private libraries [%s]" % extension_default),
43 action="store", dest='PRIVATE_EXTENSION', default=extension_default)
45 extension_exception = default_value('PRIVATE_EXTENSION_EXCEPTION')
46 gr.add_option('--private-extension-exception',
47 help=("comma separated list of libraries to not apply extension to [%s]" % extension_exception),
48 action="store", dest='PRIVATE_EXTENSION_EXCEPTION', default=extension_exception)
50 builtin_default = default_value('BUILTIN_LIBRARIES_DEFAULT')
51 gr.add_option('--builtin-libraries',
52 help=("command separated list of libraries to build directly into binaries [%s]" % builtin_default),
53 action="store", dest='BUILTIN_LIBRARIES', default=builtin_default)
55 gr.add_option('--minimum-library-version',
56 help=("list of minimum system library versions (LIBNAME1:version,LIBNAME2:version)"),
57 action="store", dest='MINIMUM_LIBRARY_VERSION', default='')
59 gr.add_option('--disable-rpath',
60 help=("Disable use of rpath for build binaries"),
61 action="store_true", dest='disable_rpath_build', default=False)
62 gr.add_option('--disable-rpath-install',
63 help=("Disable use of rpath for library path in installed files"),
64 action="store_true", dest='disable_rpath_install', default=False)
65 gr.add_option('--disable-rpath-private-install',
66 help=("Disable use of rpath for private library path in installed files"),
67 action="store_true", dest='disable_rpath_private_install', default=False)
68 gr.add_option('--nonshared-binary',
69 help=("Disable use of shared libs for the listed binaries"),
70 action="store", dest='NONSHARED_BINARIES', default='')
71 gr.add_option('--disable-symbol-versions',
72 help=("Disable use of the --version-script linker option"),
73 action="store_true", dest='disable_symbol_versions', default=False)
75 opt.add_option('--with-modulesdir',
76 help=("modules directory [PREFIX/modules]"),
77 action="store", dest='MODULESDIR', default='${PREFIX}/modules')
79 opt.add_option('--with-privatelibdir',
80 help=("private library directory [PREFIX/lib/%s]" % Context.g_module.APPNAME),
81 action="store", dest='PRIVATELIBDIR', default=None)
83 opt.add_option('--with-libiconv',
84 help='additional directory to search for libiconv',
85 action='store', dest='iconv_open', default='/usr/local',
86 match = ['Checking for library iconv', 'Checking for iconv_open', 'Checking for header iconv.h'])
87 opt.add_option('--without-gettext',
88 help=("Disable use of gettext"),
89 action="store_true", dest='disable_gettext', default=False)
91 gr = opt.option_group('developer options')
93 gr.add_option('-C',
94 help='enable configure caching',
95 action='store_true', dest='enable_configure_cache')
96 gr.add_option('--enable-auto-reconfigure',
97 help='enable automatic reconfigure on build',
98 action='store_true', dest='enable_auto_reconfigure')
99 gr.add_option('--enable-debug',
100 help=("Turn on debugging symbols"),
101 action="store_true", dest='debug', default=False)
102 gr.add_option('--enable-developer',
103 help=("Turn on developer warnings and debugging"),
104 action="store_true", dest='developer', default=False)
105 gr.add_option('--pidl-developer',
106 help=("annotate PIDL-generated code for developers"),
107 action="store_true", dest='pidl_developer', default=False)
108 gr.add_option('--disable-warnings-as-errors',
109 help=("Do not treat all warnings as errors (disable -Werror)"),
110 action="store_true", dest='disable_warnings_as_errors', default=False)
111 opt.add_option('--enable-coverage',
112 help=("enable options necessary for code coverage "
113 "reporting on selftest (default=no)"),
114 action="store_true", dest='enable_coverage', default=False)
115 gr.add_option('--fatal-errors',
116 help=("Stop compilation on first error (enable -Wfatal-errors)"),
117 action="store_true", dest='fatal_errors', default=False)
118 gr.add_option('--enable-gccdeps',
119 help=("Enable use of gcc -MD dependency module"),
120 action="store_true", dest='enable_gccdeps', default=True)
121 gr.add_option('--pedantic',
122 help=("Enable even more compiler warnings"),
123 action='store_true', dest='pedantic', default=False)
124 gr.add_option('--git-local-changes',
125 help=("mark version with + if local git changes"),
126 action='store_true', dest='GIT_LOCAL_CHANGES', default=False)
127 gr.add_option('--address-sanitizer',
128 help=("Enable address sanitizer compile and linker flags"),
129 action="store_true", dest='address_sanitizer', default=False)
130 gr.add_option('--undefined-sanitizer',
131 help=("Enable undefined behaviour sanitizer compile and linker flags"),
132 action="store_true",
133 dest='undefined_sanitizer',
134 default=False)
135 gr.add_option('--enable-libfuzzer',
136 help=("Build fuzzing binaries (use ADDITIONAL_CFLAGS to specify compiler options for libFuzzer or use CC=honggfuzz/hfuzz-cc)"),
137 action="store_true", dest='enable_libfuzzer', default=False)
138 gr.add_option('--enable-afl-fuzzer',
139 help=("Build fuzzing binaries AFL-style (typically use with CC=afl-gcc)"),
140 action="store_true", dest='enable_afl_fuzzer', default=False)
142 # Fuzz targets may need additional LDFLAGS that we can't use on
143 # internal binaries like asn1_compile
145 gr.add_option('--fuzz-target-ldflags',
146 help=("Linker flags to be used when building fuzz targets"),
147 action="store", dest='FUZZ_TARGET_LDFLAGS', default='')
149 gr.add_option('--abi-check',
150 help=("Check ABI signatures for libraries"),
151 action='store_true', dest='ABI_CHECK', default=False)
152 gr.add_option('--abi-check-disable',
153 help=("Disable ABI checking (used with --enable-developer)"),
154 action='store_true', dest='ABI_CHECK_DISABLE', default=False)
155 gr.add_option('--abi-update',
156 help=("Update ABI signature files for libraries"),
157 action='store_true', dest='ABI_UPDATE', default=False)
159 gr.add_option('--show-deps',
160 help=("Show dependency tree for the given target"),
161 dest='SHOWDEPS', default='')
163 gr.add_option('--symbol-check',
164 help=("check symbols in object files against project rules"),
165 action='store_true', dest='SYMBOLCHECK', default=False)
167 gr.add_option('--dup-symbol-check',
168 help=("check for duplicate symbols in object files and system libs (must be configured with --enable-developer)"),
169 action='store_true', dest='DUP_SYMBOLCHECK', default=False)
171 gr.add_option('--why-needed',
172 help=("TARGET:DEPENDENCY check why TARGET needs DEPENDENCY"),
173 action='store', type='str', dest='WHYNEEDED', default=None)
175 gr.add_option('--show-duplicates',
176 help=("Show objects which are included in multiple binaries or libraries"),
177 action='store_true', dest='SHOW_DUPLICATES', default=False)
179 gr = opt.add_option_group('cross compilation options')
181 gr.add_option('--cross-compile',
182 help=("configure for cross-compilation"),
183 action='store_true', dest='CROSS_COMPILE', default=False)
184 gr.add_option('--cross-execute',
185 help=("command prefix to use for cross-execution in configure"),
186 action='store', dest='CROSS_EXECUTE', default='')
187 gr.add_option('--cross-answers',
188 help=("answers to cross-compilation configuration (auto modified)"),
189 action='store', dest='CROSS_ANSWERS', default='')
190 gr.add_option('--hostcc',
191 help=("set host compiler when cross compiling"),
192 action='store', dest='HOSTCC', default=False)
194 # we use SUPPRESS_HELP for these, as they are ignored, and are there only
195 # to allow existing RPM spec files to work
196 opt.add_option('--build',
197 help=SUPPRESS_HELP,
198 action='store', dest='AUTOCONF_BUILD', default='')
199 opt.add_option('--host',
200 help=SUPPRESS_HELP,
201 action='store', dest='AUTOCONF_HOST', default='')
202 opt.add_option('--target',
203 help=SUPPRESS_HELP,
204 action='store', dest='AUTOCONF_TARGET', default='')
205 opt.add_option('--program-prefix',
206 help=SUPPRESS_HELP,
207 action='store', dest='AUTOCONF_PROGRAM_PREFIX', default='')
208 opt.add_option('--disable-dependency-tracking',
209 help=SUPPRESS_HELP,
210 action='store_true', dest='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default=False)
211 opt.add_option('--disable-silent-rules',
212 help=SUPPRESS_HELP,
213 action='store_true', dest='AUTOCONF_DISABLE_SILENT_RULES', default=False)
215 gr = opt.option_group('dist options')
216 gr.add_option('--sign-release',
217 help='sign the release tarball created by waf dist',
218 action='store_true', dest='SIGN_RELEASE')
219 gr.add_option('--tag',
220 help='tag release in git at the same time',
221 type='string', action='store', dest='TAG_RELEASE')
223 opt.add_option('--disable-python',
224 help='do not generate python modules',
225 action='store_true', dest='disable_python', default=False)
228 @Utils.run_once
229 def configure(conf):
230 conf.env.hlist = []
231 conf.env.srcdir = conf.srcnode.abspath()
233 conf.define('SRCDIR', conf.env['srcdir'])
235 conf.SETUP_CONFIGURE_CACHE(Options.options.enable_configure_cache)
237 # load our local waf extensions
238 conf.load('gnu_dirs')
239 conf.load('wafsamba')
241 conf.CHECK_CC_ENV()
243 conf.load('compiler_c')
245 conf.CHECK_STANDARD_LIBPATH()
247 # we need git for 'waf dist'
248 conf.find_program('git', var='GIT')
250 # older gcc versions (< 4.4) does not work with gccdeps, so we have to see if the .d file is generated
251 if Options.options.enable_gccdeps:
252 # stale file removal - the configuration may pick up the old .pyc file
253 p = os.path.join(conf.env.srcdir, 'buildtools/wafsamba/gccdeps.pyc')
254 if os.path.exists(p):
255 os.remove(p)
256 conf.load('gccdeps')
258 # make the install paths available in environment
259 conf.env.LIBDIR = Options.options.LIBDIR or '${PREFIX}/lib'
260 conf.env.BINDIR = Options.options.BINDIR or '${PREFIX}/bin'
261 conf.env.SBINDIR = Options.options.SBINDIR or '${PREFIX}/sbin'
262 conf.env.MODULESDIR = Options.options.MODULESDIR
263 conf.env.PRIVATELIBDIR = Options.options.PRIVATELIBDIR
264 conf.env.BUNDLED_LIBS = Options.options.BUNDLED_LIBS.split(',')
265 conf.env.SYSTEM_LIBS = ()
266 conf.env.PRIVATE_LIBS = Options.options.PRIVATE_LIBS.split(',')
267 conf.env.BUILTIN_LIBRARIES = Options.options.BUILTIN_LIBRARIES.split(',')
268 conf.env.NONSHARED_BINARIES = Options.options.NONSHARED_BINARIES.split(',')
270 conf.env.PRIVATE_EXTENSION = Options.options.PRIVATE_EXTENSION
271 conf.env.PRIVATE_EXTENSION_EXCEPTION = Options.options.PRIVATE_EXTENSION_EXCEPTION.split(',')
273 conf.env.CROSS_COMPILE = Options.options.CROSS_COMPILE
274 conf.env.CROSS_EXECUTE = Options.options.CROSS_EXECUTE
275 conf.env.CROSS_ANSWERS = Options.options.CROSS_ANSWERS
276 conf.env.HOSTCC = Options.options.HOSTCC
278 conf.env.AUTOCONF_BUILD = Options.options.AUTOCONF_BUILD
279 conf.env.AUTOCONF_HOST = Options.options.AUTOCONF_HOST
280 conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
282 conf.env.disable_python = Options.options.disable_python
284 if (conf.env.AUTOCONF_HOST and
285 conf.env.AUTOCONF_BUILD and
286 conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST):
287 Logs.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
288 sys.exit(1)
289 if conf.env.AUTOCONF_PROGRAM_PREFIX:
290 Logs.error('ERROR: --program-prefix not supported')
291 sys.exit(1)
293 # enable ABI checking for developers
294 conf.env.ABI_CHECK = Options.options.ABI_CHECK or Options.options.developer
295 if Options.options.ABI_CHECK_DISABLE:
296 conf.env.ABI_CHECK = False
297 try:
298 conf.find_program('gdb', mandatory=True)
299 except:
300 conf.env.ABI_CHECK = False
302 conf.env.enable_coverage = Options.options.enable_coverage
303 if conf.env.enable_coverage:
304 conf.ADD_LDFLAGS('-lgcov', testflags=True)
305 conf.ADD_CFLAGS('--coverage', testflags=True)
306 # disable abi check for coverage, otherwise ld will fail
307 conf.env.ABI_CHECK = False
309 conf.env.GIT_LOCAL_CHANGES = Options.options.GIT_LOCAL_CHANGES
311 conf.CHECK_UNAME()
313 # see if we can compile and run a simple C program
314 conf.CHECK_CODE('printf("hello world")',
315 define='HAVE_SIMPLE_C_PROG',
316 mandatory=True,
317 execute=True,
318 headers='stdio.h',
319 msg='Checking simple C program')
321 # Try to find the right extra flags for -Werror behaviour
322 for f in ["-Werror", # GCC
323 "-errwarn=%all", # Sun Studio
324 "-qhalt=w", # IBM xlc
325 "-w2", # Tru64
327 if conf.CHECK_CFLAGS([f]):
328 if not 'WERROR_CFLAGS' in conf.env:
329 conf.env['WERROR_CFLAGS'] = []
330 conf.env['WERROR_CFLAGS'].extend([f])
331 break
333 # check which compiler/linker flags are needed for rpath support
334 if conf.CHECK_LDFLAGS(['-Wl,-rpath,.']):
335 conf.env['RPATH_ST'] = '-Wl,-rpath,%s'
336 elif conf.CHECK_LDFLAGS(['-Wl,-R,.']):
337 conf.env['RPATH_ST'] = '-Wl,-R,%s'
339 # check for rpath
340 if conf.CHECK_LIBRARY_SUPPORT(rpath=True):
341 support_rpath = True
342 conf.env.RPATH_ON_BUILD = not Options.options.disable_rpath_build
343 conf.env.RPATH_ON_INSTALL = (conf.env.RPATH_ON_BUILD and
344 not Options.options.disable_rpath_install)
345 if not conf.env.PRIVATELIBDIR:
346 conf.env.PRIVATELIBDIR = '%s/%s' % (conf.env.LIBDIR, Context.g_module.APPNAME)
347 conf.env.RPATH_ON_INSTALL_PRIVATE = (
348 not Options.options.disable_rpath_private_install)
349 else:
350 support_rpath = False
351 conf.env.RPATH_ON_INSTALL = False
352 conf.env.RPATH_ON_BUILD = False
353 conf.env.RPATH_ON_INSTALL_PRIVATE = False
354 if not conf.env.PRIVATELIBDIR:
355 # rpath is not possible so there is no sense in having a
356 # private library directory by default.
357 # the user can of course always override it.
358 conf.env.PRIVATELIBDIR = conf.env.LIBDIR
360 if (not Options.options.disable_symbol_versions and
361 conf.CHECK_LIBRARY_SUPPORT(rpath=support_rpath,
362 version_script=True,
363 msg='-Wl,--version-script support')):
364 conf.env.HAVE_LD_VERSION_SCRIPT = True
365 else:
366 conf.env.HAVE_LD_VERSION_SCRIPT = False
368 if conf.CHECK_CFLAGS(['-fvisibility=hidden']):
369 conf.env.VISIBILITY_CFLAGS = '-fvisibility=hidden'
370 conf.CHECK_CODE('''int main(void) { return 0; }
371 __attribute__((visibility("default"))) void vis_foo2(void) {}\n''',
372 cflags=conf.env.VISIBILITY_CFLAGS,
373 strict=True,
374 define='HAVE_VISIBILITY_ATTR', addmain=False)
376 # check HAVE_CONSTRUCTOR_ATTRIBUTE
377 conf.CHECK_CODE('''
378 void test_constructor_attribute(void) __attribute__ ((constructor));
380 void test_constructor_attribute(void)
382 return;
385 int main(void) {
386 return 0;
388 ''',
389 'HAVE_CONSTRUCTOR_ATTRIBUTE',
390 addmain=False,
391 strict=True,
392 msg='Checking for library constructor support')
394 # check HAVE_DESTRUCTOR_ATTRIBUTE
395 conf.CHECK_CODE('''
396 void test_destructor_attribute(void) __attribute__ ((destructor));
398 void test_destructor_attribute(void)
400 return;
403 int main(void) {
404 return 0;
406 ''',
407 'HAVE_DESTRUCTOR_ATTRIBUTE',
408 addmain=False,
409 strict=True,
410 msg='Checking for library destructor support')
412 conf.CHECK_CODE('''
413 void test_attribute(void) __attribute__ (());
415 void test_attribute(void)
417 return;
420 int main(void) {
421 return 0;
423 ''',
424 'HAVE___ATTRIBUTE__',
425 addmain=False,
426 strict=True,
427 msg='Checking for __attribute__')
429 # Solaris by defauls uses draft versions of some functions unless you set _POSIX_PTHREAD_SEMANTICS
430 if sys.platform.startswith('sunos'):
431 conf.DEFINE('_POSIX_PTHREAD_SEMANTICS', 1)
433 if sys.platform.startswith('aix'):
434 conf.DEFINE('_ALL_SOURCE', 1, add_to_cflags=True)
435 # Might not be needed if ALL_SOURCE is defined
436 # conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
438 # we should use the PIC options in waf instead
439 # Some compilo didn't support -fPIC but just print a warning
440 if conf.env['COMPILER_CC'] == "suncc":
441 conf.ADD_CFLAGS('-KPIC', testflags=True)
442 # we really want define here as we need to have this
443 # define even during the tests otherwise detection of
444 # boolean is broken
445 conf.DEFINE('_STDC_C99', 1, add_to_cflags=True)
446 conf.DEFINE('_XPG6', 1, add_to_cflags=True)
447 else:
448 conf.ADD_CFLAGS('-fPIC', testflags=True)
450 # On Solaris 8 with suncc (at least) the flags for the linker to define the name of the
451 # library are not always working (if the command line is very very long and with a lot
452 # files)
454 if conf.env['COMPILER_CC'] == "suncc":
455 save = conf.env['SONAME_ST']
456 conf.env['SONAME_ST'] = '-Wl,-h,%s'
457 if not conf.CHECK_SHLIB_INTRASINC_NAME_FLAGS("Checking if flags %s are ok" % conf.env['SONAME_ST']):
458 conf.env['SONAME_ST'] = save
460 conf.CHECK_INLINE()
462 # check for pkgconfig
463 conf.CHECK_CFG(atleast_pkgconfig_version='0.0.0')
465 conf.DEFINE('_GNU_SOURCE', 1, add_to_cflags=True)
466 conf.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags=True)
469 # Needs to be defined before std*.h and string*.h are included
470 # As Python.h already brings string.h we need it in CFLAGS.
471 # See memset_s() details here:
472 # https://en.cppreference.com/w/c/string/byte/memset
474 if conf.CHECK_CFLAGS(['-D__STDC_WANT_LIB_EXT1__=1']):
475 conf.ADD_CFLAGS('-D__STDC_WANT_LIB_EXT1__=1')
477 # on Tru64 certain features are only available with _OSF_SOURCE set to 1
478 # and _XOPEN_SOURCE set to 600
479 if conf.env['SYSTEM_UNAME_SYSNAME'] == 'OSF1':
480 conf.DEFINE('_OSF_SOURCE', 1, add_to_cflags=True)
481 conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
483 # SCM_RIGHTS is only avail if _XOPEN_SOURCE iѕ defined on IRIX
484 if conf.env['SYSTEM_UNAME_SYSNAME'] == 'IRIX':
485 conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
486 conf.DEFINE('_BSD_TYPES', 1, add_to_cflags=True)
488 # Try to find the right extra flags for C99 initialisers
489 for f in ["", "-AC99", "-qlanglvl=extc99", "-qlanglvl=stdc99", "-c99"]:
490 if conf.CHECK_CFLAGS([f], '''
491 struct foo {int x;char y;};
492 struct foo bar = { .y = 'X', .x = 1 };
493 '''):
494 if f != "":
495 conf.ADD_CFLAGS(f)
496 break
498 # get the base headers we'll use for the rest of the tests
499 conf.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
500 add_headers=True)
501 conf.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers=True)
502 conf.CHECK_HEADERS('ctype.h', add_headers=True)
504 if sys.platform != 'darwin':
505 conf.CHECK_HEADERS('standards.h', add_headers=True)
507 conf.CHECK_HEADERS('stdbool.h stdint.h stdarg.h vararg.h', add_headers=True)
508 conf.CHECK_HEADERS('limits.h assert.h')
510 # see if we need special largefile flags
511 if not conf.CHECK_LARGEFILE():
512 raise Errors.WafError('Samba requires large file support support, but not available on this platform: sizeof(off_t) < 8')
514 if conf.env.HAVE_STDDEF_H and conf.env.HAVE_STDLIB_H:
515 conf.DEFINE('STDC_HEADERS', 1)
517 conf.CHECK_HEADERS('sys/time.h time.h', together=True)
519 if conf.env.HAVE_SYS_TIME_H and conf.env.HAVE_TIME_H:
520 conf.DEFINE('TIME_WITH_SYS_TIME', 1)
522 # cope with different extensions for libraries
523 (root, ext) = os.path.splitext(conf.env.cshlib_PATTERN)
524 if ext[0] == '.':
525 conf.define('SHLIBEXT', ext[1:], quote=True)
526 else:
527 conf.define('SHLIBEXT', "so", quote=True)
529 # First try a header check for cross-compile friendlyness
530 conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
531 #define B __BYTE_ORDER
532 #elif defined(BYTE_ORDER)
533 #define B BYTE_ORDER
534 #endif
536 #ifdef __LITTLE_ENDIAN
537 #define LITTLE __LITTLE_ENDIAN
538 #elif defined(LITTLE_ENDIAN)
539 #define LITTLE LITTLE_ENDIAN
540 #endif
542 #if !defined(LITTLE) || !defined(B) || LITTLE != B
543 #error Not little endian.
544 #endif
545 int main(void) { return 0; }\n""",
546 addmain=False,
547 headers="endian.h sys/endian.h",
548 define="HAVE_LITTLE_ENDIAN")
549 conf.CHECK_CODE(code = """#ifdef __BYTE_ORDER
550 #define B __BYTE_ORDER
551 #elif defined(BYTE_ORDER)
552 #define B BYTE_ORDER
553 #endif
555 #ifdef __BIG_ENDIAN
556 #define BIG __BIG_ENDIAN
557 #elif defined(BIG_ENDIAN)
558 #define BIG BIG_ENDIAN
559 #endif
561 #if !defined(BIG) || !defined(B) || BIG != B
562 #error Not big endian.
563 #endif
564 int main(void) { return 0; }\n""",
565 addmain=False,
566 headers="endian.h sys/endian.h",
567 define="HAVE_BIG_ENDIAN")
569 if not conf.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
570 # That didn't work! Do runtime test.
571 conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
572 u.i = 0x01020304;
573 return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
574 addmain=True, execute=True,
575 define='HAVE_LITTLE_ENDIAN',
576 msg="Checking for HAVE_LITTLE_ENDIAN - runtime")
577 conf.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
578 u.i = 0x01020304;
579 return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
580 addmain=True, execute=True,
581 define='HAVE_BIG_ENDIAN',
582 msg="Checking for HAVE_BIG_ENDIAN - runtime")
584 # Extra sanity check.
585 if conf.CONFIG_SET("HAVE_BIG_ENDIAN") == conf.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
586 Logs.error("Failed endian determination. The PDP-11 is back?")
587 sys.exit(1)
588 else:
589 if conf.CONFIG_SET("HAVE_BIG_ENDIAN"):
590 conf.DEFINE('WORDS_BIGENDIAN', 1)
592 # check if signal() takes a void function
593 if conf.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
594 define='RETSIGTYPE_INT',
595 execute=False,
596 headers='signal.h',
597 msg='Checking if signal handlers return int'):
598 conf.DEFINE('RETSIGTYPE', 'int')
599 else:
600 conf.DEFINE('RETSIGTYPE', 'void')
602 conf.CHECK_VARIABLE('__FUNCTION__', define='HAVE_FUNCTION_MACRO')
604 conf.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
605 define="HAVE_VA_COPY",
606 msg="Checking for va_copy")
608 conf.CHECK_CODE('''
609 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
610 eprintf("bla", "bar")
611 ''', define='HAVE__VA_ARGS__MACRO')
613 conf.env.enable_fuzzing = False
615 conf.env.enable_libfuzzer = Options.options.enable_libfuzzer
616 conf.env.enable_afl_fuzzer = Options.options.enable_afl_fuzzer
617 if conf.env.enable_libfuzzer or conf.env.enable_afl_fuzzer:
618 conf.env.enable_fuzzing = True
619 conf.DEFINE('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
620 conf.env.FUZZ_TARGET_LDFLAGS = Options.options.FUZZ_TARGET_LDFLAGS
622 conf.load('clang_compilation_database')
624 # Create a symlink of the compile db for clangd
625 symlink(os.path.join(conf.bldnode.abspath(), 'default/compile_commands.json'),
626 os.path.join(conf.srcnode.abspath(), 'compile_commands.json'),
627 force=True)
629 conf.SAMBA_BUILD_ENV()
632 def build(bld):
633 # give a more useful message if the source directory has moved
634 curdir = bld.path.abspath()
635 srcdir = bld.srcnode.abspath()
636 relpath = os.path.relpath(curdir, srcdir)
637 if relpath.find('../') != -1:
638 Logs.error('bld.path %s is not a child of %s' % (curdir, srcdir))
639 raise Errors.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
641 bld.SETUP_BUILD_GROUPS()
642 bld.ENFORCE_GROUP_ORDERING()
643 bld.CHECK_PROJECT_RULES()