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
def CHECK_INLINE(conf): '''check for the right value for inline''' conf.COMPOUND_START('Checking for inline') for i in ['inline', '__inline__', '__inline']: ret = conf.CHECK_CODE(''' typedef int foo_t; static %s foo_t static_foo () {return 0; } %s foo_t foo () {return 0; }''' % (i, i), define='INLINE_MACRO', addmain=False, link=False) if ret: if i != 'inline': conf.DEFINE('inline', i, quote=False) break if not ret: conf.COMPOUND_END(ret) else: conf.COMPOUND_END(i) return ret
def CHECK_SAMBA3_CHARSET(conf, crossbuild=False): '''Check for default charsets for Samba3 ''' if conf.CHECK_ICONV(define='HAVE_NATIVE_ICONV'): default_dos_charset = False default_display_charset = False default_unix_charset = False # check for default dos charset name for charset in ['CP850', 'IBM850']: if conf.CHECK_CHARSET_EXISTS(charset, headers='iconv.h'): default_dos_charset = charset break # check for default display charset name for charset in ['ASCII', '646']: if conf.CHECK_CHARSET_EXISTS(charset, headers='iconv.h'): default_display_charset = charset break # check for default unix charset name for charset in ['UTF-8', 'UTF8']: if conf.CHECK_CHARSET_EXISTS(charset, headers='iconv.h'): default_unix_charset = charset break # At this point, we have a libiconv candidate. We know that # we have the right headers and libraries, but we don't know # whether it does the conversions we want. We can't test this # because we are cross-compiling. This is not necessarily a big # deal, since we can't guarantee that the results we get now will # match the results we get at runtime anyway. if crossbuild: default_dos_charset = "CP850" default_display_charset = "ASCII" default_unix_charset = "UTF-8" # TODO: this used to warn about the set charset on cross builds conf.DEFINE('DEFAULT_DOS_CHARSET', default_dos_charset, quote=True) conf.DEFINE('DEFAULT_DISPLAY_CHARSET', default_display_charset, quote=True) conf.DEFINE('DEFAULT_UNIX_CHARSET', default_unix_charset, quote=True) else: conf.DEFINE('DEFAULT_DOS_CHARSET', "ASCII", quote=True) conf.DEFINE('DEFAULT_DISPLAY_CHARSET', "ASCII", quote=True) conf.DEFINE('DEFAULT_UNIX_CHARSET', "UTF8", quote=True)
def CHECK_SIZEOF(conf, vars, headers=None, define=None, critical=True): '''check the size of a type''' for v in TO_LIST(vars): v_define = define ret = False if v_define is None: v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_') for size in list((1, 2, 4, 8, 16, 32)): if CHECK_CODE(conf, 'static int test_array[1 - 2 * !(((long int)(sizeof(%s))) <= %d)];' % (v, size), define=v_define, quote=False, headers=headers, local_include=False, msg="Checking if size of %s == %d" % (v, size)): conf.DEFINE(v_define, size) ret = True break if not ret and critical: Logs.error("Couldn't determine size of '%s'" % v) sys.exit(1) return ret
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, on_target=True): '''check if some code compiles and/or runs''' if CONFIG_SET(conf, define): return True if headers is not None: CHECK_HEADERS(conf, headers=headers, lib=lib) if add_headers: hdrs = header_list(conf, headers=headers, lib=lib) else: hdrs = '' if execute: execute = 1 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) else: fragment = '%s\n%s\n%s\n' % (defs, hdrs, code) if msg is None: msg = "Checking for %s" % define cflags = TO_LIST(cflags) if local_include: cflags.append('-I%s' % conf.curdir) if not link: type = 'nolink' else: type = 'cprogram' uselib = TO_LIST(lib) (ccflags, ldflags, cpppath) = library_flags(conf, uselib) includes = TO_LIST(includes) includes.extend(cpppath) uselib = [l.upper() for l in uselib] cflags.extend(ccflags) if on_target: exec_args = conf.SAMBA_CROSS_ARGS(msg=msg) else: exec_args = [] conf.COMPOUND_START(msg) 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) conf.COMPOUND_END(True) else: conf.COMPOUND_END(conf.env[define]) return True if always: conf.DEFINE(define, 0) conf.COMPOUND_END(False) return False