3 # this is a base set of waf rules that everything else pulls in first
6 from waflib
import Configure
, Logs
, Options
, Utils
, Context
, Errors
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
]
26 opt
.load('compiler_cc')
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 in order to limit the effect of 'ALL'"),
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')
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"),
133 dest
='undefined_sanitizer',
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',
198 action
='store', dest
='AUTOCONF_BUILD', default
='')
199 opt
.add_option('--host',
201 action
='store', dest
='AUTOCONF_HOST', default
='')
202 opt
.add_option('--target',
204 action
='store', dest
='AUTOCONF_TARGET', default
='')
205 opt
.add_option('--program-prefix',
207 action
='store', dest
='AUTOCONF_PROGRAM_PREFIX', default
='')
208 opt
.add_option('--disable-dependency-tracking',
210 action
='store_true', dest
='AUTOCONF_DISABLE_DEPENDENCY_TRACKING', default
=False)
211 opt
.add_option('--disable-silent-rules',
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)
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')
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
):
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(',')
272 conf
.env
.PRIVATE_VERSION
= "%s_%s_%s" % (Context
.g_module
.APPNAME
,
273 Context
.g_module
.VERSION
, conf
.env
.PRIVATE_EXTENSION
)
275 conf
.env
.CROSS_COMPILE
= Options
.options
.CROSS_COMPILE
276 conf
.env
.CROSS_EXECUTE
= Options
.options
.CROSS_EXECUTE
277 conf
.env
.CROSS_ANSWERS
= Options
.options
.CROSS_ANSWERS
278 conf
.env
.HOSTCC
= Options
.options
.HOSTCC
280 conf
.env
.AUTOCONF_BUILD
= Options
.options
.AUTOCONF_BUILD
281 conf
.env
.AUTOCONF_HOST
= Options
.options
.AUTOCONF_HOST
282 conf
.env
.AUTOCONF_PROGRAM_PREFIX
= Options
.options
.AUTOCONF_PROGRAM_PREFIX
284 conf
.env
.disable_python
= Options
.options
.disable_python
286 if (conf
.env
.AUTOCONF_HOST
and
287 conf
.env
.AUTOCONF_BUILD
and
288 conf
.env
.AUTOCONF_BUILD
!= conf
.env
.AUTOCONF_HOST
):
289 Logs
.error('ERROR: Mismatch between --build and --host. Please use --cross-compile instead')
291 if conf
.env
.AUTOCONF_PROGRAM_PREFIX
:
292 Logs
.error('ERROR: --program-prefix not supported')
295 # enable ABI checking for developers
296 conf
.env
.ABI_CHECK
= Options
.options
.ABI_CHECK
or Options
.options
.developer
297 if Options
.options
.ABI_CHECK_DISABLE
:
298 conf
.env
.ABI_CHECK
= False
300 conf
.find_program('gdb', mandatory
=True)
302 conf
.env
.ABI_CHECK
= False
304 conf
.env
.enable_coverage
= Options
.options
.enable_coverage
305 if conf
.env
.enable_coverage
:
306 conf
.ADD_LDFLAGS('-lgcov', testflags
=True)
307 conf
.ADD_CFLAGS('--coverage', testflags
=True)
308 # disable abi check for coverage, otherwise ld will fail
309 conf
.env
.ABI_CHECK
= False
311 conf
.env
.GIT_LOCAL_CHANGES
= Options
.options
.GIT_LOCAL_CHANGES
315 # see if we can compile and run a simple C program
316 conf
.CHECK_CODE('printf("hello world")',
317 define
='HAVE_SIMPLE_C_PROG',
321 msg
='Checking simple C program')
323 # Try to find the right extra flags for -Werror behaviour
324 for f
in ["-Werror", # GCC
325 "-errwarn=%all", # Sun Studio
326 "-qhalt=w", # IBM xlc
329 if conf
.CHECK_CFLAGS([f
]):
330 if not 'WERROR_CFLAGS' in conf
.env
:
331 conf
.env
['WERROR_CFLAGS'] = []
332 conf
.env
['WERROR_CFLAGS'].extend([f
])
335 # check which compiler/linker flags are needed for rpath support
336 if conf
.CHECK_LDFLAGS(['-Wl,-rpath,.']):
337 conf
.env
['RPATH_ST'] = '-Wl,-rpath,%s'
338 elif conf
.CHECK_LDFLAGS(['-Wl,-R,.']):
339 conf
.env
['RPATH_ST'] = '-Wl,-R,%s'
342 if conf
.CHECK_LIBRARY_SUPPORT(rpath
=True):
344 conf
.env
.RPATH_ON_BUILD
= not Options
.options
.disable_rpath_build
345 conf
.env
.RPATH_ON_INSTALL
= (conf
.env
.RPATH_ON_BUILD
and
346 not Options
.options
.disable_rpath_install
)
347 if not conf
.env
.PRIVATELIBDIR
:
348 conf
.env
.PRIVATELIBDIR
= '%s/%s' % (conf
.env
.LIBDIR
, Context
.g_module
.APPNAME
)
349 conf
.env
.RPATH_ON_INSTALL_PRIVATE
= (
350 not Options
.options
.disable_rpath_private_install
)
352 support_rpath
= False
353 conf
.env
.RPATH_ON_INSTALL
= False
354 conf
.env
.RPATH_ON_BUILD
= False
355 conf
.env
.RPATH_ON_INSTALL_PRIVATE
= False
356 if not conf
.env
.PRIVATELIBDIR
:
357 # rpath is not possible so there is no sense in having a
358 # private library directory by default.
359 # the user can of course always override it.
360 conf
.env
.PRIVATELIBDIR
= conf
.env
.LIBDIR
362 if (not Options
.options
.disable_symbol_versions
and
363 conf
.CHECK_LIBRARY_SUPPORT(rpath
=support_rpath
,
365 msg
='-Wl,--version-script support')):
366 conf
.env
.HAVE_LD_VERSION_SCRIPT
= True
368 conf
.env
.HAVE_LD_VERSION_SCRIPT
= False
370 if conf
.CHECK_CFLAGS(['-fvisibility=hidden']):
371 conf
.env
.VISIBILITY_CFLAGS
= '-fvisibility=hidden'
372 conf
.CHECK_CODE('''int main(void) { return 0; }
373 __attribute__((visibility("default"))) void vis_foo2(void) {}\n''',
374 cflags
=conf
.env
.VISIBILITY_CFLAGS
,
376 define
='HAVE_VISIBILITY_ATTR', addmain
=False)
378 # check HAVE_CONSTRUCTOR_ATTRIBUTE
380 void test_constructor_attribute(void) __attribute__ ((constructor));
382 void test_constructor_attribute(void)
391 'HAVE_CONSTRUCTOR_ATTRIBUTE',
394 msg
='Checking for library constructor support')
396 # check HAVE_PRAGMA_INIT alternatively
397 if not conf
.env
.HAVE_CONSTRUCTOR_ATTRIBUTE
:
399 #pragma init (test_init)
413 msg
='Checking for pragma init support')
415 # check HAVE_DESTRUCTOR_ATTRIBUTE
417 void test_destructor_attribute(void) __attribute__ ((destructor));
419 void test_destructor_attribute(void)
428 'HAVE_DESTRUCTOR_ATTRIBUTE',
431 msg
='Checking for library destructor support')
433 # check HAVE_PRAGMA_FINI alternatively
434 if not conf
.env
.HAVE_DESTRUCTOR_ATTRIBUTE
:
436 #pragma fini (test_fini)
450 msg
='Checking for pragma fini support')
453 void test_attribute(void) __attribute__ (());
455 void test_attribute(void)
464 'HAVE___ATTRIBUTE__',
467 msg
='Checking for __attribute__')
469 # Solaris by defauls uses draft versions of some functions unless you set _POSIX_PTHREAD_SEMANTICS
470 if sys
.platform
.startswith('sunos'):
471 conf
.DEFINE('_POSIX_PTHREAD_SEMANTICS', 1)
473 if sys
.platform
.startswith('aix'):
474 conf
.DEFINE('_ALL_SOURCE', 1, add_to_cflags
=True)
475 # Might not be needed if ALL_SOURCE is defined
476 # conf.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags=True)
478 # we should use the PIC options in waf instead
479 # Some compilo didn't support -fPIC but just print a warning
480 if conf
.env
['COMPILER_CC'] == "suncc":
481 conf
.ADD_CFLAGS('-KPIC', testflags
=True)
482 # we really want define here as we need to have this
483 # define even during the tests otherwise detection of
485 conf
.DEFINE('_STDC_C99', 1, add_to_cflags
=True)
486 conf
.DEFINE('_XPG6', 1, add_to_cflags
=True)
488 conf
.ADD_CFLAGS('-fPIC', testflags
=True)
490 # On Solaris 8 with suncc (at least) the flags for the linker to define the name of the
491 # library are not always working (if the command line is very very long and with a lot
494 if conf
.env
['COMPILER_CC'] == "suncc":
495 save
= conf
.env
['SONAME_ST']
496 conf
.env
['SONAME_ST'] = '-Wl,-h,%s'
497 if not conf
.CHECK_SHLIB_INTRASINC_NAME_FLAGS("Checking if flags %s are ok" % conf
.env
['SONAME_ST']):
498 conf
.env
['SONAME_ST'] = save
502 # check for pkgconfig
503 conf
.CHECK_CFG(atleast_pkgconfig_version
='0.0.0')
505 conf
.DEFINE('_GNU_SOURCE', 1, add_to_cflags
=True)
506 conf
.DEFINE('_XOPEN_SOURCE_EXTENDED', 1, add_to_cflags
=True)
509 # Needs to be defined before std*.h and string*.h are included
510 # As Python.h already brings string.h we need it in CFLAGS.
511 # See memset_s() details here:
512 # https://en.cppreference.com/w/c/string/byte/memset
514 if conf
.CHECK_CFLAGS(['-D__STDC_WANT_LIB_EXT1__=1']):
515 conf
.ADD_CFLAGS('-D__STDC_WANT_LIB_EXT1__=1')
517 # on Tru64 certain features are only available with _OSF_SOURCE set to 1
518 # and _XOPEN_SOURCE set to 600
519 if conf
.env
['SYSTEM_UNAME_SYSNAME'] == 'OSF1':
520 conf
.DEFINE('_OSF_SOURCE', 1, add_to_cflags
=True)
521 conf
.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags
=True)
523 # SCM_RIGHTS is only avail if _XOPEN_SOURCE iѕ defined on IRIX
524 if conf
.env
['SYSTEM_UNAME_SYSNAME'] == 'IRIX':
525 conf
.DEFINE('_XOPEN_SOURCE', 600, add_to_cflags
=True)
526 conf
.DEFINE('_BSD_TYPES', 1, add_to_cflags
=True)
528 # Try to find the right extra flags for C99 initialisers
529 for f
in ["", "-AC99", "-qlanglvl=extc99", "-qlanglvl=stdc99", "-c99"]:
530 if conf
.CHECK_CFLAGS([f
], '''
531 struct foo {int x;char y;};
532 struct foo bar = { .y = 'X', .x = 1 };
538 # get the base headers we'll use for the rest of the tests
539 conf
.CHECK_HEADERS('stdio.h sys/types.h sys/stat.h stdlib.h stddef.h memory.h string.h',
541 conf
.CHECK_HEADERS('strings.h inttypes.h stdint.h unistd.h minix/config.h', add_headers
=True)
542 conf
.CHECK_HEADERS('ctype.h', add_headers
=True)
544 if sys
.platform
== 'darwin':
545 conf
.DEFINE('_DARWIN_C_SOURCE', 1, add_to_cflags
=True)
546 conf
.DEFINE('_DARWIN_UNLIMITED_GETGROUPS', 1, add_to_cflags
=True)
548 conf
.CHECK_HEADERS('standards.h', add_headers
=True)
550 conf
.CHECK_HEADERS('stdbool.h stdint.h stdarg.h vararg.h', add_headers
=True)
551 conf
.CHECK_HEADERS('limits.h assert.h')
553 # see if we need special largefile flags
554 if not conf
.CHECK_LARGEFILE():
555 raise Errors
.WafError('Samba requires large file support support, but not available on this platform: sizeof(off_t) < 8')
557 if conf
.env
.HAVE_STDDEF_H
and conf
.env
.HAVE_STDLIB_H
:
558 conf
.DEFINE('STDC_HEADERS', 1)
560 conf
.CHECK_HEADERS('sys/time.h time.h', together
=True)
562 if conf
.env
.HAVE_SYS_TIME_H
and conf
.env
.HAVE_TIME_H
:
563 conf
.DEFINE('TIME_WITH_SYS_TIME', 1)
565 # cope with different extensions for libraries
566 (root
, ext
) = os
.path
.splitext(conf
.env
.cshlib_PATTERN
)
568 conf
.define('SHLIBEXT', ext
[1:], quote
=True)
570 conf
.define('SHLIBEXT', "so", quote
=True)
572 # First try a header check for cross-compile friendlyness
573 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
574 #define B __BYTE_ORDER
575 #elif defined(BYTE_ORDER)
579 #ifdef __LITTLE_ENDIAN
580 #define LITTLE __LITTLE_ENDIAN
581 #elif defined(LITTLE_ENDIAN)
582 #define LITTLE LITTLE_ENDIAN
585 #if !defined(LITTLE) || !defined(B) || LITTLE != B
586 #error Not little endian.
588 int main(void) { return 0; }\n""",
590 headers
="endian.h sys/endian.h",
591 define
="HAVE_LITTLE_ENDIAN")
592 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
593 #define B __BYTE_ORDER
594 #elif defined(BYTE_ORDER)
599 #define BIG __BIG_ENDIAN
600 #elif defined(BIG_ENDIAN)
601 #define BIG BIG_ENDIAN
604 #if !defined(BIG) || !defined(B) || BIG != B
605 #error Not big endian.
607 int main(void) { return 0; }\n""",
609 headers
="endian.h sys/endian.h",
610 define
="HAVE_BIG_ENDIAN")
612 if not conf
.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
613 # That didn't work! Do runtime test.
614 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
616 return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
617 addmain
=True, execute
=True,
618 define
='HAVE_LITTLE_ENDIAN',
619 msg
="Checking for HAVE_LITTLE_ENDIAN - runtime")
620 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
622 return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
623 addmain
=True, execute
=True,
624 define
='HAVE_BIG_ENDIAN',
625 msg
="Checking for HAVE_BIG_ENDIAN - runtime")
627 # Extra sanity check.
628 if conf
.CONFIG_SET("HAVE_BIG_ENDIAN") == conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
629 Logs
.error("Failed endian determination. The PDP-11 is back?")
632 if conf
.CONFIG_SET("HAVE_BIG_ENDIAN"):
633 conf
.DEFINE('WORDS_BIGENDIAN', 1)
635 # check if signal() takes a void function
636 if conf
.CHECK_CODE('return *(signal (0, 0)) (0) == 1',
637 define
='RETSIGTYPE_INT',
640 msg
='Checking if signal handlers return int'):
641 conf
.DEFINE('RETSIGTYPE', 'int')
643 conf
.DEFINE('RETSIGTYPE', 'void')
645 conf
.CHECK_VARIABLE('__FUNCTION__', define
='HAVE_FUNCTION_MACRO')
647 conf
.CHECK_CODE('va_list ap1,ap2; va_copy(ap1,ap2)',
648 define
="HAVE_VA_COPY",
649 msg
="Checking for va_copy")
652 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
653 eprintf("bla", "bar")
654 ''', define
='HAVE__VA_ARGS__MACRO')
656 conf
.env
.enable_fuzzing
= False
658 conf
.env
.enable_libfuzzer
= Options
.options
.enable_libfuzzer
659 conf
.env
.enable_afl_fuzzer
= Options
.options
.enable_afl_fuzzer
660 if conf
.env
.enable_libfuzzer
or conf
.env
.enable_afl_fuzzer
:
661 conf
.env
.enable_fuzzing
= True
662 conf
.DEFINE('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1)
663 conf
.env
.FUZZ_TARGET_LDFLAGS
= Options
.options
.FUZZ_TARGET_LDFLAGS
665 # Create a symlink of the compile db for clangd
666 symlink(os
.path
.join(conf
.bldnode
.abspath(), 'default/compile_commands.json'),
667 os
.path
.join(conf
.srcnode
.abspath(), 'compile_commands.json'),
670 conf
.SAMBA_BUILD_ENV()
674 # give a more useful message if the source directory has moved
675 curdir
= bld
.path
.abspath()
676 srcdir
= bld
.srcnode
.abspath()
677 relpath
= os
.path
.relpath(curdir
, srcdir
)
678 if relpath
.find('../') != -1:
679 Logs
.error('bld.path %s is not a child of %s' % (curdir
, srcdir
))
680 raise Errors
.WafError('''The top source directory has moved. Please run distclean and reconfigure''')
682 bld
.SETUP_BUILD_GROUPS()
683 bld
.ENFORCE_GROUP_ORDERING()
684 bld
.CHECK_PROJECT_RULES()