# a waf tool to add autoconf-like macros to the configure section
import os, sys
-import Build, Options, preproc, Logs
-from Configure import conf
-from TaskGen import feature
+from waflib import Build, Options, Logs, Context
+from waflib.Configure import conf
+from waflib.TaskGen import feature
+from waflib.Tools import c_preproc as preproc
from samba_utils import TO_LIST, GET_TARGET_TYPE, SET_TARGET_TYPE, unique_list, mkdir_p
missing_headers = set()
'''define a config option'''
conf.define(d, v, quote=quote)
if add_to_cflags:
- conf.env.append_value('CCDEFINES', d + '=' + str(v))
+ conf.env.append_value('CFLAGS', '-D%s=%s' % (d, str(v)))
def hlist_to_string(conf, headers=None):
'''convert a headers list to a set of #include lines'''
if v != [] and v != 0:
conf.env.in_compound = v + 1
return
- conf.check_message_1(msg)
- conf.saved_check_message_1 = conf.check_message_1
- conf.check_message_1 = null_check_message_1
- conf.saved_check_message_2 = conf.check_message_2
- conf.check_message_2 = null_check_message_2
+ conf.start_msg(msg)
+ conf.saved_check_message_1 = conf.start_msg
+ conf.start_msg = null_check_message_1
+ conf.saved_check_message_2 = conf.end_msg
+ conf.end_msg = null_check_message_2
conf.env.in_compound = 1
conf.env.in_compound -= 1
if conf.env.in_compound != 0:
return
- conf.check_message_1 = conf.saved_check_message_1
- conf.check_message_2 = conf.saved_check_message_2
- p = conf.check_message_2
+ conf.start_msg = conf.saved_check_message_1
+ conf.end_msg = conf.saved_check_message_2
+ p = conf.end_msg
if result is True:
p('ok')
elif not result:
hdrs = hlist_to_string(conf, headers=h)
if lib is None:
lib = ""
- ret = conf.check(fragment='%s\nint main(void) { return 0; }' % hdrs,
+ ret = conf.check(fragment='%s\nint main(void) { return 0; }\n' % hdrs,
type='nolink',
execute=0,
- ccflags=ccflags,
+ cflags=ccflags,
mandatory=False,
includes=cpppath,
uselib=lib.upper(),
ret = False
if v_define is None:
v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_')
- for size in list((1, 2, 4, 8, 16, 32)):
+ for size in list((1, 2, 4, 8, 16, 32, 64)):
if CHECK_CODE(conf,
'static int test_array[1 - 2 * !(((long int)(sizeof(%s))) <= %d)];' % (v, size),
define=v_define,
headers=None, msg=None, cflags='', includes='# .',
local_include=True, lib=None, link=True,
define_ret=False, quote=False,
- on_target=True):
+ on_target=True, strict=False):
'''check if some code compiles and/or runs'''
if CONFIG_SET(conf, define):
else:
execute = 0
- defs = conf.get_config_header()
-
if addmain:
- fragment='%s\n%s\n int main(void) { %s; return 0; }\n' % (defs, hdrs, code)
+ fragment='%s\n int main(void) { %s; return 0; }\n' % (hdrs, code)
else:
- fragment='%s\n%s\n%s\n' % (defs, hdrs, code)
+ fragment='%s\n%s\n' % (hdrs, code)
if msg is None:
msg="Checking for %s" % define
cflags = TO_LIST(cflags)
+ # Be strict when relying on a compiler check
+ # Some compilers (e.g. xlc) ignore non-supported features as warnings
+ if strict:
+ if 'WERROR_CFLAGS' in conf.env:
+ cflags.extend(conf.env['WERROR_CFLAGS'])
+
if local_include:
- cflags.append('-I%s' % conf.curdir)
+ cflags.append('-I%s' % conf.path.abspath())
if not link:
type='nolink'
conf.COMPOUND_START(msg)
- ret = conf.check(fragment=fragment,
+ try:
+ ret = conf.check(fragment=fragment,
execute=execute,
define_name = define,
- mandatory = mandatory,
- ccflags=cflags,
+ cflags=cflags,
ldflags=ldflags,
includes=includes,
uselib=uselib,
quote=quote,
exec_args=exec_args,
define_ret=define_ret)
- if not ret and CONFIG_SET(conf, define):
- # sometimes conf.check() returns false, but it
- # sets the define. Maybe a waf bug?
- ret = True
- if ret:
+ except Exception:
+ if always:
+ conf.DEFINE(define, 0)
+ else:
+ conf.undefine(define)
+ conf.COMPOUND_END(False)
+ if mandatory:
+ raise
+ return False
+ else:
+ # Success is indicated by ret but we should unset
+ # defines set by WAF's c_config.check() because it
+ # defines it to int(ret) and we want to undefine it
+ if not ret:
+ conf.undefine(define)
+ conf.COMPOUND_END(False)
+ return False
if not define_ret:
conf.DEFINE(define, 1)
conf.COMPOUND_END(True)
else:
- conf.COMPOUND_END(conf.env[define])
+ conf.DEFINE(define, ret, quote=quote)
+ conf.COMPOUND_END(ret)
return True
- if always:
- conf.DEFINE(define, 0)
- conf.COMPOUND_END(False)
- return False
-
@conf
def CHECK_STRUCTURE_MEMBER(conf, structname, member,
- always=False, define=None, headers=None):
+ always=False, define=None, headers=None,
+ lib=None):
'''check for a structure member'''
if define is None:
define = 'HAVE_%s' % member.upper()
define,
execute=False,
link=False,
+ lib=lib,
always=always,
headers=headers,
local_include=False,
def CHECK_CFLAGS(conf, cflags, fragment='int main(void) { return 0; }\n'):
'''check if the given cflags are accepted by the compiler
'''
+ check_cflags = TO_LIST(cflags)
+ if 'WERROR_CFLAGS' in conf.env:
+ check_cflags.extend(conf.env['WERROR_CFLAGS'])
return conf.check(fragment=fragment,
execute=0,
+ mandatory=False,
type='nolink',
- ccflags=cflags,
+ cflags=check_cflags,
msg="Checking compiler accepts %s" % cflags)
@conf
# note that we do not add the -I and -L in here, as that is added by the waf
# core. Adding it here would just change the order that it is put on the link line
# which can cause system paths to be added before internal libraries
- extra_ccflags = TO_LIST(getattr(self.env, 'CCFLAGS_%s' % lib.upper(), []))
+ extra_ccflags = TO_LIST(getattr(self.env, 'CFLAGS_%s' % lib.upper(), []))
extra_ldflags = TO_LIST(getattr(self.env, 'LDFLAGS_%s' % lib.upper(), []))
extra_cpppath = TO_LIST(getattr(self.env, 'CPPPATH_%s' % lib.upper(), []))
ccflags.extend(extra_ccflags)
ldflags.extend(extra_ldflags)
cpppath.extend(extra_cpppath)
+
+ extra_cpppath = TO_LIST(getattr(self.env, 'INCLUDES_%s' % lib.upper(), []))
+ cpppath.extend(extra_cpppath)
if 'EXTRA_LDFLAGS' in self.env:
ldflags.extend(self.env['EXTRA_LDFLAGS'])
(ccflags, ldflags, cpppath) = library_flags(conf, lib)
if shlib:
- res = conf.check(features='c cshlib', fragment=fragment, lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)
+ res = conf.check(features='c cshlib', fragment=fragment, lib=lib, uselib_store=lib, cflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)
else:
- res = conf.check(lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)
+ res = conf.check(lib=lib, uselib_store=lib, cflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)
if not res:
if mandatory:
@conf
def IN_LAUNCH_DIR(conf):
'''return True if this rule is being run from the launch directory'''
- return os.path.realpath(conf.curdir) == os.path.realpath(Options.launch_dir)
-Options.Handler.IN_LAUNCH_DIR = IN_LAUNCH_DIR
+ return os.path.realpath(conf.path.abspath()) == os.path.realpath(Context.launch_dir)
+Options.OptionsContext.IN_LAUNCH_DIR = IN_LAUNCH_DIR
@conf
return
# we need to build real code that can't be optimized away to test
- if conf.check(fragment='''
- #include <stdio.h>
-
- int main(void)
- {
- char t[100000];
- while (fgets(t, sizeof(t), stdin));
- return 0;
- }
- ''',
- execute=0,
- ccflags='-fstack-protector',
- ldflags='-fstack-protector',
- mandatory=False,
- msg='Checking if toolchain accepts -fstack-protector'):
- conf.ADD_CFLAGS('-fstack-protector')
- conf.ADD_LDFLAGS('-fstack-protector')
+ stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
+ for stack_protect_flag in stack_protect_list:
+ flag_supported = conf.check(fragment='''
+ #include <stdio.h>
+
+ int main(void)
+ {
+ char t[100000];
+ while (fgets(t, sizeof(t), stdin));
+ return 0;
+ }
+ ''',
+ execute=0,
+ cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
+ mandatory=False,
+ msg='Checking if compiler accepts %s' % (stack_protect_flag))
+ if flag_supported:
+ conf.ADD_CFLAGS('%s' % (stack_protect_flag))
+ break
+
+ flag_supported = conf.check(fragment='''
+ #include <stdio.h>
+
+ int main(void)
+ {
+ char t[100000];
+ while (fgets(t, sizeof(t), stdin));
+ return 0;
+ }
+ ''',
+ execute=0,
+ cflags=[ '-Werror', '-fstack-clash-protection'],
+ mandatory=False,
+ msg='Checking if compiler accepts -fstack-clash-protection')
+ if flag_supported:
+ conf.ADD_CFLAGS('-fstack-clash-protection')
if Options.options.debug:
conf.ADD_CFLAGS('-g', testflags=True)
testflags=True)
conf.ADD_CFLAGS('-Werror=uninitialized -Wuninitialized',
testflags=True)
+ conf.ADD_CFLAGS('-Wimplicit-fallthrough',
+ testflags=True)
+ conf.ADD_CFLAGS('-Werror=strict-overflow -Wstrict-overflow=2',
+ testflags=True)
conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
+ conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
+ conf.ADD_CFLAGS('-Werror=format-security -Wformat-security',
+ testflags=True, prereq_flags='-Wformat')
# This check is because for ldb_search(), a NULL format string
# is not an error, but some compilers complain about that.
if CHECK_CFLAGS(conf, ["-Werror=format", "-Wformat=2"], '''
if Options.options.picky_developer:
conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Werror -Wno-error=deprecated-declarations', testflags=True)
+ conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=tautological-compare', testflags=True)
if Options.options.fatal_errors:
conf.ADD_CFLAGS('-Wfatal-errors', testflags=True)
conf.env['EXTRA_LDFLAGS'].extend(conf.env['ADDITIONAL_LDFLAGS'])
if path is None:
- conf.write_config_header('config.h', top=True)
+ conf.write_config_header('default/config.h', top=True, remove=False)
else:
- conf.write_config_header(path)
+ conf.write_config_header(os.path.join(conf.variant, path), remove=False)
+ for key in conf.env.define_key:
+ conf.undefine(key, from_env=False)
+ conf.env.define_key = []
conf.SAMBA_CROSS_CHECK_COMPLETE()
conf.env[name] = conf.env['PREFIX'] + default
@conf
-def ADD_NAMED_CFLAGS(conf, name, flags, testflags=False):
+def ADD_NAMED_CFLAGS(conf, name, flags, testflags=False, prereq_flags=[]):
'''add some CFLAGS to the command line
optionally set testflags to ensure all the flags work
'''
+ prereq_flags = TO_LIST(prereq_flags)
if testflags:
ok_flags=[]
for f in flags.split():
- if CHECK_CFLAGS(conf, f):
+ if CHECK_CFLAGS(conf, [f] + prereq_flags):
ok_flags.append(f)
flags = ok_flags
if not name in conf.env:
conf.env[name].extend(TO_LIST(flags))
@conf
-def ADD_CFLAGS(conf, flags, testflags=False):
+def ADD_CFLAGS(conf, flags, testflags=False, prereq_flags=[]):
'''add some CFLAGS to the command line
optionally set testflags to ensure all the flags work
'''
- ADD_NAMED_CFLAGS(conf, 'EXTRA_CFLAGS', flags, testflags=testflags)
+ ADD_NAMED_CFLAGS(conf, 'EXTRA_CFLAGS', flags, testflags=testflags,
+ prereq_flags=prereq_flags)
@conf
def ADD_LDFLAGS(conf, flags, testflags=False):
The build farm sometimes puts a space at the start"""
if os.environ.get('CC'):
conf.env.CC = TO_LIST(os.environ.get('CC'))
- if len(conf.env.CC) == 1:
- # make for nicer logs if just a single command
- conf.env.CC = conf.env.CC[0]
@conf
# when -C is chosen, we will use a private cache and will
# not look into system includes. This roughtly matches what
# autoconf does with -C
- cache_path = os.path.join(conf.blddir, '.confcache')
+ cache_path = os.path.join(conf.bldnode.abspath(), '.confcache')
mkdir_p(cache_path)
Options.cache_global = os.environ['WAFCACHE'] = cache_path
else:
if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']):
conf.env.undefined_ignore_ldflags = ['-undefined', 'dynamic_lookup']
-@conf
-def CHECK_CFG(self, *k, **kw):
- return self.check_cfg(*k, **kw)