Example #1
0
def python_config(conf, version, var=''):
    version_number = version.replace('.', '')
    if not var: var = 'python%s'%(version_number)
    if 'posix' in conf.env.VALID_PLATFORMS:
        try:
            cflags, libs, ldflags = conf.run_pkg_config('python-%s'%version)
        except Errors.WafError as error:
            cflags = ['-I/usr/include/python%s'%version]
            ldflags=[]
            libs = ['python%s'%version]
        conf.check(
            compile_filename=[],
            features='check_python',
            msg='check for python %s'%version,
            cxxflags=cflags,
            libs=libs,
            ldflags=ldflags,
            use=[var],
            code="""
                #include <Python.h>
                int main() { Py_Initialize(); return 0; }
            """)
        conf.env['check_%s' % var] = True
        for lib in libs:
            if lib.startswith('python'):
                lib_name = lib
        conf.env['check_%s_defines' % var] = ['PYTHON_LIBRARY=%s' % lib_name]
    elif 'macosx' in conf.env.VALID_PLATFORMS:
        conf.recurse('../python%s/python%s.py' % (version_number, version_number), name='setup_python', once=False)
    elif 'windows' in conf.env.VALID_PLATFORMS:
        conf.recurse('../python%s/python%s.py' % (version_number, version_number), name='setup_python', once=False)
    else:
        raise Errors.WafError('TODO')
Example #2
0
File: javaw.py Project: mrotaru/waf
def check_jni_headers(conf):
    """
	Check for jni headers and libraries. On success the conf.env variables xxx_JAVA are added for use in C/C++ targets::

		def options(opt):
			opt.load('compiler_c')

		def configure(conf):
			conf.load('compiler_c java')
			conf.check_jni_headers()

		def build(bld):
			bld.shlib(source='a.c', target='app', use='JAVA')
	"""

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

    if not conf.env.JAVA_HOME:
        conf.fatal("set JAVA_HOME in the system environment")

        # jni requires the jvm
    javaHome = conf.env["JAVA_HOME"][0]

    dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + "/include")
    if dir is None:
        dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + "/../Headers")  # think different?!
    if dir is None:
        conf.fatal("JAVA_HOME does not seem to be set properly")

    f = dir.ant_glob("**/(jni|jni_md).h")
    incDirs = [x.parent.abspath() for x in f]

    dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob("**/*jvm.(so|dll|dylib)")
    libDirs = [x.parent.abspath() for x in f] or [javaHome]

    # On windows, we need both the .dll and .lib to link.  On my JDK, they are
    # in different directories...
    f = dir.ant_glob("**/*jvm.(lib)")
    if f:
        libDirs = [[x, y.parent.abspath()] for x in libDirs for y in f]

    for d in libDirs:
        try:
            conf.check(
                header_name="jni.h",
                define_name="HAVE_JNI_H",
                lib="jvm",
                libpath=d,
                includes=incDirs,
                uselib_store="JAVA",
                uselib="JAVA",
            )
        except Exception:
            pass
        else:
            break
    else:
        conf.fatal("could not find lib jvm in %r (see config.log)" % libDirs)
Example #3
0
File: javaw.py Project: janbre/NUTS
def check_jni_headers(conf):
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal("load a compiler first (gcc, g++, ..)")
    if not conf.env.JAVA_HOME:
        conf.fatal("set JAVA_HOME in the system environment")
    javaHome = conf.env["JAVA_HOME"][0]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + "/include")
    if dir is None:
        conf.fatal("JAVA_HOME does not seem to be set properly")
    f = dir.ant_glob("**/(jni|jni_md).h")
    incDirs = [x.parent.abspath() for x in f]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob("**/*jvm.(so|dll|dylib)")
    libDirs = [x.parent.abspath() for x in f] or [javaHome]
    f = dir.ant_glob("**/*jvm.(lib)")
    if f:
        libDirs = [[x, y.parent.abspath()] for x in libDirs for y in f]
    for d in libDirs:
        try:
            conf.check(
                header_name="jni.h",
                define_name="HAVE_JNI_H",
                lib="jvm",
                libpath=d,
                includes=incDirs,
                uselib_store="JAVA",
                uselib="JAVA",
            )
        except:
            pass
        else:
            break
    else:
        conf.fatal("could not find lib jvm in %r (see config.log)" % libDirs)
Example #4
0
def check_jni_headers(conf):
	if not conf.env.CC_NAME and not conf.env.CXX_NAME:
		conf.fatal('load a compiler first (gcc, g++, ..)')
	if not conf.env.JAVA_HOME:
		conf.fatal('set JAVA_HOME in the system environment')
	javaHome=conf.env['JAVA_HOME'][0]
	dir=conf.root.find_dir(conf.env.JAVA_HOME[0]+'/include')
	if dir is None:
		dir=conf.root.find_dir(conf.env.JAVA_HOME[0]+'/../Headers')
	if dir is None:
		conf.fatal('JAVA_HOME does not seem to be set properly')
	f=dir.ant_glob('**/(jni|jni_md).h')
	incDirs=[x.parent.abspath()for x in f]
	dir=conf.root.find_dir(conf.env.JAVA_HOME[0])
	f=dir.ant_glob('**/*jvm.(so|dll|dylib)')
	libDirs=[x.parent.abspath()for x in f]or[javaHome]
	f=dir.ant_glob('**/*jvm.(lib)')
	if f:
		libDirs=[[x,y.parent.abspath()]for x in libDirs for y in f]
	for d in libDirs:
		try:
			conf.check(header_name='jni.h',define_name='HAVE_JNI_H',lib='jvm',libpath=d,includes=incDirs,uselib_store='JAVA',uselib='JAVA')
		except Exception:
			pass
		else:
			break
	else:
		conf.fatal('could not find lib jvm in %r (see config.log)'%libDirs)
Example #5
0
def check_libs(conf):
    compiler = FLAGS[conf.env.COMPILER_CXX]
    boost_params = dict(dict(mt  = True,
                             abi = 'gd' if conf.variant == 'debug' else ''),
                        **compiler['boost'])
    conf.check_boost(**boost_params)
    conf.check(lib='gtest' if conf.variant == 'release' else 'gtestd',
               uselib_store='GTEST', mandatory=False)
    conf.check(lib='gmock' if conf.variant == 'release' else 'gmockd',
               uselib_store='GMOCK', mandatory=False)
Example #6
0
def check_jni_headers(conf):
	"""
	Checks for jni headers and libraries. On success the conf.env variables xxx_JAVA are added for use in C/C++ targets::

		def options(opt):
			opt.load('compiler_c')

		def configure(conf):
			conf.load('compiler_c java')
			conf.check_jni_headers()

		def build(bld):
			bld.shlib(source='a.c', target='app', use='JAVA')
	"""
	if not conf.env.CC_NAME and not conf.env.CXX_NAME:
		conf.fatal('load a compiler first (gcc, g++, ..)')

	if not conf.env.JAVA_HOME:
		conf.fatal('set JAVA_HOME in the system environment')

	# jni requires the jvm
	javaHome = conf.env.JAVA_HOME[0]

	dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
	if dir is None:
		dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + '/../Headers') # think different?!
	if dir is None:
		conf.fatal('JAVA_HOME does not seem to be set properly')

	f = dir.ant_glob('**/(jni|jni_md).h')
	incDirs = [x.parent.abspath() for x in f]

	dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
	f = dir.ant_glob('**/*jvm.(so|dll|dylib)')
	libDirs = [x.parent.abspath() for x in f] or [javaHome]

	# On windows, we need both the .dll and .lib to link.  On my JDK, they are
	# in different directories...
	f = dir.ant_glob('**/*jvm.(lib)')
	if f:
		libDirs = [[x, y.parent.abspath()] for x in libDirs for y in f]

	if conf.env.DEST_OS == 'freebsd':
		conf.env.append_unique('LINKFLAGS_JAVA', '-pthread')
	for d in libDirs:
		try:
			conf.check(header_name='jni.h', define_name='HAVE_JNI_H', lib='jvm',
				libpath=d, includes=incDirs, uselib_store='JAVA', uselib='JAVA')
		except Exception:
			pass
		else:
			break
	else:
		conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Example #7
0
def configure(conf):
	"""
	Detects the program *msgfmt* and set *conf.env.MSGFMT*.
	Detects the program *intltool-merge* and set *conf.env.INTLTOOL*.
	It is possible to set INTLTOOL in the environment, but it must not have spaces in it::

		$ INTLTOOL="/path/to/the program/intltool" waf configure

	If a C/C++ compiler is present, execute a compilation test to find the header *locale.h*.
	"""
	conf.find_msgfmt()
	conf.find_intltool_merge()
	if conf.env.CC or conf.env.CXX:
		conf.check(header_name='locale.h')
Example #8
0
def check_library_func(conf, library, function, use, envvars=None):
    if envvars is None: envvars = []
    envvars += ['LIB','LIBPATH','LINKFLAGS']
    for u in to_list(use): envvars += ['LIB_%s'%u,'LIBPATH_%s'%u,'LINKFLAGS_%s'%u]
    try:
        conf.check(fragment='int main(){ %s(); }'%function,
                   msg="Checking for library %s"%library,
                   okmsg="found function %s"%function,
                   errmsg="couldn't find function %s"%function,
                   use=use)
    except conf.errors.ConfigurationError: 
        conf.fatal(('%s was not found on your system. '
                    'Check that it is installed and that the following '
                    'environment variables are set correctly:\n')%library+
                    '\n'.join(['%s = %s'%(x,' '.join(getattr(conf.env,x,''))) for x in sorted(set(envvars))]))
Example #9
0
File: javaw.py Project: SjB/waf
def check_jni_headers(conf):
	"""
	Check for jni headers and libraries. On success the conf.env variables xxx_JAVA are added for use in c/c++ targets.
	"""

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

	if not conf.env.JAVA_HOME:
		conf.fatal('set JAVA_HOME in the system environment')

	# jni requires the jvm
	javaHome = conf.env['JAVA_HOME'][0]

	dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
	f = dir.ant_glob('**/(jni|jni_md).h')
	incDirs = [x.parent.abspath() for x in f]

	dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
	f = dir.ant_glob('**/*jvm.(so|dll)')
	libDirs = [x.parent.abspath() for x in f] or [javaHome]

	for i, d in enumerate(libDirs):
		if conf.check(header_name='jni.h', define_name='HAVE_JNI_H', lib='jvm',
				libpath=d, includes=incDirs, uselib_store='JAVA', uselib='JAVA'):
			break
	else:
		conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Example #10
0
def check_jni_headers(conf):
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal("load a compiler first (gcc, g++, ..)")
    if not conf.env.JAVA_HOME:
        conf.fatal("set JAVA_HOME in the system environment")
    javaHome = conf.env["JAVA_HOME"][0]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + "/include")
    f = dir.ant_glob("**/(jni|jni_md).h")
    incDirs = [x.parent.abspath() for x in f]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob("**/*jvm.(so|dll)")
    libDirs = [x.parent.abspath() for x in f] or [javaHome]
    for i, d in enumerate(libDirs):
        if conf.check(
            header_name="jni.h",
            define_name="HAVE_JNI_H",
            lib="jvm",
            libpath=d,
            includes=incDirs,
            uselib_store="JAVA",
            uselib="JAVA",
        ):
            break
    else:
        conf.fatal("could not find lib jvm in %r (see config.log)" % libDirs)
Example #11
0
def CHECK_LIB(conf, libs, mandatory=False, empty_decl=True, set_target=True, shlib=False):
    '''check if a set of libraries exist as system libraries

    returns the sublist of libs that do exist as a syslib or []
    '''

    fragment= '''
int foo()
{
    int v = 2;
    return v*2;
}
'''
    ret = []
    liblist  = TO_LIST(libs)
    for lib in liblist[:]:
        if GET_TARGET_TYPE(conf, lib) == 'SYSLIB':
            ret.append(lib)
            continue

        (ccflags, ldflags, cpppath) = library_flags(conf, lib)
        if shlib:
            res = conf.check(features='c cshlib', fragment=fragment, lib=lib, uselib_store=lib, cflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)
        else:
            res = conf.check(lib=lib, uselib_store=lib, cflags=ccflags, ldflags=ldflags, uselib=lib.upper(), mandatory=False)

        if not res:
            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
                if set_target:
                    SET_TARGET_TYPE(conf, lib, 'EMPTY')
        else:
            conf.define('HAVE_LIB%s' % lib.upper().replace('-','_').replace('.','_'), 1)
            conf.env['LIB_' + lib.upper()] = lib
            if set_target:
                conf.SET_TARGET_TYPE(lib, 'SYSLIB')
            ret.append(lib)

    return ret
Example #12
0
def CHECK_CFLAGS(conf, cflags, fragment='int main(void) { return 0; }\n'):
    '''check if the given cflags are accepted by the compiler
    '''
    check_cflags = TO_LIST(cflags)
    if 'WERROR_CFLAGS' in conf.env:
        check_cflags.extend(conf.env['WERROR_CFLAGS'])
    return conf.check(fragment=fragment,
                      execute=0,
                      mandatory=False,
                      type='nolink',
                      cflags=check_cflags,
                      msg="Checking compiler accepts %s" % cflags)
Example #13
0
def CHECK_NEED_LC(conf, msg):
    '''check if we need -lc'''
    def build(bld):
        lib_node = bld.srcnode.make_node('libdir/liblc1.c')
        lib_node.parent.mkdir()
        lib_node.write(
            '#include <stdio.h>\nint lib_func(void) { FILE *f = fopen("foo", "r");}\n',
            'w')
        bld(features='c cshlib',
            source=[lib_node],
            linkflags=conf.env.EXTRA_LDFLAGS,
            target='liblc')

    try:
        conf.check(build_fun=build,
                   msg=msg,
                   okmsg='-lc is unnecessary',
                   errmsg='-lc is necessary')
    except conf.errors.ConfigurationError:
        return False
    return True
Example #14
0
def CHECK_SHLIB_INTRASINC_NAME_FLAGS(conf, msg):
    '''
        check if the waf default flags for setting the name of lib
        are ok
    '''

    snip = '''
int foo(int v) {
    return v * 2;
}
'''
    return conf.check(features='c cshlib',vnum="1",fragment=snip,msg=msg, mandatory=False)
Example #15
0
def check_python_headers(conf):
	env=conf.env
	if not env['CC_NAME']and not env['CXX_NAME']:
		conf.fatal('load a compiler first (gcc, g++, ..)')
	if not env['PYTHON_VERSION']:
		conf.check_python_version()
	pybin=conf.env.PYTHON
	if not pybin:
		conf.fatal('Could not find the python executable')
	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
	try:
		lst=conf.get_python_variables(["get_config_var('%s') or ''"%x for x in v])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")
	vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)]
	conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals)))
	dct=dict(zip(v,lst))
	x='MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		conf.env[x]=conf.environ[x]=dct[x]
	if not env.pyext_PATTERN:
		if dct['SO']:
			env.pyext_PATTERN='%s'+dct['SO']
		else:
			env.pyext_PATTERN=(conf.env.cshlib_PATTERN or conf.env.cxxshlib_PATTERN).lstrip('lib')
	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
	conf.find_program([''.join(pybin)+'-config','python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',msg="python-config")
	all_flags=[['--cflags','--libs','--ldflags']]
	if sys.hexversion<0x2060000:
		all_flags=[[x]for x in all_flags[0]]
	xx=conf.env.CXX_NAME and'cxx'or'c'
	for flags in all_flags:
		conf.check_cfg(msg='Asking python-config for pyembed %r flags'%' '.join(flags),path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=flags)
	conf.check(header_name='Python.h',define_name='HAVE_PYEMBED',msg='Getting pyembed flags from python-config',fragment=FRAG,errmsg='Could not build a python embedded interpreter',features='%s %sprogram pyembed'%(xx,xx))
	for flags in all_flags:
		conf.check_cfg(msg='Asking python-config for pyext %r flags'%' '.join(flags),path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEXT',args=flags)
	conf.check(header_name='Python.h',define_name='HAVE_PYEXT',msg='Getting pyext flags from python-config',features='%s %sshlib pyext'%(xx,xx),fragment=FRAG,errmsg='Could not build python extensions')
	conf.define('HAVE_PYTHON_H',1)
def CHECK_LIBRARY_SUPPORT(conf, rpath=False, version_script=False, msg=None):
    '''see if the platform supports building libraries'''

    if msg is None:
        if rpath:
            msg = "rpath library support"
        else:
            msg = "building library support"

    def build(bld):
        lib_node = bld.srcnode.make_node('libdir/liblc1.c')
        lib_node.parent.mkdir()
        lib_node.write('int lib_func(void) { return 42; }\n', 'w')
        main_node = bld.srcnode.make_node('main.c')
        main_node.write('int main(void) {return !(lib_func() == 42);}', 'w')
        linkflags = []
        if version_script:
            script = bld.srcnode.make_node('ldscript')
            script.write('TEST_1.0A2 { global: *; };\n', 'w')
            linkflags.append('-Wl,--version-script=%s' % script.abspath())
        bld(features='c cshlib', source=lib_node, target='lib1', linkflags=linkflags, name='lib1')
        o = bld(features='c cprogram', source=main_node, target='prog1', uselib_local='lib1')
        if rpath:
            o.rpath = [lib_node.parent.abspath()]
        def run_app(self):
             args = conf.SAMBA_CROSS_ARGS(msg=msg)
             env = dict(os.environ)
             env['LD_LIBRARY_PATH'] = self.inputs[0].parent.abspath() + os.pathsep + env.get('LD_LIBRARY_PATH', '')
             self.generator.bld.cmd_and_log([self.inputs[0].abspath()] + args, env=env)
        o.post()
        bld(rule=run_app, source=o.link_task.outputs[0])

    # ok, so it builds
    try:
        conf.check(build_fun=build, msg='Checking for %s' % msg)
    except conf.errors.ConfigurationError:
        return False
    return True
Example #17
0
def check_adios(conf):
    opt = conf.options
    conf.env['ADIOS_FOUND'] = False

    if not conf.options.enable_adios:
        return

    if conf.options.adiosIncDir:
        conf.env.INCLUDES_ADIOS = conf.options.adiosIncDir
    else:
        conf.env.INCLUDES_ADIOS = conf.options.gkylDepsDir + '/adios/include'

    if conf.options.adiosLibDir:
        #conf.env.STLIBPATH_ADIOS = conf.options.adiosLibDir
        conf.env.STLIBPATH_ADIOS = conf.options.adiosLibDir.split(',')
    else:
        conf.env.STLIBPATH_ADIOS = conf.options.gkylDepsDir + '/adios/lib'

    if conf.options.enable_mpi:
        conf.env.STLIB_ADIOS = ["adios", "adiosread"]
    else:
        conf.env.append_value('CXXFLAGS', '-D_NOMPI')
        conf.env.append_value('CFLAGS', '-D_NOMPI')
        conf.env.STLIB_ADIOS = ["adios_nompi", "adiosread_nompi"]

    if conf.options.adiosLinkLibs:
        libList = conf.options.adiosLinkLibs
        conf.env.append_value('STLIB_ADIOS', libList.split(','))

    conf.start_msg('Checking for ADIOS')
    conf.check(header_name='adios.h',
               features='cxx cxxprogram',
               use="ADIOS MPI",
               mandatory=True)
    conf.end_msg("Found ADIOS")
    conf.env['ADIOS_FOUND'] = True
    return 1
Example #18
0
def check_jni_headers(conf):
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if not conf.env.JAVA_HOME:
        conf.fatal('set JAVA_HOME in the system environment')
    javaHome = conf.env.JAVA_HOME[0]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
    if dir is None:
        dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + '/../Headers')
    if dir is None:
        conf.fatal('JAVA_HOME does not seem to be set properly')
    f = dir.ant_glob('**/(jni|jni_md).h')
    incDirs = [x.parent.abspath() for x in f]
    dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob('**/*jvm.(so|dll|dylib)')
    libDirs = [x.parent.abspath() for x in f] or [javaHome]
    f = dir.ant_glob('**/*jvm.(lib)')
    if f:
        libDirs = [[x, y.parent.abspath()] for x in libDirs for y in f]
    if conf.env.DEST_OS == 'freebsd':
        conf.env.append_unique('LINKFLAGS_JAVA', '-pthread')
    for d in libDirs:
        try:
            conf.check(header_name='jni.h',
                       define_name='HAVE_JNI_H',
                       lib='jvm',
                       libpath=d,
                       includes=incDirs,
                       uselib_store='JAVA',
                       uselib='JAVA')
        except Exception:
            pass
        else:
            break
    else:
        conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Example #19
0
def CHECK_SHLIB_W_PYTHON(conf, msg):
    '''check if we need -undefined dynamic_lookup'''

    dir = find_config_dir(conf)
    snip = '''
#include <Python.h>
#include <crt_externs.h>
#define environ (*_NSGetEnviron())

static PyObject *ldb_module = NULL;
int foo(int v) {
    extern char **environ;
    environ[0] = 1;
    ldb_module = PyImport_ImportModule("ldb");
    return v * 2;
}'''
    return conf.check(features='c cshlib',uselib='PYEMBED',fragment=snip,msg=msg, mandatory=False)
Example #20
0
def check_jni_headers(conf):
	if not conf.env.CC_NAME and not conf.env.CXX_NAME:
		conf.fatal('load a compiler first (gcc, g++, ..)')
	if not conf.env.JAVA_HOME:
		conf.fatal('set JAVA_HOME in the system environment')
	javaHome=conf.env['JAVA_HOME'][0]
	dir=conf.root.find_dir(conf.env.JAVA_HOME[0]+'/include')
	f=dir.ant_glob('**/(jni|jni_md).h')
	incDirs=[x.parent.abspath()for x in f]
	dir=conf.root.find_dir(conf.env.JAVA_HOME[0])
	f=dir.ant_glob('**/*jvm.(so|dll)')
	libDirs=[x.parent.abspath()for x in f]or[javaHome]
	for i,d in enumerate(libDirs):
		if conf.check(header_name='jni.h',define_name='HAVE_JNI_H',lib='jvm',libpath=d,includes=incDirs,uselib_store='JAVA',uselib='JAVA'):
			break
	else:
		conf.fatal('could not find lib jvm in %r (see config.log)'%libDirs)
Example #21
0
def configure(conf):
    conf.find_msgfmt()
    conf.find_intltool_merge()
    if conf.env.CC or conf.env.CXX:
        conf.check(header_name='locale.h')
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()
Example #23
0
def check_python_headers(conf):
    """
    Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
    On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

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

    # FIXME rewrite

    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
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('could not find the python executable')

    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["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).")

    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" %
                (pybin, '\n'.join(vals)))

    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]

    env['pyext_PATTERN'] = '%s' + dct['SO']  # not a mistake

    # Check for python libraries for embedding

    all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEMBED')
    conf.parse_flags(all_flags, 'PYEXT')

    result = None
    #name = 'python' + env['PYTHON_VERSION']

    # TODO simplify this
    for name in ('python' + env['PYTHON_VERSION'],
                 'python' + env['PYTHON_VERSION'].replace('.', '')):

        if Utils.is_win32 and name == "python2.7":
            name = "python27"
            print "walif/tools/python.py: python hack for windows"

        #name.replace('.', '')

        # LIBPATH_PYEMBED is already set; see if it works.
        if not result and env['LIBPATH_PYEMBED']:
            path = env['LIBPATH_PYEMBED']
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib='PYEMBED',
                libpath=path,
                mandatory=False,
                msg='Checking for library %s in LIBPATH_PYEMBED' % name)

        if not result and dct['LIBDIR']:
            path = [dct['LIBDIR']]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in LIBDIR' % name)

        if not result and dct['LIBPL']:
            path = [dct['LIBPL']]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in python_LIBPL' %
                                name)

        if not result:
            path = [os.path.join(dct['prefix'], "libs")]
            conf.to_log(
                "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in $prefix/libs' %
                                name)

        if result:
            break  # do not forget to set LIBPATH_PYEMBED

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

    # under certain conditions, python extensions must link to
    # python libraries, not just python embedding programs.
    if (Utils.is_win32 or sys.platform.startswith('os2')
            or sys.platform == 'darwin' or dct['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.
    num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
    conf.find_program([
        'python%s-config' % num,
        'python-config-%s' % num,
        'python%sm-config' % num
    ],
                      var='PYTHON_CONFIG',
                      mandatory=False)

    includes = []
    if conf.env.PYTHON_CONFIG:
        for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG,
                                        '--includes']).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.to_log("Include path for Python extensions "
                    "(found via python-config --includes): %r\n" %
                    (includes, ))
        env['INCLUDES_PYEXT'] = includes
        env['INCLUDES_PYEMBED'] = includes
    else:
        conf.to_log("Include path for Python extensions "
                    "(found via distutils module): %r\n" %
                    (dct['INCLUDEPY'], ))
        env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
        env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]

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

    # See if it compiles
    try:
        conf.check(header_name='Python.h',
                   define_name='HAVE_PYTHON_H',
                   uselib='PYEMBED',
                   fragment=FRAG,
                   errmsg='Could not find the python development headers')
    except conf.errors.ConfigurationError:
        # python3.2, oh yeah
        conf.check_cfg(path=conf.env.PYTHON_CONFIG,
                       package='',
                       uselib_store='PYEMBED',
                       args=['--cflags', '--libs'])
        conf.check(
            header_name='Python.h',
            define_name='HAVE_PYTHON_H',
            msg='Getting the python flags from python-config',
            uselib='PYEMBED',
            fragment=FRAG,
            errmsg='Could not find the python development headers elsewhere')
def check_python_headers(conf, features="pyembed pyext"):
    """
    Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
    On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

    * PYEXT: for compiling python extensions
    * PYEMBED: for embedding a python interpreter
    """
    features = Utils.to_list(features)
    assert ("pyembed" in features) or (
        "pyext" in features
    ), "check_python_headers features must include 'pyembed' and/or 'pyext'"
    env = conf.env
    if not env.CC_NAME and not env.CXX_NAME:
        conf.fatal("load a compiler first (gcc, g++, ..)")

    # bypass all the code below for cross-compilation
    if conf.python_cross_compile(features):
        return

    if not env.PYTHON_VERSION:
        conf.check_python_version()

    pybin = env.PYTHON
    if not pybin:
        conf.fatal("Could not find the python executable")

    # so we actually do all this for compatibility reasons and for obtaining pyext_PATTERN below
    v = "prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION".split()
    try:
        lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")

    vals = [f"{x} = {y!r}" for (x, y) in zip(v, lst)]
    conf.to_log(
        "Configuration returned from {!r}:\n{}\n".format(pybin, "\n".join(vals))
    )

    dct = dict(zip(v, lst))
    x = "MACOSX_DEPLOYMENT_TARGET"
    if dct[x]:
        env[x] = conf.environ[x] = dct[x]
    env.pyext_PATTERN = "%s" + dct["SO"]  # not a mistake

    # Try to get pythonX.Y-config
    num = ".".join(env.PYTHON_VERSION.split(".")[:2])
    conf.find_program(
        [
            "".join(pybin) + "-config",
            "python%s-config" % num,
            "python-config-%s" % num,
            "python%sm-config" % num,
        ],
        var="PYTHON_CONFIG",
        msg="python-config",
        mandatory=False,
    )

    if env.PYTHON_CONFIG:
        # python2.6-config requires 3 runs
        all_flags = [["--cflags", "--libs", "--ldflags"]]
        if sys.hexversion < 0x2070000:
            all_flags = [[k] for k in all_flags[0]]

        xx = env.CXX_NAME and "cxx" or "c"

        if "pyembed" in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg="Asking python-config for pyembed %r flags" % " ".join(flags),
                    path=env.PYTHON_CONFIG,
                    package="",
                    uselib_store="PYEMBED",
                    args=flags,
                )

            try:
                conf.test_pyembed(xx)
            except conf.errors.ConfigurationError:
                # python bug 7352
                if dct["Py_ENABLE_SHARED"] and dct["LIBDIR"]:
                    env.append_unique("LIBPATH_PYEMBED", [dct["LIBDIR"]])
                    conf.test_pyembed(xx)
                else:
                    raise

        if "pyext" in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg="Asking python-config for pyext %r flags" % " ".join(flags),
                    path=env.PYTHON_CONFIG,
                    package="",
                    uselib_store="PYEXT",
                    args=flags,
                )

            try:
                conf.test_pyext(xx)
            except conf.errors.ConfigurationError:
                # python bug 7352
                if dct["Py_ENABLE_SHARED"] and dct["LIBDIR"]:
                    env.append_unique("LIBPATH_PYEXT", [dct["LIBDIR"]])
                    conf.test_pyext(xx)
                else:
                    raise

        conf.define("HAVE_PYTHON_H", 1)
        return

    # No python-config, do something else on windows systems
    all_flags = dct["LDFLAGS"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEMBED")

    all_flags = dct["LDFLAGS"] + " " + dct["LDSHARED"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEXT")

    result = None
    if not dct["LDVERSION"]:
        dct["LDVERSION"] = env.PYTHON_VERSION

    # further simplification will be complicated
    for name in (
        "python" + dct["LDVERSION"],
        "python" + env.PYTHON_VERSION + "m",
        "python" + env.PYTHON_VERSION.replace(".", ""),
    ):

        # LIBPATH_PYEMBED is already set; see if it works.
        if not result and env.LIBPATH_PYEMBED:
            path = env.LIBPATH_PYEMBED
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBPATH_PYEMBED" % name,
            )

        if not result and dct["LIBDIR"]:
            path = [dct["LIBDIR"]]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBDIR" % name,
            )

        if not result and dct["LIBPL"]:
            path = [dct["LIBPL"]]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in python_LIBPL" % name,
            )

        if not result:
            path = [os.path.join(dct["prefix"], "libs")]
            conf.to_log(
                "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
            )
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in $prefix/libs" % name,
            )

        if result:
            break  # do not forget to set LIBPATH_PYEMBED

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

    # under certain conditions, python extensions must link to
    # python libraries, not just python embedding programs.
    if Utils.is_win32 or dct["Py_ENABLE_SHARED"]:
        env.LIBPATH_PYEXT = env.LIBPATH_PYEMBED
        env.LIB_PYEXT = env.LIB_PYEMBED

    conf.to_log(
        "Include path for Python extensions (found via distutils module): {!r}\n".format(
            dct["INCLUDEPY"]
        )
    )
    env.INCLUDES_PYEXT = [dct["INCLUDEPY"]]
    env.INCLUDES_PYEMBED = [dct["INCLUDEPY"]]

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

    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler

        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value("CFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("CXXFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("LINKFLAGS_PYEXT", dist_compiler.ldflags_shared)

    # See if it compiles
    conf.check(
        header_name="Python.h",
        define_name="HAVE_PYTHON_H",
        uselib="PYEMBED",
        fragment=FRAG,
        errmsg="Distutils not installed? Broken python installation? Get python-config now!",
    )
Example #25
0
def check_python_headers(conf):
	env=conf.env
	if not env['CC_NAME']and not env['CXX_NAME']:
		conf.fatal('load a compiler first (gcc, g++, ..)')
	if not env['PYTHON_VERSION']:
		conf.check_python_version()
	pybin=env.PYTHON
	if not pybin:
		conf.fatal('Could not find the python executable')
	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
	try:
		lst=conf.get_python_variables(["get_config_var('%s') or ''"%x for x in v])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")
	vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)]
	conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals)))
	dct=dict(zip(v,lst))
	x='MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		env[x]=conf.environ[x]=dct[x]
	env['pyext_PATTERN']='%s'+dct['SO']
	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
	conf.find_program([''.join(pybin)+'-config','python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',msg="python-config",mandatory=False)
	if env.PYTHON_CONFIG:
		all_flags=[['--cflags','--libs','--ldflags']]
		if sys.hexversion<0x2060000:
			all_flags=[[k]for k in all_flags[0]]
		xx=env.CXX_NAME and'cxx'or'c'
		for flags in all_flags:
			conf.check_cfg(msg='Asking python-config for pyembed %r flags'%' '.join(flags),path=env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=flags)
		conf.check(header_name='Python.h',define_name='HAVE_PYEMBED',msg='Getting pyembed flags from python-config',fragment=FRAG,errmsg='Could not build a python embedded interpreter',features='%s %sprogram pyembed'%(xx,xx))
		for flags in all_flags:
			conf.check_cfg(msg='Asking python-config for pyext %r flags'%' '.join(flags),path=env.PYTHON_CONFIG,package='',uselib_store='PYEXT',args=flags)
		conf.check(header_name='Python.h',define_name='HAVE_PYEXT',msg='Getting pyext flags from python-config',features='%s %sshlib pyext'%(xx,xx),fragment=FRAG,errmsg='Could not build python extensions')
		conf.define('HAVE_PYTHON_H',1)
		return
	all_flags=dct['LDFLAGS']+' '+dct['CFLAGS']
	conf.parse_flags(all_flags,'PYEMBED')
	all_flags=dct['LDFLAGS']+' '+dct['LDSHARED']+' '+dct['CFLAGS']
	conf.parse_flags(all_flags,'PYEXT')
	result=None
	if not dct["LDVERSION"]:
		dct["LDVERSION"]=env['PYTHON_VERSION']
	for name in('python'+dct['LDVERSION'],'python'+env['PYTHON_VERSION']+'m','python'+env['PYTHON_VERSION'].replace('.','')):
		if not result and env['LIBPATH_PYEMBED']:
			path=env['LIBPATH_PYEMBED']
			conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n"%path)
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBPATH_PYEMBED'%name)
		if not result and dct['LIBDIR']:
			path=[dct['LIBDIR']]
			conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n"%path)
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBDIR'%name)
		if not result and dct['LIBPL']:
			path=[dct['LIBPL']]
			conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in python_LIBPL'%name)
		if not result:
			path=[os.path.join(dct['prefix'],"libs")]
			conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in $prefix/libs'%name)
		if result:
			break
	if result:
		env['LIBPATH_PYEMBED']=path
		env.append_value('LIB_PYEMBED',[name])
	else:
		conf.to_log("\n\n### LIB NOT FOUND\n")
	if Utils.is_win32 or dct['Py_ENABLE_SHARED']:
		env['LIBPATH_PYEXT']=env['LIBPATH_PYEMBED']
		env['LIB_PYEXT']=env['LIB_PYEMBED']
	conf.to_log("Include path for Python extensions (found via distutils module): %r\n"%(dct['INCLUDEPY'],))
	env['INCLUDES_PYEXT']=[dct['INCLUDEPY']]
	env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']]
	if env['CC_NAME']=='gcc':
		env.append_value('CFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CFLAGS_PYEXT',['-fno-strict-aliasing'])
	if env['CXX_NAME']=='gcc':
		env.append_value('CXXFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CXXFLAGS_PYEXT',['-fno-strict-aliasing'])
	if env.CC_NAME=="msvc":
		from distutils.msvccompiler import MSVCCompiler
		dist_compiler=MSVCCompiler()
		dist_compiler.initialize()
		env.append_value('CFLAGS_PYEXT',dist_compiler.compile_options)
		env.append_value('CXXFLAGS_PYEXT',dist_compiler.compile_options)
		env.append_value('LINKFLAGS_PYEXT',dist_compiler.ldflags_shared)
	conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG,errmsg='Distutils not installed? Broken python installation? Get python-config now!')
Example #26
0
def check_jni_headers(conf):
    """
    Checks for jni headers and libraries. On success the conf.env variables xxx_JAVA are added for use in C/C++ targets::

            def options(opt):
                    opt.load('compiler_c')

            def configure(conf):
                    conf.load('compiler_c java')
                    conf.check_jni_headers()

            def build(bld):
                    bld.shlib(source='a.c', target='app', use='JAVA')
    """
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal("load a compiler first (gcc, g++, ..)")

    if not conf.env.JAVA_HOME:
        conf.fatal("set JAVA_HOME in the system environment")

    # jni requires the jvm
    javaHome = conf.env.JAVA_HOME[0]

    dir = conf.root.find_dir(conf.env.JAVA_HOME[0] + "/include")
    if dir is None:
        dir = conf.root.find_dir(conf.env.JAVA_HOME[0] +
                                 "/../Headers")  # think different?!
    if dir is None:
        conf.fatal("JAVA_HOME does not seem to be set properly")

    f = dir.ant_glob("**/(jni|jni_md).h")
    incDirs = [x.parent.abspath() for x in f]

    dir = conf.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob("**/*jvm.(so|dll|dylib)")
    libDirs = [x.parent.abspath() for x in f] or [javaHome]

    # On windows, we need both the .dll and .lib to link.  On my JDK, they are
    # in different directories...
    f = dir.ant_glob("**/*jvm.(lib)")
    if f:
        libDirs = [[x, y.parent.abspath()] for x in libDirs for y in f]

    if conf.env.DEST_OS == "freebsd":
        conf.env.append_unique("LINKFLAGS_JAVA", "-pthread")
    for d in libDirs:
        try:
            conf.check(
                header_name="jni.h",
                define_name="HAVE_JNI_H",
                lib="jvm",
                libpath=d,
                includes=incDirs,
                uselib_store="JAVA",
                uselib="JAVA",
            )
        except Exception:
            pass
        else:
            break
    else:
        conf.fatal("could not find lib jvm in %r (see config.log)" % libDirs)
Example #27
0
def check_gcov(conf):
    if conf.variant == 'debug':
        conf.check(lib='gcov', uselib_store='GCOV', mandatory=False)
    if (conf.env.LIB_GCOV):
        conf.env.CXXFLAGS  += ['--coverage', '-fprofile-arcs', '-ftest-coverage']
        conf.env.LINKFLAGS += ['--coverage', '-fprofile-arcs']
Example #28
0
def check_gtest(conf):
    conf.check(lib='gtest' if conf.variant == 'release' else 'gtestd',
               header_name='gtest/gtest.h', uselib_store='GTEST', mandatory=False)
    conf.check(lib='gmock' if conf.variant == 'release' else 'gmockd', use='GTEST',
               header_name='gmock/gmock.h', uselib_store='GMOCK', mandatory=False)
Example #29
0
def check_python_headers(conf):
	"""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')

	v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split()
	try:
		lst = conf.get_python_variables(python, ["get_config_var('%s')" % x for x in v],
			['from distutils.sysconfig import get_config_var'])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")

	vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
	conf.to_log("Configuration returned from %r:\n%r\n" % (python, '\n'.join(vals)))

	dct = dict(zip(v, lst))
	x = 'MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		conf.env[x] = conf.environ[x] = dct[x]

	env['pyext_PATTERN'] = '%s' + dct['SO'] # not a mistake

	# Check for python libraries for embedding

	all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
	conf.parse_flags(all_flags, 'PYEMBED')
	conf.parse_flags(all_flags, 'PYEXT')

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

	# LIBPATH_PYEMBED is already set; see if it works.
	path = env['LIBPATH_PYEMBED']
	conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
	result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False)

	if not result:
		conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
		path = [dct['LIBDIR'] or '']
		result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False)

	if not result:
		conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
		path = [dct['LIBPL'] or '']
		result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False)

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

	if result:
		env['LIBPATH_PYEMBED'] = path
		env.append_value('LIB_PYEMBED', [name])
	else:
		conf.to_log("\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 dct['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.
	num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
	try:
		conf.find_program(
			'python%s-config' % num,
			var='PYTHON_CONFIG')
	except conf.errors.ConfigurationError:
		conf.find_program(
			'python-config-%s' % num,
			var='PYTHON_CONFIG', mandatory=False)

	includes = []
	if conf.env.PYTHON_CONFIG:
		for incstr in conf.cmd_and_log("%s %s --includes" % (python, conf.env.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.to_log("Include path for Python extensions "
			       "(found via python-config --includes): %r\n" % (includes,))
		env['INCLUDES_PYEXT'] = includes
		env['INCLUDES_PYEMBED'] = includes
	else:
		conf.to_log("Include path for Python extensions "
			       "(found via distutils module): %r\n" % (dct['INCLUDEPY'],))
		env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
		env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]

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

	# See if it compiles
	conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H',
		   uselib='PYEMBED', fragment=FRAG,
		   errmsg='Could not find the python development headers')
Example #30
0
def check_python_headers(conf):
    env = conf.env
    if not env['CC_NAME'] and not env['CXX_NAME']:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if not env['PYTHON_VERSION']:
        conf.check_python_version()
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('Could not find the python executable')
    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")
    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" %
                (pybin, '\n'.join(vals)))
    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]
    if not env.pyext_PATTERN:
        if dct['SO']:
            env.pyext_PATTERN = '%s' + dct['SO']
        else:
            env.pyext_PATTERN = (conf.env.cshlib_PATTERN
                                 or conf.env.cxxshlib_PATTERN).lstrip('lib')
    num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
    conf.find_program([
        ''.join(pybin) + '-config',
        'python%s-config' % num,
        'python-config-%s' % num,
        'python%sm-config' % num
    ],
                      var='PYTHON_CONFIG',
                      msg="python-config")
    all_flags = [['--cflags', '--libs', '--ldflags']]
    if sys.hexversion < 0x2060000:
        all_flags = [[x] for x in all_flags[0]]
    xx = conf.env.CXX_NAME and 'cxx' or 'c'
    for flags in all_flags:
        conf.check_cfg(msg='Asking python-config for pyembed %r flags' %
                       ' '.join(flags),
                       path=conf.env.PYTHON_CONFIG,
                       package='',
                       uselib_store='PYEMBED',
                       args=flags)
    conf.check(header_name='Python.h',
               define_name='HAVE_PYEMBED',
               msg='Getting pyembed flags from python-config',
               fragment=FRAG,
               errmsg='Could not build a python embedded interpreter',
               features='%s %sprogram pyembed' % (xx, xx))
    for flags in all_flags:
        conf.check_cfg(msg='Asking python-config for pyext %r flags' %
                       ' '.join(flags),
                       path=conf.env.PYTHON_CONFIG,
                       package='',
                       uselib_store='PYEXT',
                       args=flags)
    conf.check(header_name='Python.h',
               define_name='HAVE_PYEXT',
               msg='Getting pyext flags from python-config',
               features='%s %sshlib pyext' % (xx, xx),
               fragment=FRAG,
               errmsg='Could not build python extensions')
    conf.define('HAVE_PYTHON_H', 1)
Example #31
0
File: python.py Project: zsx/waf
def check_python_headers(conf):
	"""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) = \
			conf.get_python_variables(python, ["get_config_var('%s')" % 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.to_log("""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))

	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'):
				lib = lib[2:] # strip '-l'
			env.append_value('LIB_PYEMBED', [lib])

	if Options.platform != 'darwin' and python_LDFLAGS:
		env.append_value('LINKFLAGS_PYEMBED', python_LDFLAGS.split())

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

	if python_LIBDIR is not None:
		path = [python_LIBDIR]
		conf.to_log("\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.to_log("\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.to_log("\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.to_log("\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.
	python_config = conf.find_program(
		'python%s-config' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])),
		var='PYTHON_CONFIG')
	if not python_config:
		python_config = conf.find_program(
			'python-config-%s' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])),
			var='PYTHON_CONFIG')

	includes = []
	if python_config:
		for incstr in conf.cmd_and_log("%s %s --includes" % (python, 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.to_log("Include path for Python extensions "
			       "(found via python-config --includes): %r\n" % (includes,))
		env['INCLUDES_PYEXT'] = includes
		env['INCLUDES_PYEMBED'] = includes
	else:
		conf.to_log("Include path for Python extensions "
			       "(found via distutils module): %r\n" % (INCLUDEPY,))
		env['INCLUDES_PYEXT'] = [INCLUDEPY]
		env['INCLUDES_PYEMBED'] = [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'])
	if env['CXX_NAME'] == 'gcc':
		env.append_value('CXXFLAGS_PYEMBED', ['-fno-strict-aliasing'])
		env.append_value('CXXFLAGS_PYEXT', ['-fno-strict-aliasing'])

	# See if it compiles
	conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H',
		   uselib='PYEMBED', fragment=FRAG,
		   errmsg='Could not find the python development headers')
Example #32
0
def check_python_headers(conf):
    env = conf.env
    if not env["CC_NAME"] and not env["CXX_NAME"]:
        conf.fatal("load a compiler first (gcc, g++, ..)")
    if not env["PYTHON_VERSION"]:
        conf.check_python_version()
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal("Could not find the python executable")
    v = "prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS".split()
    try:
        lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")
    vals = ["%s = %r" % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" % (pybin, "\n".join(vals)))
    dct = dict(zip(v, lst))
    x = "MACOSX_DEPLOYMENT_TARGET"
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]
    env["pyext_PATTERN"] = "%s" + dct["SO"]
    all_flags = dct["LDFLAGS"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEMBED")
    all_flags = dct["LDFLAGS"] + " " + dct["LDSHARED"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEXT")
    result = None
    for name in (
        "python" + env["PYTHON_VERSION"],
        "python" + env["PYTHON_VERSION"] + "m",
        "python" + env["PYTHON_VERSION"].replace(".", ""),
    ):
        if not result and env["LIBPATH_PYEMBED"]:
            path = env["LIBPATH_PYEMBED"]
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBPATH_PYEMBED" % name,
            )
        if not result and dct["LIBDIR"]:
            path = [dct["LIBDIR"]]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBDIR" % name,
            )
        if not result and dct["LIBPL"]:
            path = [dct["LIBPL"]]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in python_LIBPL" % name,
            )
        if not result:
            path = [os.path.join(dct["prefix"], "libs")]
            conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in $prefix/libs" % name,
            )
        if result:
            break
    if result:
        env["LIBPATH_PYEMBED"] = path
        env.append_value("LIB_PYEMBED", [name])
    else:
        conf.to_log("\n\n### LIB NOT FOUND\n")
    if Utils.is_win32 or sys.platform.startswith("os2") or dct["Py_ENABLE_SHARED"]:
        env["LIBPATH_PYEXT"] = env["LIBPATH_PYEMBED"]
        env["LIB_PYEXT"] = env["LIB_PYEMBED"]
    num = ".".join(env["PYTHON_VERSION"].split(".")[:2])
    conf.find_program(
        ["".join(pybin) + "-config", "python%s-config" % num, "python-config-%s" % num, "python%sm-config" % num],
        var="PYTHON_CONFIG",
        display_name="python-config",
        mandatory=False,
    )
    includes = []
    if conf.env.PYTHON_CONFIG:
        for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG, "--includes"]).strip().split():
            if incstr.startswith("-I") or incstr.startswith("/I"):
                incstr = incstr[2:]
            if incstr not in includes:
                includes.append(incstr)
        conf.to_log("Include path for Python extensions (found via python-config --includes): %r\n" % (includes,))
        env["INCLUDES_PYEXT"] = includes
        env["INCLUDES_PYEMBED"] = includes
    else:
        conf.to_log("Include path for Python extensions " "(found via distutils module): %r\n" % (dct["INCLUDEPY"],))
        env["INCLUDES_PYEXT"] = [dct["INCLUDEPY"]]
        env["INCLUDES_PYEMBED"] = [dct["INCLUDEPY"]]
    if env["CC_NAME"] == "gcc":
        env.append_value("CFLAGS_PYEMBED", ["-fno-strict-aliasing"])
        env.append_value("CFLAGS_PYEXT", ["-fno-strict-aliasing"])
    if env["CXX_NAME"] == "gcc":
        env.append_value("CXXFLAGS_PYEMBED", ["-fno-strict-aliasing"])
        env.append_value("CXXFLAGS_PYEXT", ["-fno-strict-aliasing"])
    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler

        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value("CFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("CXXFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("LINKFLAGS_PYEXT", dist_compiler.ldflags_shared)
    try:
        conf.check(header_name="Python.h", define_name="HAVE_PYTHON_H", uselib="PYEMBED", fragment=FRAG, errmsg=":-(")
    except conf.errors.ConfigurationError:
        xx = conf.env.CXX_NAME and "cxx" or "c"
        flags = ["--cflags", "--libs", "--ldflags"]
        for f in flags:
            conf.check_cfg(
                msg="Asking python-config for pyembed %s flags" % f,
                path=conf.env.PYTHON_CONFIG,
                package="",
                uselib_store="PYEMBED",
                args=[f],
            )
        conf.check(
            header_name="Python.h",
            define_name="HAVE_PYTHON_H",
            msg="Getting pyembed flags from python-config",
            fragment=FRAG,
            errmsg="Could not build a python embedded interpreter",
            features="%s %sprogram pyembed" % (xx, xx),
        )
        for f in flags:
            conf.check_cfg(
                msg="Asking python-config for pyext %s flags" % f,
                path=conf.env.PYTHON_CONFIG,
                package="",
                uselib_store="PYEXT",
                args=[f],
            )
        conf.check(
            header_name="Python.h",
            define_name="HAVE_PYTHON_H",
            msg="Getting pyext flags from python-config",
            features="%s %sshlib pyext" % (xx, xx),
            fragment=FRAG,
            errmsg="Could not build python extensions",
        )
Example #33
0
def check_python_headers(conf, features='pyembed pyext'):
    features = Utils.to_list(features)
    assert ('pyembed' in features) or (
        'pyext' in features
    ), "check_python_headers features must include 'pyembed' and/or 'pyext'"
    env = conf.env
    if not env['CC_NAME'] and not env['CXX_NAME']:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if conf.python_cross_compile(features):
        return
    if not env['PYTHON_VERSION']:
        conf.check_python_version()
    pybin = env.PYTHON
    if not pybin:
        conf.fatal('Could not find the python executable')
    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")
    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%s\n" %
                (pybin, '\n'.join(vals)))
    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        env[x] = conf.environ[x] = dct[x]
    env['pyext_PATTERN'] = '%s' + dct['SO']
    num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
    conf.find_program([
        ''.join(pybin) + '-config',
        'python%s-config' % num,
        'python-config-%s' % num,
        'python%sm-config' % num
    ],
                      var='PYTHON_CONFIG',
                      msg="python-config",
                      mandatory=False)
    if env.PYTHON_CONFIG:
        all_flags = [['--cflags', '--libs', '--ldflags']]
        if sys.hexversion < 0x2070000:
            all_flags = [[k] for k in all_flags[0]]
        xx = env.CXX_NAME and 'cxx' or 'c'
        if 'pyembed' in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg='Asking python-config for pyembed %r flags' %
                    ' '.join(flags),
                    path=env.PYTHON_CONFIG,
                    package='',
                    uselib_store='PYEMBED',
                    args=flags)
            try:
                conf.test_pyembed(xx)
            except conf.errors.ConfigurationError:
                if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
                    env.append_unique('LIBPATH_PYEMBED', [dct['LIBDIR']])
                    conf.test_pyembed(xx)
                else:
                    raise
        if 'pyext' in features:
            for flags in all_flags:
                conf.check_cfg(msg='Asking python-config for pyext %r flags' %
                               ' '.join(flags),
                               path=env.PYTHON_CONFIG,
                               package='',
                               uselib_store='PYEXT',
                               args=flags)
            try:
                conf.test_pyext(xx)
            except conf.errors.ConfigurationError:
                if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
                    env.append_unique('LIBPATH_PYEXT', [dct['LIBDIR']])
                    conf.test_pyext(xx)
                else:
                    raise
        conf.define('HAVE_PYTHON_H', 1)
        return
    all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEMBED')
    all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEXT')
    result = None
    if not dct["LDVERSION"]:
        dct["LDVERSION"] = env['PYTHON_VERSION']
    for name in ('python' + dct['LDVERSION'],
                 'python' + env['PYTHON_VERSION'] + 'm',
                 'python' + env['PYTHON_VERSION'].replace('.', '')):
        if not result and env['LIBPATH_PYEMBED']:
            path = env['LIBPATH_PYEMBED']
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib='PYEMBED',
                libpath=path,
                mandatory=False,
                msg='Checking for library %s in LIBPATH_PYEMBED' % name)
        if not result and dct['LIBDIR']:
            path = [dct['LIBDIR']]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in LIBDIR' % name)
        if not result and dct['LIBPL']:
            path = [dct['LIBPL']]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in python_LIBPL' %
                                name)
        if not result:
            path = [os.path.join(dct['prefix'], "libs")]
            conf.to_log(
                "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in $prefix/libs' %
                                name)
        if result:
            break
    if result:
        env['LIBPATH_PYEMBED'] = path
        env.append_value('LIB_PYEMBED', [name])
    else:
        conf.to_log("\n\n### LIB NOT FOUND\n")
    if Utils.is_win32 or dct['Py_ENABLE_SHARED']:
        env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED']
        env['LIB_PYEXT'] = env['LIB_PYEMBED']
    conf.to_log(
        "Include path for Python extensions (found via distutils module): %r\n"
        % (dct['INCLUDEPY'], ))
    env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
    env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
    if env['CC_NAME'] == 'gcc':
        env.append_value('CFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CFLAGS_PYEXT', ['-fno-strict-aliasing'])
    if env['CXX_NAME'] == 'gcc':
        env.append_value('CXXFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CXXFLAGS_PYEXT', ['-fno-strict-aliasing'])
    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler
        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)
    conf.check(
        header_name='Python.h',
        define_name='HAVE_PYTHON_H',
        uselib='PYEMBED',
        fragment=FRAG,
        errmsg=
        'Distutils not installed? Broken python installation? Get python-config now!'
    )
Example #34
0
def check_python_headers(conf):
	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
	pybin=conf.env.PYTHON
	if not pybin:
		conf.fatal('could not find the python executable')
	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split()
	try:
		lst=conf.get_python_variables(["get_config_var('%s') or ''"%x for x in v])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")
	vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)]
	conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals)))
	dct=dict(zip(v,lst))
	x='MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		conf.env[x]=conf.environ[x]=dct[x]
	env['pyext_PATTERN']='%s'+dct['SO']
	all_flags=dct['LDFLAGS']+' '+dct['CFLAGS']
	conf.parse_flags(all_flags,'PYEMBED')
	all_flags=dct['LDFLAGS']+' '+dct['LDSHARED']+' '+dct['CFLAGS']
	conf.parse_flags(all_flags,'PYEXT')
	result=None
	for name in('python'+env['PYTHON_VERSION'],'python'+env['PYTHON_VERSION'].replace('.','')):
		if not result and env['LIBPATH_PYEMBED']:
			path=env['LIBPATH_PYEMBED']
			conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n"%path)
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBPATH_PYEMBED'%name)
		if not result and dct['LIBDIR']:
			path=[dct['LIBDIR']]
			conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n"%path)
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBDIR'%name)
		if not result and dct['LIBPL']:
			path=[dct['LIBPL']]
			conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in python_LIBPL'%name)
		if not result:
			path=[os.path.join(dct['prefix'],"libs")]
			conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
			result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in $prefix/libs'%name)
		if result:
			break
	if result:
		env['LIBPATH_PYEMBED']=path
		env.append_value('LIB_PYEMBED',[name])
	else:
		conf.to_log("\n\n### LIB NOT FOUND\n")
	if(Utils.is_win32 or sys.platform.startswith('os2')or dct['Py_ENABLE_SHARED']):
		env['LIBPATH_PYEXT']=env['LIBPATH_PYEMBED']
		env['LIB_PYEXT']=env['LIB_PYEMBED']
	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
	conf.find_program(['python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',mandatory=False)
	includes=[]
	if conf.env.PYTHON_CONFIG:
		for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG,'--includes']).strip().split():
			if(incstr.startswith('-I')or incstr.startswith('/I')):
				incstr=incstr[2:]
			if incstr not in includes:
				includes.append(incstr)
		conf.to_log("Include path for Python extensions (found via python-config --includes): %r\n"%(includes,))
		env['INCLUDES_PYEXT']=includes
		env['INCLUDES_PYEMBED']=includes
	else:
		conf.to_log("Include path for Python extensions ""(found via distutils module): %r\n"%(dct['INCLUDEPY'],))
		env['INCLUDES_PYEXT']=[dct['INCLUDEPY']]
		env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']]
	if env['CC_NAME']=='gcc':
		env.append_value('CFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CFLAGS_PYEXT',['-fno-strict-aliasing'])
	if env['CXX_NAME']=='gcc':
		env.append_value('CXXFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CXXFLAGS_PYEXT',['-fno-strict-aliasing'])
	if env.CC_NAME=="msvc":
		from distutils.msvccompiler import MSVCCompiler
		dist_compiler=MSVCCompiler()
		dist_compiler.initialize()
		env.append_value('CFLAGS_PYEXT',dist_compiler.compile_options)
		env.append_value('CXXFLAGS_PYEXT',dist_compiler.compile_options)
		env.append_value('LINKFLAGS_PYEXT',dist_compiler.ldflags_shared)
	try:
		conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG,errmsg='Could not find the python development headers')
	except conf.errors.ConfigurationError:
		conf.check_cfg(path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=['--cflags','--libs'])
		conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',msg='Getting the python flags from python-config',uselib='PYEMBED',fragment=FRAG,errmsg='Could not find the python development headers elsewhere')
Example #35
0
def check_python_headers(conf):
	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
	pybin=conf.env.PYTHON
	if not pybin:
		conf.fatal('could not find the python executable')
	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split()
	try:
		lst=conf.get_python_variables(["get_config_var('%s')"%x for x in v],['from distutils.sysconfig import get_config_var'])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")
	vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)]
	conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals)))
	dct=dict(zip(v,lst))
	x='MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		conf.env[x]=conf.environ[x]=dct[x]
	env['pyext_PATTERN']='%s'+dct['SO']
	all_flags=dct['LDFLAGS']+' '+dct['LDSHARED']+' '+dct['CFLAGS']
	conf.parse_flags(all_flags,'PYEMBED')
	conf.parse_flags(all_flags,'PYEXT')
	result=None
	name='python'+env['PYTHON_VERSION']
	path=env['LIBPATH_PYEMBED']
	conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n"%path)
	result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False)
	if not result:
		conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n"%path)
		path=[dct['LIBDIR']or'']
		result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False)
	if not result:
		conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
		path=[dct['LIBPL']or'']
		result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False)
	if not result:
		conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
		path=[os.path.join(dct['prefix'],"libs")]
		name='python'+env['PYTHON_VERSION'].replace('.','')
		result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False)
	if result:
		env['LIBPATH_PYEMBED']=path
		env.append_value('LIB_PYEMBED',[name])
	else:
		conf.to_log("\n\n### LIB NOT FOUND\n")
	if(sys.platform=='win32'or sys.platform.startswith('os2')or sys.platform=='darwin'or dct['Py_ENABLE_SHARED']):
		env['LIBPATH_PYEXT']=env['LIBPATH_PYEMBED']
		env['LIB_PYEXT']=env['LIB_PYEMBED']
	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
	try:
		conf.find_program('python%s-config'%num,var='PYTHON_CONFIG')
	except conf.errors.ConfigurationError:
		conf.find_program('python-config-%s'%num,var='PYTHON_CONFIG',mandatory=False)
	includes=[]
	if conf.env.PYTHON_CONFIG:
		for incstr in conf.cmd_and_log(conf.env.PYTHON_CONFIG + ' --includes').strip().split():
			if(incstr.startswith('-I')or incstr.startswith('/I')):
				incstr=incstr[2:]
			if incstr not in includes:
				includes.append(incstr)
		conf.to_log("Include path for Python extensions ""(found via python-config --includes): %r\n"%(includes,))
		env['INCLUDES_PYEXT']=includes
		env['INCLUDES_PYEMBED']=includes
	else:
		conf.to_log("Include path for Python extensions ""(found via distutils module): %r\n"%(dct['INCLUDEPY'],))
		env['INCLUDES_PYEXT']=[dct['INCLUDEPY']]
		env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']]
	if env['CC_NAME']=='gcc':
		env.append_value('CFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CFLAGS_PYEXT',['-fno-strict-aliasing'])
	if env['CXX_NAME']=='gcc':
		env.append_value('CXXFLAGS_PYEMBED',['-fno-strict-aliasing'])
		env.append_value('CXXFLAGS_PYEXT',['-fno-strict-aliasing'])
Example #36
0
def check_python_headers(conf):
    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
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('could not find the python executable')
    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["get_config_var('%s')" % x for x in v],
            ['from distutils.sysconfig import get_config_var'])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")
    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" %
                (pybin, '\n'.join(vals)))
    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]
    env['pyext_PATTERN'] = '%s' + dct['SO']
    all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEMBED')
    conf.parse_flags(all_flags, 'PYEXT')
    result = None
    name = 'python' + env['PYTHON_VERSION']
    path = env['LIBPATH_PYEMBED']
    conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
    result = conf.check(lib=name,
                        uselib='PYEMBED',
                        libpath=path,
                        mandatory=False)
    if not result:
        conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
        path = [dct['LIBDIR'] or '']
        result = conf.check(lib=name,
                            uselib='PYEMBED',
                            libpath=path,
                            mandatory=False)
    if not result:
        conf.to_log(
            "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
        )
        path = [dct['LIBPL'] or '']
        result = conf.check(lib=name,
                            uselib='PYEMBED',
                            libpath=path,
                            mandatory=False)
    if not result:
        conf.to_log(
            "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
        )
        path = [os.path.join(dct['prefix'], "libs")]
        name = 'python' + env['PYTHON_VERSION'].replace('.', '')
        result = conf.check(lib=name,
                            uselib='PYEMBED',
                            libpath=path,
                            mandatory=False)
    if result:
        env['LIBPATH_PYEMBED'] = path
        env.append_value('LIB_PYEMBED', [name])
    else:
        conf.to_log("\n\n### LIB NOT FOUND\n")
    if (sys.platform == 'win32' or sys.platform.startswith('os2')
            or sys.platform == 'darwin' or dct['Py_ENABLE_SHARED']):
        env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED']
        env['LIB_PYEXT'] = env['LIB_PYEMBED']
    num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
    try:
        conf.find_program('python%s-config' % num, var='PYTHON_CONFIG')
    except conf.errors.ConfigurationError:
        conf.find_program('python-config-%s' % num,
                          var='PYTHON_CONFIG',
                          mandatory=False)
    includes = []
    if conf.env.PYTHON_CONFIG:
        for incstr in conf.cmd_and_log(
                conf.env.PYTHON +
            [conf.env.PYTHON_CONFIG, '--includes']).strip().split():
            if (incstr.startswith('-I') or incstr.startswith('/I')):
                incstr = incstr[2:]
            if incstr not in includes:
                includes.append(incstr)
        conf.to_log("Include path for Python extensions "
                    "(found via python-config --includes): %r\n" %
                    (includes, ))
        env['INCLUDES_PYEXT'] = includes
        env['INCLUDES_PYEMBED'] = includes
    else:
        conf.to_log("Include path for Python extensions "
                    "(found via distutils module): %r\n" %
                    (dct['INCLUDEPY'], ))
        env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
        env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
    if env['CC_NAME'] == 'gcc':
        env.append_value('CFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CFLAGS_PYEXT', ['-fno-strict-aliasing'])
    if env['CXX_NAME'] == 'gcc':
        env.append_value('CXXFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CXXFLAGS_PYEXT', ['-fno-strict-aliasing'])
    conf.check(header_name='Python.h',
               define_name='HAVE_PYTHON_H',
               uselib='PYEMBED',
               fragment=FRAG,
               errmsg='Could not find the python development headers')
Example #37
0
def check_python_headers(conf):
    env = conf.env
    if not env['CC_NAME'] and not env['CXX_NAME']:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if not env['PYTHON_VERSION']:
        conf.check_python_version()
    pybin = conf.env.PYTHON
    if not pybin:
        conf.fatal('Could not find the python executable')
    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")
    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" %
                (pybin, '\n'.join(vals)))
    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]
    env['pyext_PATTERN'] = '%s' + dct['SO']
    all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEMBED')
    all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEXT')
    result = None
    for name in ('python' + env['PYTHON_VERSION'],
                 'python' + env['PYTHON_VERSION'].replace('.', '')):
        if not result and env['LIBPATH_PYEMBED']:
            path = env['LIBPATH_PYEMBED']
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib='PYEMBED',
                libpath=path,
                mandatory=False,
                msg='Checking for library %s in LIBPATH_PYEMBED' % name)
        if not result and dct['LIBDIR']:
            path = [dct['LIBDIR']]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in LIBDIR' % name)
        if not result and dct['LIBPL']:
            path = [dct['LIBPL']]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in python_LIBPL' %
                                name)
        if not result:
            path = [os.path.join(dct['prefix'], "libs")]
            conf.to_log(
                "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in $prefix/libs' %
                                name)
        if result:
            break
    if result:
        env['LIBPATH_PYEMBED'] = path
        env.append_value('LIB_PYEMBED', [name])
    else:
        conf.to_log("\n\n### LIB NOT FOUND\n")
    if (Utils.is_win32 or sys.platform.startswith('os2')
            or dct['Py_ENABLE_SHARED']):
        env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED']
        env['LIB_PYEXT'] = env['LIB_PYEMBED']
    num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
    conf.find_program([
        ''.join(pybin) + '-config',
        'python%s-config' % num,
        'python-config-%s' % num,
        'python%sm-config' % num
    ],
                      var='PYTHON_CONFIG',
                      mandatory=False)
    includes = []
    if conf.env.PYTHON_CONFIG:
        for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG,
                                        '--includes']).strip().split():
            if (incstr.startswith('-I') or incstr.startswith('/I')):
                incstr = incstr[2:]
            if incstr not in includes:
                includes.append(incstr)
        conf.to_log(
            "Include path for Python extensions (found via python-config --includes): %r\n"
            % (includes, ))
        env['INCLUDES_PYEXT'] = includes
        env['INCLUDES_PYEMBED'] = includes
    else:
        conf.to_log("Include path for Python extensions "
                    "(found via distutils module): %r\n" %
                    (dct['INCLUDEPY'], ))
        env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
        env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]
    if env['CC_NAME'] == 'gcc':
        env.append_value('CFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CFLAGS_PYEXT', ['-fno-strict-aliasing'])
    if env['CXX_NAME'] == 'gcc':
        env.append_value('CXXFLAGS_PYEMBED', ['-fno-strict-aliasing'])
        env.append_value('CXXFLAGS_PYEXT', ['-fno-strict-aliasing'])
    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler
        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)
    try:
        conf.check(header_name='Python.h',
                   define_name='HAVE_PYTHON_H',
                   uselib='PYEMBED',
                   fragment=FRAG,
                   errmsg=':-(')
    except conf.errors.ConfigurationError:
        xx = conf.env.CXX_NAME and 'cxx' or 'c'
        conf.check_cfg(msg='Asking python-config for the flags (pyembed)',
                       path=conf.env.PYTHON_CONFIG,
                       package='',
                       uselib_store='PYEMBED',
                       args=['--cflags', '--libs', '--ldflags'])
        conf.check(header_name='Python.h',
                   define_name='HAVE_PYTHON_H',
                   msg='Getting pyembed flags from python-config',
                   fragment=FRAG,
                   errmsg='Could not build a python embedded interpreter',
                   features='%s %sprogram pyembed' % (xx, xx))
        conf.check_cfg(msg='Asking python-config for the flags (pyext)',
                       path=conf.env.PYTHON_CONFIG,
                       package='',
                       uselib_store='PYEXT',
                       args=['--cflags', '--libs', '--ldflags'])
        conf.check(header_name='Python.h',
                   define_name='HAVE_PYTHON_H',
                   msg='Getting pyext flags from python-config',
                   features='%s %sshlib pyext' % (xx, xx),
                   fragment=FRAG,
                   errmsg='Could not build python extensions')
Example #38
0
def check_python_headers(conf, features='pyembed pyext'):
	"""
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

	* PYEXT: for compiling python extensions
	* PYEMBED: for embedding a python interpreter
	"""
	features = Utils.to_list(features)
	assert ('pyembed' in features) or ('pyext' in features), "check_python_headers features must include 'pyembed' and/or 'pyext'"
	env = conf.env
	if not env.CC_NAME and not env.CXX_NAME:
		conf.fatal('load a compiler first (gcc, g++, ..)')

	# bypass all the code below for cross-compilation
	if conf.python_cross_compile(features):
		return

	if not env.PYTHON_VERSION:
		conf.check_python_version()

	pybin = env.PYTHON
	if not pybin:
		conf.fatal('Could not find the python executable')

	# so we actually do all this for compatibility reasons and for obtaining pyext_PATTERN below
	v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
	try:
		lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")

	vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
	conf.to_log("Configuration returned from %r:\n%s\n" % (pybin, '\n'.join(vals)))

	dct = dict(zip(v, lst))
	x = 'MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		env[x] = conf.environ[x] = dct[x]
	env.pyext_PATTERN = '%s' + dct['SO'] # not a mistake


	# Try to get pythonX.Y-config
	num = '.'.join(env.PYTHON_VERSION.split('.')[:2])
	conf.find_program([''.join(pybin) + '-config', 'python%s-config' % num, 'python-config-%s' % num, 'python%sm-config' % num], var='PYTHON_CONFIG', msg="python-config", mandatory=False)

	if env.PYTHON_CONFIG:
		# python2.6-config requires 3 runs
		all_flags = [['--cflags', '--libs', '--ldflags']]
		if sys.hexversion < 0x2070000:
			all_flags = [[k] for k in all_flags[0]]

		xx = env.CXX_NAME and 'cxx' or 'c'

		if 'pyembed' in features:
			for flags in all_flags:
				conf.check_cfg(msg='Asking python-config for pyembed %r flags' % ' '.join(flags), path=env.PYTHON_CONFIG, package='', uselib_store='PYEMBED', args=flags)

			try:
				conf.test_pyembed(xx)
			except conf.errors.ConfigurationError:
				# python bug 7352
				if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
					env.append_unique('LIBPATH_PYEMBED', [dct['LIBDIR']])
					conf.test_pyembed(xx)
				else:
					raise

		if 'pyext' in features:
			for flags in all_flags:
				conf.check_cfg(msg='Asking python-config for pyext %r flags' % ' '.join(flags), path=env.PYTHON_CONFIG, package='', uselib_store='PYEXT', args=flags)

			try:
				conf.test_pyext(xx)
			except conf.errors.ConfigurationError:
				# python bug 7352
				if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
					env.append_unique('LIBPATH_PYEXT', [dct['LIBDIR']])
					conf.test_pyext(xx)
				else:
					raise

		conf.define('HAVE_PYTHON_H', 1)
		return

	# No python-config, do something else on windows systems
	all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
	conf.parse_flags(all_flags, 'PYEMBED')

	all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
	conf.parse_flags(all_flags, 'PYEXT')

	result = None
	if not dct["LDVERSION"]:
		dct["LDVERSION"] = env.PYTHON_VERSION

	# further simplification will be complicated
	for name in ('python' + dct['LDVERSION'], 'python' + env.PYTHON_VERSION + 'm', 'python' + env.PYTHON_VERSION.replace('.', '')):

		# LIBPATH_PYEMBED is already set; see if it works.
		if not result and env.LIBPATH_PYEMBED:
			path = env.LIBPATH_PYEMBED
			conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBPATH_PYEMBED' % name)

		if not result and dct['LIBDIR']:
			path = [dct['LIBDIR']]
			conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBDIR' % name)

		if not result and dct['LIBPL']:
			path = [dct['LIBPL']]
			conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in python_LIBPL' % name)

		if not result:
			path = [os.path.join(dct['prefix'], "libs")]
			conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in $prefix/libs' % name)

		if result:
			break # do not forget to set LIBPATH_PYEMBED

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

	# under certain conditions, python extensions must link to
	# python libraries, not just python embedding programs.
	if Utils.is_win32 or dct['Py_ENABLE_SHARED']:
		env.LIBPATH_PYEXT = env.LIBPATH_PYEMBED
		env.LIB_PYEXT = env.LIB_PYEMBED

	conf.to_log("Include path for Python extensions (found via distutils module): %r\n" % (dct['INCLUDEPY'],))
	env.INCLUDES_PYEXT = [dct['INCLUDEPY']]
	env.INCLUDES_PYEMBED = [dct['INCLUDEPY']]

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

	if env.CC_NAME == "msvc":
		from distutils.msvccompiler import MSVCCompiler
		dist_compiler = MSVCCompiler()
		dist_compiler.initialize()
		env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
		env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
		env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)

	# See if it compiles
	conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H', uselib='PYEMBED', fragment=FRAG, errmsg='Distutils not installed? Broken python installation? Get python-config now!')
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,
               strict=False):
    '''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

    if addmain:
        fragment = '%s\n int main(void) { %s; return 0; }\n' % (hdrs, code)
    else:
        fragment = '%s\n%s\n' % (hdrs, code)

    if msg is None:
        msg = "Checking for %s" % define

    cflags = TO_LIST(cflags)

    # Be strict when relying on a compiler check
    # Some compilers (e.g. xlc) ignore non-supported features as warnings
    if strict:
        if 'WERROR_CFLAGS' in conf.env:
            cflags.extend(conf.env['WERROR_CFLAGS'])

    if local_include:
        cflags.append('-I%s' % conf.path.abspath())

    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:
        test_args = conf.SAMBA_CROSS_ARGS(msg=msg)
    else:
        test_args = []

    conf.COMPOUND_START(msg)

    try:
        ret = conf.check(fragment=fragment,
                         execute=execute,
                         define_name=define,
                         cflags=cflags,
                         ldflags=ldflags,
                         includes=includes,
                         uselib=uselib,
                         type=type,
                         msg=msg,
                         quote=quote,
                         test_args=test_args,
                         define_ret=define_ret)
    except Exception:
        if always:
            conf.DEFINE(define, 0)
        else:
            conf.undefine(define)
        conf.COMPOUND_END(False)
        if mandatory:
            raise
        return False
    else:
        # Success is indicated by ret but we should unset
        # defines set by WAF's c_config.check() because it
        # defines it to int(ret) and we want to undefine it
        if not ret:
            conf.undefine(define)
            conf.COMPOUND_END(False)
            return False
        if not define_ret:
            conf.DEFINE(define, 1)
            conf.COMPOUND_END(True)
        else:
            conf.DEFINE(define, ret, quote=quote)
            conf.COMPOUND_END(ret)
        return True
Example #40
0
def check_python_headers(conf, features="pyembed pyext"):
    """
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

	* PYEXT: for compiling python extensions
	* PYEMBED: for embedding a python interpreter
	"""
    features = Utils.to_list(features)
    assert ("pyembed" in features) or (
        "pyext" in features
    ), "check_python_headers features must include 'pyembed' and/or 'pyext'"
    env = conf.env
    if not env["CC_NAME"] and not env["CXX_NAME"]:
        conf.fatal("load a compiler first (gcc, g++, ..)")

        # bypass all the code below for cross-compilation
    if conf.python_cross_compile(features):
        return

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

    pybin = env.PYTHON
    if not pybin:
        conf.fatal("Could not find the python executable")

        # so we actually do all this for compatibility reasons and for obtaining pyext_PATTERN below
    v = "prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION".split()
    try:
        lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")

    vals = ["%s = %r" % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%s\n" % (pybin, "\n".join(vals)))

    dct = dict(zip(v, lst))
    x = "MACOSX_DEPLOYMENT_TARGET"
    if dct[x]:
        env[x] = conf.environ[x] = dct[x]
    env["pyext_PATTERN"] = "%s" + dct["SO"]  # not a mistake

    # Try to get pythonX.Y-config
    num = ".".join(env["PYTHON_VERSION"].split(".")[:2])
    conf.find_program(
        ["".join(pybin) + "-config", "python%s-config" % num, "python-config-%s" % num, "python%sm-config" % num],
        var="PYTHON_CONFIG",
        msg="python-config",
        mandatory=False,
    )

    if env.PYTHON_CONFIG:
        # python2.6-config requires 3 runs
        all_flags = [["--cflags", "--libs", "--ldflags"]]
        if sys.hexversion < 0x2070000:
            all_flags = [[k] for k in all_flags[0]]

        xx = env.CXX_NAME and "cxx" or "c"

        if "pyembed" in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg="Asking python-config for pyembed %r flags" % " ".join(flags),
                    path=env.PYTHON_CONFIG,
                    package="",
                    uselib_store="PYEMBED",
                    args=flags,
                )

            conf.check(
                header_name="Python.h",
                define_name="HAVE_PYEMBED",
                msg="Getting pyembed flags from python-config",
                fragment=FRAG,
                errmsg="Could not build a python embedded interpreter",
                features="%s %sprogram pyembed" % (xx, xx),
            )

        if "pyext" in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg="Asking python-config for pyext %r flags" % " ".join(flags),
                    path=env.PYTHON_CONFIG,
                    package="",
                    uselib_store="PYEXT",
                    args=flags,
                )

            conf.check(
                header_name="Python.h",
                define_name="HAVE_PYEXT",
                msg="Getting pyext flags from python-config",
                features="%s %sshlib pyext" % (xx, xx),
                fragment=FRAG,
                errmsg="Could not build python extensions",
            )

        conf.define("HAVE_PYTHON_H", 1)
        return

        # No python-config, do something else on windows systems
    all_flags = dct["LDFLAGS"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEMBED")

    all_flags = dct["LDFLAGS"] + " " + dct["LDSHARED"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEXT")

    result = None
    if not dct["LDVERSION"]:
        dct["LDVERSION"] = env["PYTHON_VERSION"]

        # further simplification will be complicated
    for name in (
        "python" + dct["LDVERSION"],
        "python" + env["PYTHON_VERSION"] + "m",
        "python" + env["PYTHON_VERSION"].replace(".", ""),
    ):

        # LIBPATH_PYEMBED is already set; see if it works.
        if not result and env["LIBPATH_PYEMBED"]:
            path = env["LIBPATH_PYEMBED"]
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBPATH_PYEMBED" % name,
            )

        if not result and dct["LIBDIR"]:
            path = [dct["LIBDIR"]]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in LIBDIR" % name,
            )

        if not result and dct["LIBPL"]:
            path = [dct["LIBPL"]]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in python_LIBPL" % name,
            )

        if not result:
            path = [os.path.join(dct["prefix"], "libs")]
            conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
            result = conf.check(
                lib=name,
                uselib="PYEMBED",
                libpath=path,
                mandatory=False,
                msg="Checking for library %s in $prefix/libs" % name,
            )

        if result:
            break  # do not forget to set LIBPATH_PYEMBED

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

        # under certain conditions, python extensions must link to
        # python libraries, not just python embedding programs.
    if Utils.is_win32 or dct["Py_ENABLE_SHARED"]:
        env["LIBPATH_PYEXT"] = env["LIBPATH_PYEMBED"]
        env["LIB_PYEXT"] = env["LIB_PYEMBED"]

    conf.to_log("Include path for Python extensions (found via distutils module): %r\n" % (dct["INCLUDEPY"],))
    env["INCLUDES_PYEXT"] = [dct["INCLUDEPY"]]
    env["INCLUDES_PYEMBED"] = [dct["INCLUDEPY"]]

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

    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler

        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value("CFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("CXXFLAGS_PYEXT", dist_compiler.compile_options)
        env.append_value("LINKFLAGS_PYEXT", dist_compiler.ldflags_shared)

        # See if it compiles
    conf.check(
        header_name="Python.h",
        define_name="HAVE_PYTHON_H",
        uselib="PYEMBED",
        fragment=FRAG,
        errmsg="Distutils not installed? Broken python installation? Get python-config now!",
    )
def check_python_headers(conf, features='pyembed pyext'):
    """
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

	* PYEXT: for compiling python extensions
	* PYEMBED: for embedding a python interpreter
	"""
    features = Utils.to_list(features)
    assert ('pyembed' in features) or (
        'pyext' in features
    ), "check_python_headers features must include 'pyembed' and/or 'pyext'"
    env = conf.env
    if not env.CC_NAME and not env.CXX_NAME:
        conf.fatal('load a compiler first (gcc, g++, ..)')

    # bypass all the code below for cross-compilation
    if conf.python_cross_compile(features):
        return

    if not env.PYTHON_VERSION:
        conf.check_python_version()

    pybin = env.PYTHON
    if not pybin:
        conf.fatal('Could not find the python executable')

    # so we actually do all this for compatibility reasons and for obtaining pyext_PATTERN below
    v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split(
    )
    try:
        lst = conf.get_python_variables(
            ["get_config_var('%s') or ''" % x for x in v])
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")

    vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%s\n" %
                (pybin, '\n'.join(vals)))

    dct = dict(zip(v, lst))
    x = 'MACOSX_DEPLOYMENT_TARGET'
    if dct[x]:
        env[x] = conf.environ[x] = dct[x]
    env.pyext_PATTERN = '%s' + dct['SO']  # not a mistake

    # Try to get pythonX.Y-config
    num = '.'.join(env.PYTHON_VERSION.split('.')[:2])
    conf.find_program([
        ''.join(pybin) + '-config',
        'python%s-config' % num,
        'python-config-%s' % num,
        'python%sm-config' % num
    ],
                      var='PYTHON_CONFIG',
                      msg="python-config",
                      mandatory=False)

    if env.PYTHON_CONFIG:
        # python2.6-config requires 3 runs
        all_flags = [['--cflags', '--libs', '--ldflags']]
        if sys.hexversion < 0x2070000:
            all_flags = [[k] for k in all_flags[0]]

        xx = env.CXX_NAME and 'cxx' or 'c'

        if 'pyembed' in features:
            for flags in all_flags:
                conf.check_cfg(
                    msg='Asking python-config for pyembed %r flags' %
                    ' '.join(flags),
                    path=env.PYTHON_CONFIG,
                    package='',
                    uselib_store='PYEMBED',
                    args=flags)

            try:
                conf.test_pyembed(xx)
            except conf.errors.ConfigurationError:
                # python bug 7352
                if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
                    env.append_unique('LIBPATH_PYEMBED', [dct['LIBDIR']])
                    conf.test_pyembed(xx)
                else:
                    raise

        if 'pyext' in features:
            for flags in all_flags:
                conf.check_cfg(msg='Asking python-config for pyext %r flags' %
                               ' '.join(flags),
                               path=env.PYTHON_CONFIG,
                               package='',
                               uselib_store='PYEXT',
                               args=flags)

            try:
                conf.test_pyext(xx)
            except conf.errors.ConfigurationError:
                # python bug 7352
                if dct['Py_ENABLE_SHARED'] and dct['LIBDIR']:
                    env.append_unique('LIBPATH_PYEXT', [dct['LIBDIR']])
                    conf.test_pyext(xx)
                else:
                    raise

        conf.define('HAVE_PYTHON_H', 1)
        return

    # No python-config, do something else on windows systems
    all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEMBED')

    all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
    conf.parse_flags(all_flags, 'PYEXT')

    result = None
    if not dct["LDVERSION"]:
        dct["LDVERSION"] = env.PYTHON_VERSION

    # further simplification will be complicated
    for name in ('python' + dct['LDVERSION'],
                 'python' + env.PYTHON_VERSION + 'm',
                 'python' + env.PYTHON_VERSION.replace('.', '')):

        # LIBPATH_PYEMBED is already set; see if it works.
        if not result and env.LIBPATH_PYEMBED:
            path = env.LIBPATH_PYEMBED
            conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
            result = conf.check(
                lib=name,
                uselib='PYEMBED',
                libpath=path,
                mandatory=False,
                msg='Checking for library %s in LIBPATH_PYEMBED' % name)

        if not result and dct['LIBDIR']:
            path = [dct['LIBDIR']]
            conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in LIBDIR' % name)

        if not result and dct['LIBPL']:
            path = [dct['LIBPL']]
            conf.to_log(
                "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in python_LIBPL' %
                                name)

        if not result:
            path = [os.path.join(dct['prefix'], "libs")]
            conf.to_log(
                "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n"
            )
            result = conf.check(lib=name,
                                uselib='PYEMBED',
                                libpath=path,
                                mandatory=False,
                                msg='Checking for library %s in $prefix/libs' %
                                name)

        if result:
            break  # do not forget to set LIBPATH_PYEMBED

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

    # under certain conditions, python extensions must link to
    # python libraries, not just python embedding programs.
    if Utils.is_win32 or dct['Py_ENABLE_SHARED']:
        env.LIBPATH_PYEXT = env.LIBPATH_PYEMBED
        env.LIB_PYEXT = env.LIB_PYEMBED

    conf.to_log(
        "Include path for Python extensions (found via distutils module): %r\n"
        % (dct['INCLUDEPY'], ))
    env.INCLUDES_PYEXT = [dct['INCLUDEPY']]
    env.INCLUDES_PYEMBED = [dct['INCLUDEPY']]

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

    if env.CC_NAME == "msvc":
        from distutils.msvccompiler import MSVCCompiler
        dist_compiler = MSVCCompiler()
        dist_compiler.initialize()
        env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
        env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)

    # See if it compiles
    conf.check(
        header_name='Python.h',
        define_name='HAVE_PYTHON_H',
        uselib='PYEMBED',
        fragment=FRAG,
        errmsg=
        'Distutils not installed? Broken python installation? Get python-config now!'
    )
Example #42
0
def configure(conf):
	conf.find_msgfmt()
	conf.find_intltool_merge()
	if conf.env.CC or conf.env.CXX:
		conf.check(header_name='locale.h')
Example #43
0
def check_python_headers(conf):
	"""
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

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

	# FIXME rewrite

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

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

	pybin = conf.env.PYTHON
	if not pybin:
		conf.fatal('Could not find the python executable')

	v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
	try:
		lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
	except RuntimeError:
		conf.fatal("Python development headers not found (-v for details).")

	vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
	conf.to_log("Configuration returned from %r:\n%r\n" % (pybin, '\n'.join(vals)))

	dct = dict(zip(v, lst))
	x = 'MACOSX_DEPLOYMENT_TARGET'
	if dct[x]:
		conf.env[x] = conf.environ[x] = dct[x]

	env['pyext_PATTERN'] = '%s' + dct['SO'] # not a mistake

	# Check for python libraries for embedding

	all_flags = dct['LDFLAGS'] + ' ' + dct['CFLAGS']
	conf.parse_flags(all_flags, 'PYEMBED')

	all_flags = dct['LDFLAGS'] + ' ' + dct['LDSHARED'] + ' ' + dct['CFLAGS']
	conf.parse_flags(all_flags, 'PYEXT')

	result = None
	#name = 'python' + env['PYTHON_VERSION']

	if not dct["LDVERSION"]:
		dct["LDVERSION"] = env['PYTHON_VERSION']

	# TODO simplify this
	for name in ('python' + dct['LDVERSION'], 'python' + env['PYTHON_VERSION'] + 'm', 'python' + env['PYTHON_VERSION'].replace('.', '')):

		# LIBPATH_PYEMBED is already set; see if it works.
		if not result and env['LIBPATH_PYEMBED']:
			path = env['LIBPATH_PYEMBED']
			conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBPATH_PYEMBED' % name)

		if not result and dct['LIBDIR']:
			path = [dct['LIBDIR']]
			conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in LIBDIR' % name)

		if not result and dct['LIBPL']:
			path = [dct['LIBPL']]
			conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n")
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in python_LIBPL' % name)

		if not result:
			path = [os.path.join(dct['prefix'], "libs")]
			conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n")
			result = conf.check(lib=name, uselib='PYEMBED', libpath=path, mandatory=False, msg='Checking for library %s in $prefix/libs' % name)

		if result:
			break # do not forget to set LIBPATH_PYEMBED

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

	# under certain conditions, python extensions must link to
	# python libraries, not just python embedding programs.
	if (Utils.is_win32 or sys.platform.startswith('os2')
		or dct['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.
	num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
	conf.find_program([''.join(pybin) + '-config', 'python%s-config' % num, 'python-config-%s' % num, 'python%sm-config' % num], var='PYTHON_CONFIG', mandatory=False)

	includes = []
	if conf.env.PYTHON_CONFIG:
		for incstr in conf.cmd_and_log([ conf.env.PYTHON_CONFIG, '--includes']).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.to_log("Include path for Python extensions (found via python-config --includes): %r\n" % (includes,))
		env['INCLUDES_PYEXT'] = includes
		env['INCLUDES_PYEMBED'] = includes
	else:
		conf.to_log("Include path for Python extensions "
			       "(found via distutils module): %r\n" % (dct['INCLUDEPY'],))
		env['INCLUDES_PYEXT'] = [dct['INCLUDEPY']]
		env['INCLUDES_PYEMBED'] = [dct['INCLUDEPY']]

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

	if env.CC_NAME == "msvc":
		from distutils.msvccompiler import MSVCCompiler
		dist_compiler = MSVCCompiler()
		dist_compiler.initialize()
		env.append_value('CFLAGS_PYEXT', dist_compiler.compile_options)
		env.append_value('CXXFLAGS_PYEXT', dist_compiler.compile_options)
		env.append_value('LINKFLAGS_PYEXT', dist_compiler.ldflags_shared)

	# See if it compiles
	try:
		conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H',
		   uselib='PYEMBED', fragment=FRAG,
		   errmsg=':-(')
	except conf.errors.ConfigurationError:
		# python3.2, oh yeah
		xx = conf.env.CXX_NAME and 'cxx' or 'c'

		flags = ['--cflags', '--libs', '--ldflags']

		for f in flags:
			conf.check_cfg(msg='Asking python-config for pyembed %s flags' % f,
				path=conf.env.PYTHON_CONFIG, package='', uselib_store='PYEMBED', args=[f])
		conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H', msg='Getting pyembed flags from python-config',
			fragment=FRAG, errmsg='Could not build a python embedded interpreter',
			features='%s %sprogram pyembed' % (xx, xx))

		for f in flags:
			conf.check_cfg(msg='Asking python-config for pyext %s flags' % f,
				path=conf.env.PYTHON_CONFIG, package='', uselib_store='PYEXT', args=[f])
		conf.check(header_name='Python.h', define_name='HAVE_PYTHON_H', msg='Getting pyext flags from python-config',
			features='%s %sshlib pyext' % (xx, xx), fragment=FRAG, errmsg='Could not build python extensions')
Example #44
0
def check_python_headers(conf):
    """
	Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
	On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:

	* 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")

    v = "prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS".split()
    try:
        lst = conf.get_python_variables(
            python, ["get_config_var('%s')" % x for x in v], ["from distutils.sysconfig import get_config_var"]
        )
    except RuntimeError:
        conf.fatal("Python development headers not found (-v for details).")

    vals = ["%s = %r" % (x, y) for (x, y) in zip(v, lst)]
    conf.to_log("Configuration returned from %r:\n%r\n" % (python, "\n".join(vals)))

    dct = dict(zip(v, lst))
    x = "MACOSX_DEPLOYMENT_TARGET"
    if dct[x]:
        conf.env[x] = conf.environ[x] = dct[x]

    env["pyext_PATTERN"] = "%s" + dct["SO"]  # not a mistake

    # Check for python libraries for embedding

    all_flags = dct["LDFLAGS"] + " " + dct["LDSHARED"] + " " + dct["CFLAGS"]
    conf.parse_flags(all_flags, "PYEMBED")
    conf.parse_flags(all_flags, "PYEXT")

    result = None
    name = "python" + env["PYTHON_VERSION"]

    # LIBPATH_PYEMBED is already set; see if it works.
    path = env["LIBPATH_PYEMBED"]
    conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n" % path)
    result = conf.check(lib=name, uselib="PYEMBED", libpath=path, mandatory=False)

    if not result:
        conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n" % path)
        path = [dct["LIBDIR"] or ""]
        result = conf.check(lib=name, uselib="PYEMBED", libpath=path, mandatory=False)

    if not result:
        conf.to_log(
            "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n"
        )
        path = [dct["LIBPL"] or ""]
        result = conf.check(lib=name, uselib="PYEMBED", libpath=path, mandatory=False)

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

    if result:
        env["LIBPATH_PYEMBED"] = path
        env.append_value("LIB_PYEMBED", [name])
    else:
        conf.to_log("\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 dct["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.
    num = ".".join(env["PYTHON_VERSION"].split(".")[:2])
    try:
        conf.find_program("python%s-config" % num, var="PYTHON_CONFIG")
    except conf.errors.ConfigurationError:
        conf.find_program("python-config-%s" % num, var="PYTHON_CONFIG", mandatory=False)

    includes = []
    if conf.env.PYTHON_CONFIG:
        for incstr in conf.cmd_and_log("%s %s --includes" % (python, conf.env.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.to_log("Include path for Python extensions " "(found via python-config --includes): %r\n" % (includes,))
        env["INCLUDES_PYEXT"] = includes
        env["INCLUDES_PYEMBED"] = includes
    else:
        conf.to_log("Include path for Python extensions " "(found via distutils module): %r\n" % (dct["INCLUDEPY"],))
        env["INCLUDES_PYEXT"] = [dct["INCLUDEPY"]]
        env["INCLUDES_PYEMBED"] = [dct["INCLUDEPY"]]

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

        # See if it compiles
    conf.check(
        header_name="Python.h",
        define_name="HAVE_PYTHON_H",
        uselib="PYEMBED",
        fragment=FRAG,
        errmsg="Could not find the python development headers",
    )