Exemple #1
0
def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS(conf):
    # we don't want any libraries or modules to rely on runtime
    # resolution of symbols
    if not sys.platform.startswith("openbsd"):
        conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)

    if not sys.platform.startswith("openbsd") and conf.env.undefined_ignore_ldflags == []:
        if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']):
            conf.env.undefined_ignore_ldflags = ['-undefined', 'dynamic_lookup']
Exemple #2
0
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
    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')

    if Options.options.debug:
        conf.ADD_CFLAGS('-g', testflags=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)
        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('-Wformat=2 -Wno-format-y2k', testflags=True)
        conf.ADD_CFLAGS('-Werror=format-security -Wformat-security',
                        testflags=True)
        # 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 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)

    if Options.options.pedantic:
        conf.ADD_CFLAGS('-W', testflags=True)

    if Options.options.address_sanitizer:
        conf.ADD_CFLAGS('-fno-omit-frame-pointer -O1 -fsanitize=address',
                        testflags=True)
        conf.ADD_LDFLAGS('-fsanitize=address', testflags=True)
        conf.env['ADDRESS_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.
    conf.add_os_flags('ADDITIONAL_CFLAGS')
    if conf.env.ADDITIONAL_CFLAGS and conf.CHECK_CFLAGS(
            conf.env['ADDITIONAL_CFLAGS']):
        conf.env['EXTRA_CFLAGS'].extend(conf.env['ADDITIONAL_CFLAGS'])
    conf.add_os_flags('ADDITIONAL_LDFLAGS')
    if conf.env.ADDITIONAL_LDFLAGS and conf.CHECK_LDFLAGS(
            conf.env['ADDITIONAL_LDFLAGS']):
        conf.env['EXTRA_LDFLAGS'].extend(conf.env['ADDITIONAL_LDFLAGS'])

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

    if conf.CHECK_CFLAGS(['-fstack-protector']) and conf.CHECK_LDFLAGS(
        ['-fstack-protector']):
        conf.ADD_CFLAGS('-fstack-protector')
        conf.ADD_LDFLAGS('-fstack-protector')

    if Options.options.debug:
        conf.ADD_CFLAGS('-g', testflags=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)
        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('-Wformat=2 -Wno-format-y2k', testflags=True)
        # 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 Options.options.picky_developer:
        conf.ADD_NAMED_CFLAGS('PICKY_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)

    # 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.
    conf.add_os_flags('ADDITIONAL_CFLAGS')
    if conf.env.ADDITIONAL_CFLAGS and conf.CHECK_CFLAGS(
            conf.env['ADDITIONAL_CFLAGS']):
        conf.env['EXTRA_CFLAGS'].extend(conf.env['ADDITIONAL_CFLAGS'])
    conf.add_os_flags('ADDITIONAL_LDFLAGS')
    if conf.env.ADDITIONAL_LDFLAGS and conf.CHECK_LDFLAGS(
            conf.env['ADDITIONAL_LDFLAGS']):
        conf.env['EXTRA_LDFLAGS'].extend(conf.env['ADDITIONAL_LDFLAGS'])

    if path is None:
        conf.write_config_header('config.h', top=True)
    else:
        conf.write_config_header(path)
    conf.SAMBA_CROSS_CHECK_COMPLETE()
def check_python_headers(conf, mandatory=True):
    """Check for headers and libraries necessary to extend or embed python.

	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added for uselib

	PYEXT: for compiling python extensions
	PYEMBED: for embedding a python interpreter"""

    if not conf.env['CC_NAME'] and not conf.env['CXX_NAME']:
        conf.fatal('load a compiler first (gcc, g++, ..)')

    if not conf.env['PYTHON_VERSION']:
        conf.check_python_version()

    env = conf.env
    python = env['PYTHON']
    if not python:
        conf.fatal('could not find the python executable')

    # # On Mac OSX we need to use mac bundles for python plugins
    if Options.platform == 'darwin':
        conf.check_tool('osx')

    try:
        # Get some python configuration variables using distutils
        v = 'prefix SO SYSLIBS LDFLAGS SHLIBS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET'.split(
        )
        (python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS, python_SHLIBS,
         python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED,
         python_MACOSX_DEPLOYMENT_TARGET) = \
         _get_python_variables(python, ["get_config_var('%s') or ''" % x for x in v],
                 ['from distutils.sysconfig import get_config_var'])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")

    conf.log.write("""Configuration returned from %r:
python_prefix = %r
python_SO = %r
python_SYSLIBS = %r
python_LDFLAGS = %r
python_SHLIBS = %r
python_LIBDIR = %r
python_LIBPL = %r
INCLUDEPY = %r
Py_ENABLE_SHARED = %r
MACOSX_DEPLOYMENT_TARGET = %r
""" % (python, python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS,
       python_SHLIBS, python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED,
       python_MACOSX_DEPLOYMENT_TARGET))

    # Allow some python overrides from env vars for cross-compiling
    os_env = dict(os.environ)

    override_python_LDFLAGS = os_env.get('python_LDFLAGS', None)
    if override_python_LDFLAGS is not None:
        conf.log.write("python_LDFLAGS override from environment = %r\n" %
                       (override_python_LDFLAGS))
        python_LDFLAGS = override_python_LDFLAGS

    override_python_LIBDIR = os_env.get('python_LIBDIR', None)
    if override_python_LIBDIR is not None:
        conf.log.write("python_LIBDIR override from environment = %r\n" %
                       (override_python_LIBDIR))
        python_LIBDIR = override_python_LIBDIR

    if python_MACOSX_DEPLOYMENT_TARGET:
        conf.env['MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET
        conf.environ[
            'MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET

    env['pyext_PATTERN'] = '%s' + python_SO

    # Check for python libraries for embedding
    if python_SYSLIBS is not None:
        for lib in python_SYSLIBS.split():
            if lib.startswith('-l'):
                lib = lib[2:]  # strip '-l'
            env.append_value('LIB_PYEMBED', lib)

    if python_SHLIBS is not None:
        for lib in python_SHLIBS.split():
            if lib.startswith('-l'):
                env.append_value('LIB_PYEMBED', lib[2:])  # strip '-l'
            else:
                env.append_value('LINKFLAGS_PYEMBED', lib)

    if Options.platform != 'darwin' and python_LDFLAGS:
        parse_flags(python_LDFLAGS, 'PYEMBED', env)

    result = False
    name = 'python' + env['PYTHON_VERSION']

    if python_LIBDIR is not None:
        path = [python_LIBDIR]
        conf.log.write("\n\n# Trying LIBDIR: %r\n" % path)
        result = conf.check(lib=name, uselib='PYEMBED', libpath=path)

    if not result and python_LIBPL is not None:
        conf.log.write(
            "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
        )
        path = [python_LIBPL]
        result = conf.check(lib=name, uselib='PYEMBED', libpath=path)

    if not result:
        conf.log.write(
            "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
        )
        path = [os.path.join(python_prefix, "libs")]
        name = 'python' + env['PYTHON_VERSION'].replace('.', '')
        result = conf.check(lib=name, uselib='PYEMBED', libpath=path)

    if result:
        env['LIBPATH_PYEMBED'] = path
        env.append_value('LIB_PYEMBED', name)
    else:
        conf.log.write("\n\n### LIB NOT FOUND\n")

    # under certain conditions, python extensions must link to
    # python libraries, not just python embedding programs.
    if (sys.platform == 'win32' or sys.platform.startswith('os2')
            or sys.platform == 'darwin' or Py_ENABLE_SHARED):
        env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED']
        env['LIB_PYEXT'] = env['LIB_PYEMBED']

    # We check that pythonX.Y-config exists, and if it exists we
    # use it to get only the includes, else fall back to distutils.

    override_python_INCLUDEPY = os_env.get('python_INCLUDEPY', None)
    if override_python_INCLUDEPY is not None:
        conf.log.write("INCLUDEPY override from environment = %r\n" %
                       (override_python_INCLUDEPY))
        INCLUDEPY = override_python_INCLUDEPY
        python_config = ''
        conf.ADD_LDFLAGS('-lm')
        conf.ADD_LDFLAGS('-lutil')
        conf.ADD_LDFLAGS('-ldl')
    else:
        includes = []

    if override_python_INCLUDEPY is None:
        python_config = conf.find_program(
            'python%s-config' %
            ('.'.join(env['PYTHON_VERSION'].split('.')[:2])),
            var='PYTHON_CONFIG')

    if not python_config and override_python_INCLUDEPY is None:
        python_config = conf.find_program(
            'python-config-%s' %
            ('.'.join(env['PYTHON_VERSION'].split('.')[:2])),
            var='PYTHON_CONFIG')

    if python_config and override_python_INCLUDEPY is None:
        for incstr in Utils.cmd_output("%s --includes" %
                                       (python_config, )).strip().split():
            # strip the -I or /I
            if (incstr.startswith('-I') or incstr.startswith('/I')):
                incstr = incstr[2:]
            # append include path, unless already given
            if incstr not in includes:
                includes.append(incstr)
        conf.log.write("Include path for Python extensions "
                       "(found via python-config --includes): %r\n" %
                       (includes, ))
        env['CPPPATH_PYEXT'] = includes
        env['CPPPATH_PYEMBED'] = includes
    else:
        conf.log.write("Include path for Python extensions "
                       "(found via distutils module): %r\n" % (INCLUDEPY, ))
        env['CPPPATH_PYEXT'] = [INCLUDEPY]
        env['CPPPATH_PYEMBED'] = [INCLUDEPY]
        env['CPPPATH'] = [INCLUDEPY]

    # Code using the Python API needs to be compiled with -fno-strict-aliasing
    if env['CC_NAME'] == 'gcc':
        env.append_value('CCFLAGS_PYEMBED', '-fno-strict-aliasing')
        env.append_value('CCFLAGS_PYEXT', '-fno-strict-aliasing')
        env.append_value('CCFLAGS_PYEMBED', '-fPIC')
        env.append_value('CCFLAGS_PYEXT', '-fPIC')
    if env['CXX_NAME'] == 'gcc':
        env.append_value('CXXFLAGS_PYEMBED', '-fno-strict-aliasing')
        env.append_value('CXXFLAGS_PYEXT', '-fno-strict-aliasing')
        env.append_value('CCFLAGS_PYEMBED', '-fPIC')
        env.append_value('CCFLAGS_PYEXT', '-fPIC')

    # See if it compiles
    conf.check(define_name='HAVE_PYTHON_H',
               uselib='PYEMBED',
               fragment=FRAG_2,
               errmsg='Could not find the python development headers',
               mandatory=mandatory)