Ejemplo n.º 1
0
def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
    '''see what we need for largefile support'''
    getconf_cflags = conf.CHECK_COMMAND(['getconf', 'LFS_CFLAGS'])
    if getconf_cflags is not False:
        if (conf.CHECK_CODE(
                'return !(sizeof(off_t) >= 8)',
                define='WORKING_GETCONF_LFS_CFLAGS',
                execute=True,
                cflags=getconf_cflags,
                msg='Checking getconf large file support flags work')):
            conf.ADD_CFLAGS(getconf_cflags)
            getconf_cflags_list = TO_LIST(getconf_cflags)
            for flag in getconf_cflags_list:
                if flag[:2] == "-D":
                    flag_split = flag[2:].split('=')
                    if len(flag_split) == 1:
                        conf.DEFINE(flag_split[0], '1')
                    else:
                        conf.DEFINE(flag_split[0], flag_split[1])

    if conf.CHECK_CODE(
            'return !(sizeof(off_t) >= 8)',
            define,
            execute=True,
            msg='Checking for large file support without additional flags'):
        return True

    if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
                       define,
                       execute=True,
                       cflags='-D_FILE_OFFSET_BITS=64',
                       msg='Checking for -D_FILE_OFFSET_BITS=64'):
        conf.DEFINE('_FILE_OFFSET_BITS', 64)
        return True

    if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
                       define,
                       execute=True,
                       cflags='-D_LARGE_FILES',
                       msg='Checking for -D_LARGE_FILES'):
        conf.DEFINE('_LARGE_FILES', 1)
        return True
    return False
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):
        return

    # we need to build real code that can't be optimized away to test
    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)

    if Options.options.pidl_developer:
        conf.env.PIDL_DEVELOPER_MODE = True

    if Options.options.developer:
        conf.env.DEVELOPER_MODE = True

        conf.ADD_CFLAGS('-g', testflags=True)
        conf.ADD_CFLAGS('-Wall', testflags=True)
        conf.ADD_CFLAGS('-Wshadow', testflags=True)
        conf.ADD_CFLAGS('-Wmissing-prototypes', testflags=True)
        if CHECK_CODE(
                conf,
                'struct a { int b; }; struct c { struct a d; } e = { };',
                'CHECK_C99_INIT',
                link=False,
                cflags=
                '-Wmissing-field-initializers -Werror=missing-field-initializers',
                msg="Checking C99 init of nested structs."):
            conf.ADD_CFLAGS('-Wmissing-field-initializers', testflags=True)
        conf.ADD_CFLAGS('-Wformat-overflow=2', testflags=True)
        conf.ADD_CFLAGS('-Wformat-zero-length', testflags=True)
        conf.ADD_CFLAGS('-Wcast-align -Wcast-qual', testflags=True)
        conf.ADD_CFLAGS('-fno-common', testflags=True)

        conf.ADD_CFLAGS('-Werror=address', testflags=True)
        # we add these here to ensure that -Wstrict-prototypes is not set during configure
        conf.ADD_CFLAGS('-Werror=strict-prototypes -Wstrict-prototypes',
                        testflags=True)
        conf.ADD_CFLAGS('-Werror=write-strings -Wwrite-strings',
                        testflags=True)
        conf.ADD_CFLAGS('-Werror-implicit-function-declaration',
                        testflags=True)
        conf.ADD_CFLAGS('-Werror=pointer-arith -Wpointer-arith',
                        testflags=True)
        conf.ADD_CFLAGS(
            '-Werror=declaration-after-statement -Wdeclaration-after-statement',
            testflags=True)
        conf.ADD_CFLAGS('-Werror=return-type -Wreturn-type', 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"], '''
int testformat(char *format, ...) __attribute__ ((format (__printf__, 1, 2)));

int main(void) {
        testformat(0);
        return 0;
}

'''):
            if not 'EXTRA_CFLAGS' in conf.env:
                conf.env['EXTRA_CFLAGS'] = []
            conf.env['EXTRA_CFLAGS'].extend(TO_LIST("-Werror=format"))

        if not Options.options.disable_warnings_as_errors:
            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)
            conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS',
                                  '-Wno-error=cast-align',
                                  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 (Options.options.address_sanitizer
            or Options.options.undefined_sanitizer):
        conf.ADD_CFLAGS('-g -O1', testflags=True)
    if Options.options.address_sanitizer:
        conf.ADD_CFLAGS('-fno-omit-frame-pointer', testflags=True)
        conf.ADD_CFLAGS('-fsanitize=address', testflags=True)
        conf.ADD_LDFLAGS('-fsanitize=address', testflags=True)
        conf.env['ADDRESS_SANITIZER'] = True
    if Options.options.undefined_sanitizer:
        conf.ADD_CFLAGS('-fsanitize=undefined', testflags=True)
        conf.ADD_CFLAGS('-fsanitize=null', testflags=True)
        conf.ADD_CFLAGS('-fsanitize=alignment', testflags=True)
        conf.ADD_LDFLAGS('-fsanitize=undefined', testflags=True)
        conf.env['UNDEFINED_SANITIZER'] = True

    # Let people pass an additional ADDITIONAL_{CFLAGS,LDFLAGS}
    # environment variables which are only used the for final build.
    #
    # The CFLAGS and LDFLAGS environment variables are also
    # used for the configure checks which might impact their results.
    #
    # If these variables don't pass a smoke test, fail the configure

    conf.add_os_flags('ADDITIONAL_CFLAGS')
    if conf.env.ADDITIONAL_CFLAGS:
        conf.CHECK_CFLAGS(conf.env['ADDITIONAL_CFLAGS'], mandatory=True)
        conf.env['EXTRA_CFLAGS'].extend(conf.env['ADDITIONAL_CFLAGS'])

    conf.add_os_flags('ADDITIONAL_LDFLAGS')
    if conf.env.ADDITIONAL_LDFLAGS:
        conf.CHECK_LDFLAGS(conf.env['ADDITIONAL_LDFLAGS'], mandatory=True)
        conf.env['EXTRA_LDFLAGS'].extend(conf.env['ADDITIONAL_LDFLAGS'])

    if path is None:
        conf.write_config_header('default/config.h', top=True, remove=False)
    else:
        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()