# a waf tool to add autoconf-like macros to the configure section
-import Build, os, Options, preproc
+import Build, os, Options, preproc, Logs
import string
from Configure import conf
from samba_utils import *
+import samba_cross
missing_headers = set()
return hdrs
+@conf
+def COMPOUND_START(conf, msg):
+ '''start a compound test'''
+ def null_check_message_1(self,*k,**kw):
+ return
+ def null_check_message_2(self,*k,**kw):
+ return
+
+ v = getattr(conf.env, 'in_compound', [])
+ 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.env.in_compound = 1
+
+
+@conf
+def COMPOUND_END(conf, result):
+ '''start a compound test'''
+ 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
+ if result == True:
+ p('ok ')
+ elif result == False:
+ p('not found', 'YELLOW')
+ else:
+ p(result)
+
+
@feature('nolink')
def nolink(self):
'''using the nolink type in conf.check() allows us to avoid
msg="Checking for variable %s" % v
return CHECK_CODE(conf,
+ # we need to make sure the compiler doesn't
+ # optimize it out...
'''
#ifndef %s
- void *_x; _x=(void *)&%s;
+ void *_x; _x=(void *)&%s; return (int)_x;
#endif
return 0
''' % (v, v),
@conf
-def CHECK_DECLS(conf, vars, reverse=False, headers=None):
+def CHECK_DECLS(conf, vars, reverse=False, headers=None, always=False):
'''check a list of variable declarations, using the HAVE_DECL_xxx form
of define
if not CHECK_VARIABLE(conf, v,
define=define,
headers=headers,
- msg='Checking for declaration of %s' % v):
+ msg='Checking for declaration of %s' % v,
+ always=always):
ret = False
return ret
-def CHECK_FUNC(conf, f, link=None, lib=None, headers=None):
+def CHECK_FUNC(conf, f, link=True, lib=None, headers=None):
'''check for a function'''
define='HAVE_%s' % f.upper()
- # there are two ways to find a function. The first is
- # to see if there is a declaration of the function, the
- # 2nd is to try and link a program that calls the function
- # unfortunately both strategies have problems.
- # the 'check the declaration' approach works fine as long
- # as the function has a declaraion in a header. If there is
- # no header declaration we can get a false negative.
- # The link method works fine as long as the compiler
- # doesn't have a builtin for the function, which could cause
- # a false negative due to mismatched parameters
- # so to be sure, we need to try both
ret = False
+ conf.COMPOUND_START('Checking for %s' % f)
+
if link is None or link == True:
ret = CHECK_CODE(conf,
- 'int main(void) { extern void %s(void); %s(); return 0; }' % (f, f),
+ # this is based on the autoconf strategy
+ '''
+ #define %s __fake__%s
+ #ifdef HAVE_LIMITS_H
+ # include <limits.h>
+ #else
+ # include <assert.h>
+ #endif
+ #undef %s
+ #if defined __stub_%s || defined __stub___%s
+ #error "bad glibc stub"
+ #endif
+ extern char %s();
+ int main() { return %s(); }
+ ''' % (f, f, f, f, f, f, f),
execute=False,
link=True,
addmain=False,
headers=headers,
msg='Checking for %s' % f)
+ if not ret:
+ ret = CHECK_CODE(conf,
+ # it might be a macro
+ # we need to make sure the compiler doesn't
+ # optimize it out...
+ 'void *__x = (void *)%s; return (int)__x' % f,
+ execute=False,
+ link=True,
+ addmain=True,
+ add_headers=True,
+ define=define,
+ local_include=False,
+ lib=lib,
+ headers=headers,
+ msg='Checking for macro %s' % f)
+
if not ret and (link is None or link == False):
ret = CHECK_VARIABLE(conf, f,
define=define,
headers=headers,
msg='Checking for declaration of %s' % f)
+ conf.COMPOUND_END(ret)
return ret
@conf
-def CHECK_FUNCS(conf, list, link=None, lib=None, headers=None):
+def CHECK_FUNCS(conf, list, link=True, lib=None, headers=None):
'''check for a list of functions'''
ret = True
for f in TO_LIST(list):
cflags = TO_LIST(cflags)
cflags.extend(ccflags)
+ exec_args = conf.SAMBA_CROSS_ARGS()
+
ret = conf.check(fragment=fragment,
execute=execute,
define_name = define,
type=type,
msg=msg,
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
msg="Checking compiler accepts %s" % cflags)
-#################################################
-# return True if a configuration option was found
@conf
def CONFIG_SET(conf, option):
+ '''return True if a configuration option was found'''
return (option in conf.env) and (conf.env[option] != ())
Build.BuildContext.CONFIG_SET = CONFIG_SET
@conf
-def CHECK_LIB(conf, libs, mandatory=False):
+def CHECK_LIB(conf, libs, mandatory=False, empty_decl=True):
'''check if a set of libraries exist'''
liblist = TO_LIST(libs)
ret = True
for lib in liblist[:]:
- if GET_TARGET_TYPE(conf, lib):
+ if GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
continue
(ccflags, ldflags) = library_flags(conf, lib)
if not conf.check(lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags):
if mandatory:
- print("Mandatory library '%s' not found for functions '%s'" % (lib, list))
+ Logs.error("Mandatory library '%s' not found for functions '%s'" % (lib, list))
sys.exit(1)
- # if it isn't a mandatory library, then remove it from dependency lists
- SET_TARGET_TYPE(conf, lib, 'EMPTY')
+ if empty_decl:
+ # if it isn't a mandatory library, then remove it from dependency lists
+ SET_TARGET_TYPE(conf, lib, 'EMPTY')
ret = False
else:
conf.define('HAVE_LIB%s' % lib.upper().replace('-','_'), 1)
return ret
-###########################################################
-# check that the functions in 'list' are available in 'library'
-# if they are, then make that library available as a dependency
-#
-# if the library is not available and mandatory==True, then
-# raise an error.
-#
-# If the library is not available and mandatory==False, then
-# add the library to the list of dependencies to remove from
-# build rules
-#
-# optionally check for the functions first in libc
+
@conf
-def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False, headers=None, link=None):
+def CHECK_FUNCS_IN(conf, list, library, mandatory=False, checklibc=False,
+ headers=None, link=True, empty_decl=True):
+ """
+ check that the functions in 'list' are available in 'library'
+ if they are, then make that library available as a dependency
+
+ if the library is not available and mandatory==True, then
+ raise an error.
+
+ If the library is not available and mandatory==False, then
+ add the library to the list of dependencies to remove from
+ build rules
+
+ optionally check for the functions first in libc
+ """
remaining = TO_LIST(list)
liblist = TO_LIST(library)
if remaining == []:
for lib in liblist:
- if GET_TARGET_TYPE(conf, lib) != 'SYSLIB':
+ if GET_TARGET_TYPE(conf, lib) != 'SYSLIB' and empty_decl:
SET_TARGET_TYPE(conf, lib, 'EMPTY')
return True
- conf.CHECK_LIB(liblist)
+ conf.CHECK_LIB(liblist, empty_decl=empty_decl)
for lib in liblist[:]:
if not GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
if mandatory:
- print("Mandatory library '%s' not found for functions '%s'" % (lib, list))
+ Logs.error("Mandatory library '%s' not found for functions '%s'" % (lib, list))
sys.exit(1)
# if it isn't a mandatory library, then remove it from dependency lists
liblist.remove(lib)
return ret
+
@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
-#################################################
-# write out config.h in the right directory
@conf
def SAMBA_CONFIG_H(conf, path=None):
+ '''write out config.h in the right directory'''
# we don't want to produce a config.h in places like lib/replace
# when we are building projects that depend on lib/replace
if not IN_LAUNCH_DIR(conf):
if Options.options.developer:
# we add these here to ensure that -Wstrict-prototypes is not set during configure
- conf.ADD_CFLAGS('-Wall -g -Wfatal-errors -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k',
+ conf.ADD_CFLAGS('-Wall -g -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Werror-implicit-function-declaration -Wformat=2 -Wno-format-y2k',
testflags=True)
+ if Options.options.picky_developer:
+ conf.ADD_CFLAGS('-Werror', testflags=True)
+
+ if Options.options.fatal_errors:
+ conf.ADD_CFLAGS('-Wfatal-errors', testflags=True)
+
if Options.options.pedantic:
- conf.ADD_CFLAGS('-W', testflags=True)
+ conf.ADD_CFLAGS('-W', testflags=True)
if path is None:
conf.write_config_header('config.h', top=True)
conf.write_config_header(path)
-##############################################################
-# setup a configurable path
@conf
def CONFIG_PATH(conf, name, default):
+ '''setup a configurable path'''
if not name in conf.env:
if default[0] == '/':
conf.env[name] = default
else:
conf.env[name] = conf.env['PREFIX'] + default
- conf.define(name, conf.env[name], quote=True)
-
@conf
def ADD_CFLAGS(conf, flags, testflags=False):
conf.env['EXTRA_CFLAGS'].extend(TO_LIST(flags))
-##############################################################
-# add some extra include directories to all builds
+
@conf
def ADD_EXTRA_INCLUDES(conf, includes):
+ '''add some extra include directories to all builds'''
if not 'EXTRA_INCLUDES' in conf.env:
conf.env['EXTRA_INCLUDES'] = []
conf.env['EXTRA_INCLUDES'].extend(TO_LIST(includes))
-##############################################################
-# work out the current flags. local flags are added first
-def CURRENT_CFLAGS(bld, target, cflags):
+
+def CURRENT_CFLAGS(bld, target, cflags, hide_symbols=False):
+ '''work out the current flags. local flags are added first'''
if not 'EXTRA_CFLAGS' in bld.env:
list = []
else:
list = bld.env['EXTRA_CFLAGS'];
ret = TO_LIST(cflags)
ret.extend(list)
+ if hide_symbols and bld.env.HAVE_VISIBILITY_ATTR:
+ ret.append('-fvisibility=hidden')
return ret
@conf
def CHECK_CC_ENV(conf):
- '''trim whitespaces from 'CC'.
- The build farm sometimes puts a space at the start'''
+ """trim whitespaces from 'CC'.
+ 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: