# a waf tool to add autoconf-like macros to the configure section
-import Build, os, Logs, sys, Configure, Options
-import string, Task, Utils, optparse
+import Build, os, Options, preproc, Logs
+import string
from Configure import conf
-from Logs import debug
-from TaskGen import extension
from samba_utils import *
+import samba_cross
+
+missing_headers = set()
####################################################
# some autoconf like helpers, to make the transition
# to waf a bit easier for those used to autoconf
# m4 files
+
@runonce
@conf
-def DEFINE(conf, d, v):
- conf.define(d, v, quote=False)
- conf.env.append_value('CCDEFINES', d + '=' + str(v))
+def DEFINE(conf, d, v, add_to_cflags=False, quote=False):
+ '''define a config option'''
+ conf.define(d, v, quote=quote)
+ if add_to_cflags:
+ conf.env.append_value('CCDEFINES', d + '=' + str(v))
-@runonce
-def CHECK_HEADER(conf, h, add_headers=True):
- if conf.check(header_name=h) and add_headers:
- conf.env.hlist.append(h)
+def hlist_to_string(conf, headers=None):
+ '''convert a headers list to a set of #include lines'''
+ hdrs=''
+ hlist = conf.env.hlist
+ if headers:
+ hlist = hlist[:]
+ hlist.extend(TO_LIST(headers))
+ for h in hlist:
+ hdrs += '#include <%s>\n' % h
+ 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
+ the link stage of a test, thus speeding it up for tests
+ that where linking is not needed'''
+ pass
+
+
+def CHECK_HEADER(conf, h, add_headers=False, lib=None):
+ '''check for a header'''
+ if h in missing_headers:
+ return False
+ d = h.upper().replace('/', '_')
+ d = d.replace('.', '_')
+ d = 'HAVE_%s' % d
+ if CONFIG_SET(conf, d):
+ if add_headers:
+ if not h in conf.env.hlist:
+ conf.env.hlist.append(h)
return True
- return False
+
+ (ccflags, ldflags) = library_flags(conf, lib)
+
+ hdrs = hlist_to_string(conf, headers=h)
+ ret = conf.check(fragment='%s\nint main(void) { return 0; }' % hdrs,
+ type='nolink',
+ execute=0,
+ ccflags=ccflags,
+ msg="Checking for header %s" % h)
+ if not ret:
+ missing_headers.add(h)
+ return False
+
+ conf.DEFINE(d, 1)
+ if add_headers and not h in conf.env.hlist:
+ conf.env.hlist.append(h)
+ return ret
+
@conf
-def CHECK_HEADERS(conf, list, add_headers=True):
+def CHECK_HEADERS(conf, headers, add_headers=False, together=False, lib=None):
+ '''check for a list of headers
+
+ when together==True, then the headers accumulate within this test.
+ This is useful for interdependent headers
+ '''
ret = True
- for hdr in to_list(list):
- if not CHECK_HEADER(conf, hdr, add_headers):
+ if not add_headers and together:
+ saved_hlist = conf.env.hlist[:]
+ set_add_headers = True
+ else:
+ set_add_headers = add_headers
+ for hdr in TO_LIST(headers):
+ if not CHECK_HEADER(conf, hdr, set_add_headers, lib=lib):
ret = False
+ if not add_headers and together:
+ conf.env.hlist = saved_hlist
return ret
+
+def header_list(conf, headers=None, lib=None):
+ '''form a list of headers which exist, as a string'''
+ hlist=[]
+ if headers is not None:
+ for h in TO_LIST(headers):
+ if CHECK_HEADER(conf, h, add_headers=False, lib=lib):
+ hlist.append(h)
+ return hlist_to_string(conf, headers=hlist)
+
+
@conf
-def CHECK_TYPES(conf, list):
+def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None, lib=None, msg=None):
+ '''check for a single type'''
+ if define is None:
+ define = 'HAVE_' + t.upper().replace(' ', '_')
+ if msg is None:
+ msg='Checking for %s' % t
+ ret = CHECK_CODE(conf, '%s _x' % t,
+ define,
+ execute=False,
+ headers=headers,
+ local_include=False,
+ msg=msg,
+ lib=lib,
+ link=False)
+ if not ret and alternate:
+ conf.DEFINE(t, alternate)
+ return ret
+
+
+@conf
+def CHECK_TYPES(conf, list, headers=None, define=None, alternate=None, lib=None):
+ '''check for a list of types'''
ret = True
- for t in to_list(list):
- if not conf.check(type_name=t, header_name=conf.env.hlist):
+ for t in TO_LIST(list):
+ if not CHECK_TYPE(conf, t, headers=headers,
+ define=define, alternate=alternate, lib=lib):
ret = False
return ret
-@conf
-def CHECK_TYPE_IN(conf, t, hdr):
- if conf.check(header_name=hdr):
- conf.check(type_name=t, header_name=hdr)
- return True
- return False
@conf
-def CHECK_TYPE(conf, t, alternate):
- if not conf.check(type_name=t, header_name=conf.env.hlist):
- conf.DEFINE(t, alternate)
- return True
- return False
+def CHECK_TYPE_IN(conf, t, headers=None, alternate=None, define=None):
+ '''check for a single type with a header'''
+ return CHECK_TYPE(conf, t, headers=headers, alternate=alternate, define=define)
+
@conf
-def CHECK_VARIABLE(conf, v, define=None, always=False, headers=None):
- hdrs=''
- if headers is not None:
- hlist = to_list(headers)
- else:
- hlist = conf.env.hlist
- for h in hlist:
- hdrs += '#include <%s>\n' % h
+def CHECK_VARIABLE(conf, v, define=None, always=False,
+ headers=None, msg=None, lib=None):
+ '''check for a variable declaration (or define)'''
if define is None:
define = 'HAVE_%s' % v.upper()
- if conf.check(fragment=
- '''
- %s
- int main(void) {
- #ifndef %s
- void *_x; _x=(void *)&%s;
- #endif
- return 0;
- }
- ''' % (hdrs, v, v),
- execute=0,
- msg="Checking for variable %s" % v):
- conf.DEFINE(define, 1)
- return True
- elif always:
- conf.DEFINE(define, 0)
- return False
+
+ if msg is None:
+ msg="Checking for variable %s" % v
+
+ return CHECK_CODE(conf,
+ '''
+ #ifndef %s
+ void *_x; _x=(void *)&%s;
+ #endif
+ return 0
+ ''' % (v, v),
+ execute=False,
+ link=False,
+ msg=msg,
+ local_include=False,
+ lib=lib,
+ headers=headers,
+ define=define,
+ always=always)
+
@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
When reverse==True then use HAVE_xxx_DECL instead of HAVE_DECL_xxx
'''
ret = True
- for v in to_list(vars):
+ for v in TO_LIST(vars):
if not reverse:
define='HAVE_DECL_%s' % v.upper()
else:
define='HAVE_%s_DECL' % v.upper()
- if not CHECK_VARIABLE(conf, v, define=define, headers=headers):
+ if not CHECK_VARIABLE(conf, v,
+ define=define,
+ headers=headers,
+ msg='Checking for declaration of %s' % v,
+ always=always):
ret = False
return ret
-@runonce
-def CHECK_FUNC(conf, f):
- return conf.check(function_name=f, header_name=conf.env.hlist)
+def CHECK_FUNC(conf, f, link=True, lib=None, headers=None):
+ '''check for a function'''
+ define='HAVE_%s' % f.upper()
+
+ ret = False
+
+ conf.COMPOUND_START('Checking for %s' % f)
+
+ if link is None or link == True:
+ ret = CHECK_CODE(conf,
+ # 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,
+ add_headers=False,
+ define=define,
+ local_include=False,
+ lib=lib,
+ headers=headers,
+ msg='Checking for %s' % f)
+
+ if not ret:
+ ret = CHECK_CODE(conf,
+ # it might be a macro
+ 'void *__x = (void *)%s' % 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):
+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):
- if not CHECK_FUNC(conf, f):
+ for f in TO_LIST(list):
+ if not CHECK_FUNC(conf, f, link=link, lib=lib, headers=headers):
ret = False
return ret
+
@conf
def CHECK_SIZEOF(conf, vars, headers=None, define=None):
- hdrs=''
+ '''check the size of a type'''
+ ret = True
+ for v in TO_LIST(vars):
+ v_define = define
+ if v_define is None:
+ v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_')
+ if not CHECK_CODE(conf,
+ 'printf("%%u\\n", (unsigned)sizeof(%s))' % v,
+ define=v_define,
+ execute=True,
+ define_ret=True,
+ quote=False,
+ headers=headers,
+ local_include=False,
+ msg="Checking size of %s" % v):
+ ret = False
+ return ret
+
+
+
+@conf
+def CHECK_CODE(conf, code, define,
+ always=False, execute=False, addmain=True,
+ add_headers=True, mandatory=False,
+ headers=None, msg=None, cflags='', includes='# .',
+ local_include=True, lib=None, link=True,
+ define_ret=False, quote=False):
+ '''check if some code compiles and/or runs'''
+
+ if CONFIG_SET(conf, define):
+ return True
+
if headers is not None:
- hlist = to_list(headers)
+ CHECK_HEADERS(conf, headers=headers, lib=lib)
+
+ if add_headers:
+ hdrs = header_list(conf, headers=headers, lib=lib)
else:
- hlist = conf.env.hlist
- for h in hlist:
- hdrs += '#include <%s>\n' % h
- for v in to_list(vars):
- if define is None:
- define_name = 'SIZEOF_%s' % string.replace(v.upper(), ' ', '_')
- else:
- define_name = define
- conf.check(fragment=
- '''
- %s
- int main(void) {
- printf("%%u\\n", (unsigned)sizeof(%s));
- return 0;
- }
- ''' % (hdrs, v),
- execute=1,
- define_ret=True,
- define_name=define_name,
- quote=False,
- msg="Checking size of %s" % v)
-
-
-#################################################
-# return True if a configuration option was found
+ hdrs = ''
+ if execute:
+ execute = 1
+ else:
+ execute = 0
+
+ if addmain:
+ fragment='#include "__confdefs.h"\n%s\n int main(void) { %s; return 0; }\n' % (hdrs, code)
+ else:
+ fragment='#include "__confdefs.h"\n%s\n%s\n' % (hdrs, code)
+
+ conf.write_config_header('__confdefs.h', top=True)
+
+ if msg is None:
+ msg="Checking for %s" % define
+
+ # include the directory containing __confdefs.h
+ cflags += ' -I../../default'
+
+ if local_include:
+ cflags += ' -I%s' % conf.curdir
+
+ if not link:
+ type='nolink'
+ else:
+ type='cprogram'
+
+ uselib = TO_LIST(lib)
+
+ (ccflags, ldflags) = library_flags(conf, uselib)
+
+ cflags = TO_LIST(cflags)
+ cflags.extend(ccflags)
+
+ exec_args = conf.SAMBA_CROSS_ARGS()
+
+ ret = conf.check(fragment=fragment,
+ execute=execute,
+ define_name = define,
+ mandatory = mandatory,
+ ccflags=cflags,
+ ldflags=ldflags,
+ includes=includes,
+ uselib=uselib,
+ 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
+ # sets the define. Maybe a waf bug?
+ ret = True
+ if ret:
+ if not define_ret:
+ conf.DEFINE(define, 1)
+ return True
+ if always:
+ conf.DEFINE(define, 0)
+ return False
+
+
+
+@conf
+def CHECK_STRUCTURE_MEMBER(conf, structname, member,
+ always=False, define=None, headers=None):
+ '''check for a structure member'''
+ if define is None:
+ define = 'HAVE_%s' % member.upper()
+ return CHECK_CODE(conf,
+ '%s s; void *_x; _x=(void *)&s.%s' % (structname, member),
+ define,
+ execute=False,
+ link=False,
+ always=always,
+ headers=headers,
+ local_include=False,
+ msg="Checking for member %s in %s" % (member, structname))
+
+
+@conf
+def CHECK_CFLAGS(conf, cflags):
+ '''check if the given cflags are accepted by the compiler
+ '''
+ return conf.check(fragment='int main(void) { return 0; }\n',
+ execute=0,
+ type='nolink',
+ ccflags=cflags,
+ msg="Checking compiler accepts %s" % cflags)
+
+
@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
-###########################################################
-# 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):
- # first see if the functions are in libc
+def library_flags(conf, libs):
+ '''work out flags from pkg_config'''
+ ccflags = []
+ ldflags = []
+ for lib in TO_LIST(libs):
+ inc_path = None
+ inc_path = getattr(conf.env, 'CPPPATH_%s' % lib.upper(), [])
+ lib_path = getattr(conf.env, 'LIBPATH_%s' % lib.upper(), [])
+ for i in inc_path:
+ ccflags.append('-I%s' % i)
+ for l in lib_path:
+ ldflags.append('-L%s' % l)
+ return (ccflags, ldflags)
+
+
+@conf
+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) == 'SYSLIB':
+ continue
+
+ (ccflags, ldflags) = library_flags(conf, lib)
+
+ if not conf.check(lib=lib, uselib_store=lib, ccflags=ccflags, ldflags=ldflags):
+ if mandatory:
+ Logs.error("Mandatory library '%s' not found for functions '%s'" % (lib, list))
+ sys.exit(1)
+ 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)
+ conf.env['LIB_' + lib.upper()] = lib
+ LOCAL_CACHE_SET(conf, 'TARGET_TYPE', lib, 'SYSLIB')
+
+ return ret
+
+
+
+@conf
+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)
+
+ # check if some already found
+ for f in remaining[:]:
+ if CONFIG_SET(conf, 'HAVE_%s' % f.upper()):
+ remaining.remove(f)
+
+ # see if the functions are in libc
if checklibc:
- remaining = []
- for f in to_list(list):
- if not CHECK_FUNC(conf, f):
- remaining.append(f)
- else:
- remaining = to_list(list)
+ for f in remaining[:]:
+ if CHECK_FUNC(conf, f, link=True, headers=headers):
+ remaining.remove(f)
if remaining == []:
- LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
+ for lib in liblist:
+ if GET_TARGET_TYPE(conf, lib) != 'SYSLIB' and empty_decl:
+ SET_TARGET_TYPE(conf, lib, 'EMPTY')
return True
- if not conf.check(lib=library, uselib_store=library):
- conf.ASSERT(not mandatory,
- "Mandatory library '%s' not found for functions '%s'" % (library, list))
- # if it isn't a mandatory library, then remove it from dependency lists
- LOCAL_CACHE_SET(conf, 'EMPTY_TARGETS', library.upper(), True)
- return False
+ conf.CHECK_LIB(liblist, empty_decl=empty_decl)
+ for lib in liblist[:]:
+ if not GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
+ if mandatory:
+ 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)
+ continue
ret = True
for f in remaining:
- if not conf.check(function_name=f, lib=library, header_name=conf.env.hlist):
+ if not CHECK_FUNC(conf, f, lib=' '.join(liblist), headers=headers, link=link):
ret = False
- conf.env['LIB_' + library.upper()] = library
- LOCAL_CACHE_SET(conf, 'TARGET_TYPE', library, 'SYSLIB')
+
return ret
-#################################################
-# write out config.h in the right directory
+@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
+
+
@conf
def SAMBA_CONFIG_H(conf, path=None):
- if os.path.normpath(conf.curdir) != os.path.normpath(os.environ.get('PWD')):
+ '''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):
return
+
+ if Options.options.developer:
+ # we add these here to ensure that -Wstrict-prototypes is not set during configure
+ 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)
+
if path is None:
conf.write_config_header('config.h', top=True)
else:
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:
- conf.env[name] = conf.env['PREFIX'] + default
- conf.define(name, conf.env[name], quote=True)
+ if default[0] == '/':
+ conf.env[name] = default
+ else:
+ conf.env[name] = conf.env['PREFIX'] + default
-##############################################################
-# add some CFLAGS to the command line
@conf
-def ADD_CFLAGS(conf, flags):
+def ADD_CFLAGS(conf, flags, testflags=False):
+ '''add some CFLAGS to the command line
+ optionally set testflags to ensure all the flags work
+ '''
+ if testflags:
+ ok_flags=[]
+ for f in flags.split():
+ if CHECK_CFLAGS(conf, f):
+ ok_flags.append(f)
+ flags = ok_flags
if not 'EXTRA_CFLAGS' in conf.env:
conf.env['EXTRA_CFLAGS'] = []
- conf.env['EXTRA_CFLAGS'].extend(to_list(flags))
+ 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))
+ conf.env['EXTRA_INCLUDES'].extend(TO_LIST(includes))
+
-##############################################################
-# work out the current flags. local flags are added first
-def CURRENT_CFLAGS(bld, cflags):
+def CURRENT_CFLAGS(bld, target, cflags):
+ '''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 = TO_LIST(cflags)
ret.extend(list)
return ret
+
+
+@conf
+def CHECK_CC_ENV(conf):
+ """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:
+ # make for nicer logs if just a single command
+ conf.env.CC = conf.env.CC[0]
+
+
+@conf
+def SETUP_CONFIGURE_CACHE(conf, enable):
+ '''enable/disable cache of configure results'''
+ if enable:
+ # 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')
+ mkdir_p(cache_path)
+ Options.cache_global = os.environ['WAFCACHE'] = cache_path
+ else:
+ # when -C is not chosen we will not cache configure checks
+ # We set the recursion limit low to prevent waf from spending
+ # a lot of time on the signatures of the files.
+ Options.cache_global = os.environ['WAFCACHE'] = ''
+ preproc.recursion_limit = 1
+ # in either case we don't need to scan system includes
+ preproc.go_absolute = False