예제 #1
0
def check_ns3_modules(conf,modules,mandatory=True):
	import os
	if not'NS3_CHECK_MODULE_ONCE'in conf.env:
		conf.env['NS3_CHECK_MODULE_ONCE']=''
		conf.check_cfg(atleast_pkgconfig_version='0.0.0')
		if conf.options.debug:
			conf.env.append_value('DEFINES','NS3_LOG_ENABLE')
	conf._check_dependencies(modules,mandatory)
예제 #2
0
파일: ns3.py 프로젝트: takahiro33/ICC
def check_ns3_modules(conf, modules, mandatory=True):
    import os
    if not 'NS3_CHECK_MODULE_ONCE' in conf.env:
        conf.env['NS3_CHECK_MODULE_ONCE'] = ''
        conf.check_cfg(atleast_pkgconfig_version='0.0.0')
        if conf.options.debug:
            conf.env.append_value('DEFINES', 'NS3_LOG_ENABLE')
    conf._check_dependencies(modules, mandatory)
예제 #3
0
def check_sdl(conf):
	conf.start_msg('Checking for SDL (2.x - sdl2-config)')
	try:
		conf.check_cfg(path='sdl2-config', args='--cflags --libs', package='', uselib_store='SDL')
	except:
		conf.end_msg('sdl2-config not found in the PATH', 'RED')
		return 1
	conf.end_msg('ok')
	conf.env.DEFINES_SDL += ['USE_SDL']
	return 1
예제 #4
0
파일: sdl.py 프로젝트: jbmouret/libfastsim
def check_sdl(conf):
	conf.start_msg('Checking for SDL (1.2 - sdl-config)')

	try:
		conf.check_cfg(path='sdl-config', args='--cflags --libs', package='', uselib_store='SDL')
	except:
		conf.end_msg('sdl-config not found', 'RED')
		return 1
	conf.end_msg('ok')
	conf.env.DEFINES_SDL += ['USE_SDL']
	return 1
예제 #5
0
def magic_check_library(conf, package, mandatory=True, **kwargs):
    # special casing for ROOT
    if package == "root":
        res = conf.check_cfg(
            path="root-config", package="", uselib_store=package, args="--libs --cflags", mandatory=mandatory, **kwargs
        )
    else:
        res = conf.check_cfg(
            package=package, uselib_store=package, args="--libs --cflags", mandatory=mandatory, **kwargs
        )
    conf.env.HAVE_LIBRARY[package] = res
    return res
예제 #6
0
def check_ssl(conf):
    if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
        libcrypto = conf.check_cc(lib='crypto',
                                  header_name='openssl/crypto.h',
                                  define_name='HAVE_SSL',
                                  uselib_store='SSL')
    else:
        conf.define("HAVE_SSL", 1)
    if not conf.get_define ("HAVE_SSL"):
        conf.fatal("Cannot find SSL libraries")
예제 #7
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)
예제 #8
0
def check_sdl(conf, *k, **kw):
    def fail(msg, required):
        if required:
            conf.fatal(msg)
        conf.end_msg(msg, 'RED')

    def get_directory(filename, dirs):
        res = conf.find_file(filename, dirs)
        return res[:-len(filename) - 1]

    required = kw.get('required', False)
    conf.start_msg('Checking for SDL (2.x - sdl2-config)')
    try:
        conf.check_cfg(path='sdl2-config',
                       args='--cflags --libs',
                       package='',
                       uselib_store='SDL')
    except:
        fail('sdl2-config not found in the PATH', required)
        return
    conf.end_msg('OK')
    conf.env.DEFINES_SDL += ['USE_SDL']
    return
예제 #9
0
def _check_dependencies(conf,modules,mandatory):
	found=[]
	libversion="optimized"
	if conf.options.debug:
		libversion="debug"
	if not isinstance(modules,list):
		modules=Utils.to_list(modules)
	for module in modules:
		retval=conf.check_cfg(package='libns3-dev-%s-%s'%(module,libversion),args='--cflags --libs',mandatory=mandatory,msg="Checking for ns3-%s"%module,uselib_store='NS3_%s'%module.upper())
		if not retval is None:
			found.append(module)
	import copy
	if not'NS3_MODULES_FOUND'in conf.env:
		conf.env['NS3_MODULES_FOUND']=[]
	conf.env['NS3_MODULES_FOUND']=conf.env['NS3_MODULES_FOUND']+copy.copy(found)
예제 #10
0
파일: ns3.py 프로젝트: zhenkai/sync
def _check_dependencies(conf, required, mandatory):
    # Logs.pprint ('CYAN', '  + %s' % required)
    found = []
    
    libversion = "optimized"
    if conf.options.ns3_debug:
        libversion = "debug"
    
    for module in required:
        retval = conf.check_cfg(package = 'libns3-dev-%s-%s' % (module, libversion),
                                args='--cflags --libs', mandatory=mandatory,
                                msg="Checking for ns3-%s" % module,
                                uselib_store='NS3_%s' % module.upper())
        # Logs.pprint ('CYAN', 'NS3_%s' % module.upper())
        if not retval is None:
            found.append(module)
    import copy
    if not 'NS3_MODULES_FOUND' in conf.env:
        conf.env['NS3_MODULES_FOUND'] = []
    conf.env['NS3_MODULES_FOUND'] = conf.env['NS3_MODULES_FOUND'] + copy.copy(found)
예제 #11
0
파일: ns3.py 프로젝트: takahiro33/ICC
def _check_dependencies(conf, modules, mandatory):
    found = []
    libversion = "optimized"
    if conf.options.debug:
        libversion = "debug"
    if not isinstance(modules, list):
        modules = Utils.to_list(modules)
    for module in modules:
        retval = conf.check_cfg(package='libns3-dev-%s-%s' %
                                (module, libversion),
                                args='--cflags --libs',
                                mandatory=mandatory,
                                msg="Checking for ns3-%s" % module,
                                uselib_store='NS3_%s' % module.upper())
        if not retval is None:
            found.append(module)
    import copy
    if not 'NS3_MODULES_FOUND' in conf.env:
        conf.env['NS3_MODULES_FOUND'] = []
    conf.env['NS3_MODULES_FOUND'] = conf.env['NS3_MODULES_FOUND'] + copy.copy(
        found)
예제 #12
0
def configure(conf):
    conf.load('compiler_c intltool')

    path, version = get_pkg_path_and_version("pidgin")
    conf.env.PIDGIN_PATH = path
    conf.env.PURPLE_PATH = join(path, "libpurple")
    conf.env.PURPLE_VERSION = version

    if conf.env.PURPLE_SSL:
        # Order matters: It seems like ssl-gnutls has to be loaded before
        # core-ssl to be found (see ssl.c:probe_ssl_plugins)
        conf.env.PURPLE_PLUGINS += ["ssl-" + conf.env.PURPLE_SSL, "ssl"]

        conf.env.append_value("LIB_PURPLE_BUILD", ["gnutls"])

    plugins = conf.env.PURPLE_PLUGINS

    conf.check_cfg(atleast_pkgconfig_version='0.1')
    conf.check_cfg(package='libxml-2.0',
                   uselib_store='XML',
                   args=['--cflags', '--libs'])

    conf.env.append_value("DEFINES_PURPLE_BUILD", ["HAVE_CONFIG_H"])
    conf.env.append_value("INCLUDES_PURPLE_BUILD",
                          ["libpurple_config", conf.env.PURPLE_PATH])
    conf.env.append_value("LIB_PURPLE_BUILD", ["resolv"])

    # We are going to build a shared library
    conf.env.append_value("CFLAGS_PURPLE_BUILD", ["-fPIC"])

    headers = [
        "arpa/nameser_compat", "fcntl", "sys/time", "unistd", "locale",
        "libintl", "signal", "stdint", "regex"
    ]

    for i in headers:
        conf.check_cc(header_name=i + ".h",
                      mandatory=False,
                      auto_add_header_name=True)

    conf.define("PURPLE_PLUGINS", 1)
    conf.define("HAVE_GETIFADDRS", 1)
    conf.define("HAVE_INET_NTOP", 1)
    conf.define("HAVE_INET_ATON", 1)
    conf.define("HAVE_GETADDRINFO", 1)
    conf.define("HAVE_STRUCT_TM_TM_ZONE", 1)
    conf.define("HAVE_TM_GMTOFF", 1)
    conf.define("HAVE_TIMEZONE", 1)
    conf.define("HAVE_TIMGM", 1)
    conf.define("HAVE_STRFTIME_Z_FORMAT", 1)
    conf.define("HAVE_FILENO", 1)
    conf.define("HAVE_STRUCT_SOCKADDR_SA_LEN", 1)
    conf.define("VERSION", conf.env.PURPLE_VERSION)
    conf.define("DISPLAY_VERSION", conf.env.PURPLE_VERSION)
    conf.define("DATADIR", ".")
    conf.define("SYSCONFDIR", ".")
    conf.define("PACKAGE_NAME", "libpurple")
    conf.define("HAVE_SSL", 1)
    conf.define("HAVE_ICONV", 1)
    conf.define("SIZEOF_TIME_T", 4, quote=False)
    conf.define("HAVE_CONFIG_H", 1, quote=False)
    conf.define("HAVE_GNUTLS_PRIORITY_FUNCS", 1)
    conf.define("_GNU_SOURCE", 1, quote=False)

    conf.define("SSL_CERTIFICATES_DIR",
                join(conf.env.APP_PATH, "share", "ca-certs"))
    conf.define("LIBDIR", conf.env.PLUGIN_PATH)

    conf.define("ENABLE_NLS", 1, quote=False)
    conf.define("PACKAGE", "libpurple")
    conf.define("LOCALEDIR", join(conf.env.APP_PATH, "share", "locale"))

    conf.define("STATIC_PROTO_INIT",
                "void static_proto_init() {}",
                quote=False)
    conf.write_config_header('libpurple_config/config.h')

    conf.load('protocols', tooldir=conf.env.TOOLDIR)
예제 #13
0
파일: python.py 프로젝트: blablack/ams-lv2
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!')
예제 #14
0
def check_protobuf(conf):
    # We'll need the library too
    conf.check_cfg(package="protobuf",
                   uselib_store="PROTOBUF",
                   args=['--cflags', '--libs'])
예제 #15
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')
예제 #16
0
파일: python.py 프로젝트: JanDeng25/ndn
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",
        )
예제 #17
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!'
    )
예제 #18
0
def configure(conf):
    conf.load('compiler_c intltool')

    path, version = get_pkg_path_and_version("pidgin")
    conf.env.PIDGIN_PATH = path
    conf.env.PURPLE_PATH = join(path, "libpurple")
    conf.env.PURPLE_VERSION = version

    if conf.env.PURPLE_SSL:
        # Order matters: It seems like ssl-gnutls has to be loaded before
        # core-ssl to be found (see ssl.c:probe_ssl_plugins)
        conf.env.PURPLE_PLUGINS += ["ssl-" + conf.env.PURPLE_SSL, "ssl"]

        conf.env.append_value("LIB_PURPLE_BUILD", ["gnutls"])

    plugins = conf.env.PURPLE_PLUGINS

    conf.check_cfg(atleast_pkgconfig_version='0.1')
    conf.check_cfg(package='libxml-2.0', uselib_store='XML',
                   args=['--cflags', '--libs'])

    conf.env.append_value("DEFINES_PURPLE_BUILD", ["HAVE_CONFIG_H"])
    conf.env.append_value("INCLUDES_PURPLE_BUILD", ["libpurple_config",
                                                    conf.env.PURPLE_PATH])
    conf.env.append_value("LIB_PURPLE_BUILD", ["resolv"])

    # We are going to build a shared library
    conf.env.append_value("CFLAGS_PURPLE_BUILD", ["-fPIC"])

    headers = ["arpa/nameser_compat", "fcntl", "sys/time",
               "unistd", "locale", "libintl", "signal", "stdint", "regex"]

    for i in headers:
        conf.check_cc(header_name=i + ".h", mandatory=False,
                      auto_add_header_name=True)

    conf.define("PURPLE_PLUGINS", 1)
    conf.define("HAVE_GETIFADDRS", 1)
    conf.define("HAVE_INET_NTOP", 1)
    conf.define("HAVE_INET_ATON", 1)
    conf.define("HAVE_GETADDRINFO", 1)
    conf.define("HAVE_STRUCT_TM_TM_ZONE", 1)
    conf.define("HAVE_TM_GMTOFF", 1)
    conf.define("HAVE_TIMEZONE", 1)
    conf.define("HAVE_TIMGM", 1)
    conf.define("HAVE_STRFTIME_Z_FORMAT", 1)
    conf.define("HAVE_FILENO", 1)
    conf.define("HAVE_STRUCT_SOCKADDR_SA_LEN", 1)
    conf.define("VERSION", conf.env.PURPLE_VERSION)
    conf.define("DISPLAY_VERSION", conf.env.PURPLE_VERSION)
    conf.define("DATADIR", ".")
    conf.define("SYSCONFDIR", ".")
    conf.define("PACKAGE_NAME", "libpurple")
    conf.define("HAVE_SSL", 1)
    conf.define("HAVE_ICONV", 1)
    conf.define("SIZEOF_TIME_T", 4, quote=False)
    conf.define("HAVE_CONFIG_H", 1, quote=False)
    conf.define("HAVE_GNUTLS_PRIORITY_FUNCS", 1)
    conf.define("_GNU_SOURCE", 1, quote=False)

    conf.define("SSL_CERTIFICATES_DIR",
            join(conf.env.APP_PATH, "share", "ca-certs")
    )
    conf.define("LIBDIR", conf.env.PLUGIN_PATH)

    conf.define("ENABLE_NLS", 1, quote=False)
    conf.define("PACKAGE", "libpurple")
    conf.define("LOCALEDIR",
                join(conf.env.APP_PATH, "share", "locale")
    )

    conf.define("STATIC_PROTO_INIT", "void static_proto_init() {}", quote=False)
    conf.write_config_header('libpurple_config/config.h')

    conf.load('protocols', tooldir=conf.env.TOOLDIR)
예제 #19
0
def check_protobuf(conf):
    # We'll need the library too
    conf.check_cfg(package="protobuf", uselib_store="PROTOBUF",
                   args=['--cflags', '--libs'])
예제 #20
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!'
    )
예제 #21
0
파일: python.py 프로젝트: rpmcpp/Audacity
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')
예제 #22
0
파일: python.py 프로젝트: maksqwe/jack2
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!",
    )
예제 #23
0
파일: python.py 프로젝트: markreyn/ndnSIMx
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!')
예제 #24
0
파일: python.py 프로젝트: alvyC/AutoNdn-Cip
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)
예제 #25
0
def check_magnum(conf, *k, **kw):
    def get_directory(filename, dirs, full=False):
        res = conf.find_file(filename, dirs)
        if not full:
            return res[:-len(filename) - 1]
        return res[:res.rfind('/')]

    def find_in_string(data, text):
        return data.find(text)

    # Check compiler version (for gcc); I am being a bit more strong (Magnum could be built with 4.7 but needs adjustment)
    if conf.env.CXX_NAME in [
            "gcc", "g++"
    ] and int(conf.env['CC_VERSION'][0] + conf.env['CC_VERSION'][1]) < 48:
        conf.fatal('Magnum cannot be setup with GCC < 4.8!')

    includes_check = [
        '/usr/local/include', '/usr/include', '/opt/local/include',
        '/sw/include'
    ]
    libs_check = [
        '/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib',
        '/usr/lib/x86_64-linux-gnu/', '/usr/lib64'
    ]
    bins_check = [
        '/usr/bin', '/usr/local/bin', '/opt/local/bin', '/sw/bin', '/bin'
    ]

    # Magnum depends on several libraries and we cannot make the assumption that
    # someone installed all of them in the same directory!
    # to-do: a better? solution would be to create different scripts for each dependency
    if conf.options.magnum_install_dir:
        includes_check = [conf.options.magnum_install_dir + '/include'
                          ] + includes_check
        libs_check = [conf.options.magnum_install_dir + '/lib'] + libs_check
        bins_check = [conf.options.magnum_install_dir + '/bin'] + bins_check

    required = kw.get('required', False)
    requested_components = kw.get('components', None)
    if requested_components == None:
        requested_components = []
    else:
        requested_components = requested_components.split()

    corrade_var = kw.get('corrade', 'Corrade')

    # Magnum requires Corrade
    if not conf.env['INCLUDES_%s' % corrade_var]:
        conf.fatal('Magnum requires Corrade! Cannot proceed!')
    if not conf.env['INCLUDES_%s_Utility' % corrade_var]:
        conf.fatal('Magnum requires Corrade Utility library! Cannot proceed!')
    if not conf.env['INCLUDES_%s_PluginManager' % corrade_var]:
        conf.fatal(
            'Magnum requires Corrade PluginManager library! Cannot proceed!')

    magnum_includes = []
    magnum_libpaths = []
    magnum_libs = []
    magnum_bins = []

    magnum_var = kw.get('uselib_store', 'Magnum')
    # to-do: enforce C++11/14

    magnum_possible_configs = [
        "BUILD_DEPRECATED", "BUILD_STATIC", "BUILD_MULTITHREADED", "TARGET_GL",
        "TARGET_GLES", "TARGET_GLES2", "TARGET_GLES3", "TARGET_DESKTOP_GLES",
        "TARGET_WEBGL", "TARGET_HEADLESS"
    ]
    magnum_config = []

    magnum_components, magnum_component_type, magnum_dependencies = get_magnum_components(
    )

    magnum_component_includes = {}
    magnum_component_libpaths = {}
    magnum_component_libs = {}
    magnum_component_bins = {}

    try:
        # to-do: support both debug and release builds
        conf.start_msg('Checking for Magnum includes')
        magnum_include_dir = get_directory('Magnum/Magnum.h', includes_check)
        magnum_includes = magnum_includes + [
            magnum_include_dir, magnum_include_dir + '/MagnumExternal/OpenGL'
        ]
        conf.end_msg(magnum_include_dir)

        conf.start_msg('Checking for Magnum lib')
        magnum_lib_path = get_directory('libMagnum.so', libs_check)
        magnum_libpaths = magnum_libpaths + [magnum_lib_path]
        magnum_libs = magnum_libs + ['Magnum']
        conf.end_msg(['Magnum'])

        conf.start_msg('Getting Magnum configuration')
        config_file = conf.find_file('Magnum/configure.h', includes_check)
        with open(config_file) as f:
            config_content = f.read()
        for config in magnum_possible_configs:
            index = find_in_string(config_content, '#define MAGNUM_' + config)
            if index > -1:
                magnum_config.append(config)
        conf.end_msg(magnum_config)

        if 'TARGET_GL' in magnum_config:
            # to-do: make it work for other platforms; now only for desktop and only for GL
            conf.start_msg('Magnum: Checking for OpenGL includes')
            opengl_include_dir = get_directory('GL/gl.h', includes_check)
            magnum_includes = magnum_includes + [opengl_include_dir]
            conf.end_msg(opengl_include_dir)

            conf.start_msg('Magnum: Checking for OpenGL lib')
            opengl_lib_dir = get_directory('libGL.so', libs_check)
            magnum_libpaths = magnum_libpaths + [opengl_lib_dir]
            magnum_libs = magnum_libs + ['GL']
            conf.end_msg(['GL'])

            conf.start_msg('Magnum: Checking for MagnumGL lib')
            gl_lib_dir = get_directory('libMagnumGL.so', libs_check)
            magnum_libpaths = magnum_libpaths + [gl_lib_dir]
            magnum_libs = magnum_libs + ['MagnumGL']
            conf.end_msg(['MagnumGL'])

        conf.start_msg('Checking for Magnum components')
        # only check for components that can exist
        requested_components = list(
            set(requested_components).intersection(magnum_components))
        # add dependencies
        for lib in requested_components:
            requested_components = requested_components + magnum_dependencies[
                lib]
        # remove duplicates
        requested_components = list(set(requested_components))

        for component in requested_components:
            magnum_component_includes[component] = []
            magnum_component_libpaths[component] = []
            magnum_component_libs[component] = []
            magnum_component_bins[component] = []

            # get component type
            component_type = magnum_component_type[component]
            if component_type == 'lib':
                pat_app = re.compile('.+Application')
                pat_context = re.compile('.+Context')

                component_file = component
                if component == 'MeshTools':
                    component_file = 'CompressIndices'
                if component == 'Primitives':
                    component_file = 'Cube'
                if component == 'TextureTools':
                    component_file = 'Atlas'

                lib_type = 'so'
                include_prefix = component
                # Applications
                if re.match(pat_app, component):
                    # to-do: all of them are static?
                    lib_type = 'a'
                    include_prefix = 'Platform'

                include_dir = get_directory(
                    'Magnum/' + include_prefix + '/' + component_file + '.h',
                    includes_check)
                lib = 'Magnum' + component
                lib_dir = get_directory('lib' + lib + '.' + lib_type,
                                        libs_check)

                magnum_component_includes[
                    component] = magnum_component_includes[component] + [
                        include_dir
                    ]
                magnum_component_libpaths[
                    component] = magnum_component_libpaths[component] + [
                        lib_dir
                    ]
                magnum_component_libs[component].append(lib)

                # Applications
                if re.match(pat_app, component):
                    if component == 'GlfwApplication':
                        # GlfwApplication requires GLFW3
                        # conf.start_msg('Magnum: Checking for GLFW3 includes')
                        glfw_inc = get_directory('GLFW/glfw3.h',
                                                 includes_check)

                        magnum_component_includes[
                            component] = magnum_component_includes[
                                component] + [glfw_inc]

                        # conf.start_msg('Magnum: Checking for GLFW3 lib')
                        libs_glfw = ['glfw', 'glfw3']
                        glfw_found = False
                        for lib_glfw in libs_glfw:
                            try:
                                lib_dir = get_directory(
                                    'lib' + lib_glfw + '.so', libs_check)
                                glfw_found = True

                                magnum_component_libpaths[
                                    component] = magnum_component_libpaths[
                                        component] + [lib_dir]
                                magnum_component_libs[component].append(
                                    lib_glfw)
                                break
                            except:
                                glfw_found = False

                        if not glfw_found:
                            conf.fatal('Not found')
                    elif component == 'GlutApplication':
                        # GlutApplication requires GLUT
                        # conf.start_msg('Magnum: Checking for GLUT includes')
                        glut_inc = get_directory('GL/freeglut.h',
                                                 includes_check)

                        magnum_component_includes[
                            component] = magnum_component_includes[
                                component] + [glut_inc]

                        # conf.start_msg('Magnum: Checking for GLFW3 lib')
                        libs_glut = ['glut', 'glut32']
                        glut_found = False
                        for lib_glut in libs_glut:
                            try:
                                lib_dir = get_directory(
                                    'lib' + lib_glut + '.so', libs_check)
                                glut_found = True

                                magnum_component_libpaths[
                                    component] = magnum_component_libpaths[
                                        component] + [lib_dir]
                                magnum_component_libs[component].append(
                                    lib_glut)
                                break
                            except:
                                glut_found = False

                        if not glut_found:
                            conf.fatal('Not found')
                    elif component == 'Sdl2Application':
                        # Sdl2Application requires SDL2
                        conf.check_cfg(path='sdl2-config',
                                       args='--cflags --libs',
                                       package='',
                                       uselib_store='MAGNUM_SDL')

                        magnum_component_includes[
                            component] = magnum_component_includes[
                                component] + conf.env['INCLUDES_MAGNUM_SDL']
                        magnum_component_libpaths[
                            component] = magnum_component_libpaths[
                                component] + conf.env['LIBPATH_MAGNUM_SDL']
                        magnum_component_libs[
                            component] = magnum_component_libs[
                                component] + conf.env['LIB_MAGNUM_SDL']
                        # to-do: maybe copy flags?
                    elif component not in [
                            'WindowlessCglApplication',
                            'WindowlessWglApplication'
                    ]:
                        # to-do: support all other applications
                        msg = 'Component ' + component + ' is not yet supported by WAF'
                        Logs.pprint('RED', msg)
                        conf.fatal(msg)

                if re.match(pat_context, component) and component not in [
                        'CglContext', 'WglContext'
                ]:
                    # to-do: support all other contexts
                    msg = 'Component ' + component + ' is not yet supported by WAF'
                    Logs.pprint('RED', msg)
                    conf.fatal(msg)

                # Audio lib required OpenAL
                if component == 'Audio':
                    # conf.start_msg('Magnum: Checking for OpenAL includes')
                    includes_audio = ['AL', 'OpenAL']
                    openal_found = False
                    for inc in includes_audio:
                        try:
                            # we need the full include dir
                            incl_audio = get_directory(inc + '/al.h',
                                                       includes_check, True)
                            openal_found = True

                            magnum_component_includes[
                                component] = magnum_component_includes[
                                    component] + [incl_audio]
                            break
                        except:
                            openal_found = False

                    if not openal_found:
                        conf.fatal('Not found')

                    # conf.start_msg('Magnum: Checking for OpenAL lib')
                    libs_audio = ['OpenAL', 'al', 'openal', 'OpenAL32']
                    openal_found = False
                    for lib_audio in libs_audio:
                        try:
                            lib_dir = get_directory('lib' + lib_audio + '.so',
                                                    libs_check)
                            openal_found = True

                            magnum_component_libpaths[
                                component] = magnum_component_libpaths[
                                    component] + [lib_dir]
                            magnum_component_libs[component].append(lib_audio)
                            break
                        except:
                            openal_found = False

                    if not openal_found:
                        conf.fatal('Not found')
            elif component_type == 'plugin':
                pat_audio = re.compile('.+AudioImporter$')
                pat_importer = re.compile('.+Importer$')
                pat_font = re.compile('.+Font$')
                pat_img_conv = re.compile('.+ImageConverter$')
                pat_font_conv = re.compile('.+FontConverter$')

                lib_path_suffix = ''
                component_file = component

                if re.match(pat_audio, component):
                    lib_path_suffix = 'audioimporters'
                    component_file = component.replace("AudioImporter",
                                                       "Importer")
                elif re.match(pat_importer, component):
                    lib_path_suffix = 'importers'
                elif re.match(pat_font, component):
                    lib_path_suffix = 'fonts'
                elif re.match(pat_img_conv, component):
                    lib_path_suffix = 'imageconverters'
                elif re.match(pat_font_conv, component):
                    lib_path_suffix = 'fontconverters'

                if lib_path_suffix != '':
                    lib_path_suffix = lib_path_suffix + '/'

                include_dir = get_directory(
                    'MagnumPlugins/' + component + '/' + component_file + '.h',
                    includes_check)
                lib = component
                # we need the full lib_dir in order to be able to link to the plugins
                # or not? because they are loaded dynamically
                # we need to set the libpath for the static plugins only
                lib_dir = get_directory(
                    'magnum/' + lib_path_suffix + lib + '.so', libs_check,
                    True)

                magnum_component_includes[
                    component] = magnum_component_includes[component] + [
                        include_dir
                    ]
                # magnum_component_libpaths[component] = magnum_component_libpaths[component] + [lib_dir]
                # magnum_component_libs[component].append(lib)
            elif component_type == 'bin':
                bin_name = 'magnum-' + component
                executable = conf.find_file(bin_name, bins_check)

                magnum_component_bins[component] = magnum_component_bins[
                    component] + [executable]

        conf.end_msg(requested_components)

        # set environmental variables
        conf.env['INCLUDES_%s' % magnum_var] = magnum_includes
        conf.env['LIBPATH_%s' % magnum_var] = magnum_libpaths
        conf.env['LIB_%s' % magnum_var] = magnum_libs
        conf.env['EXEC_%s' % magnum_var] = magnum_bins

        # set main Magnum component
        conf.env['INCLUDES_%s_Magnum' % magnum_var] = magnum_includes
        conf.env['LIBPATH_%s_Magnum' % magnum_var] = magnum_libpaths
        conf.env['LIB_%s_Magnum' % magnum_var] = magnum_libs
        conf.env['EXEC_%s_Magnum' % magnum_var] = magnum_bins

        # Plugin directories
        magnum_plugins_dir = magnum_lib_path + '/magnum'
        magnum_plugins_font_dir = magnum_plugins_dir + '/fonts'
        magnum_plugins_fontconverter_dir = magnum_plugins_dir + '/fontconverters'
        magnum_plugins_imageconverter_dir = magnum_plugins_dir + '/imageconverters'
        magnum_plugins_importer_dir = magnum_plugins_dir + '/importers'
        magnum_plugins_audioimporter_dir = magnum_plugins_dir + '/audioimporters'

        # conf.env['%s_PLUGINS_DIR' % magnum_var] = magnum_plugins_dir
        # conf.env['%s_PLUGINS_FONT_DIR' % magnum_var] = magnum_plugins_font_dir
        # conf.env['%s_PLUGINS_FONTCONVERTER_DIR' % magnum_var] = magnum_plugins_fontconverter_dir
        # conf.env['%s_PLUGINS_IMAGECONVERTER_DIR' % magnum_var] = magnum_plugins_imageconverter_dir
        # conf.env['%s_PLUGINS_IMPORTER_DIR' % magnum_var] = magnum_plugins_importer_dir
        # conf.env['%s_PLUGINS_AUDIOIMPORTER_DIR' % magnum_var] = magnum_plugins_audioimporter_dir

        # set C++ defines
        conf.env['DEFINES_%s' % magnum_var] = []
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_DIR="%s"' % (magnum_var.upper(), magnum_plugins_dir))
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_FONT_DIR="%s"' %
            (magnum_var.upper(), magnum_plugins_font_dir))
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_FONTCONVERTER_DIR="%s"' %
            (magnum_var.upper(), magnum_plugins_fontconverter_dir))
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_IMAGECONVERTER_DIR="%s"' %
            (magnum_var.upper(), magnum_plugins_imageconverter_dir))
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_IMPORTER_DIR="%s"' %
            (magnum_var.upper(), magnum_plugins_importer_dir))
        conf.env['DEFINES_%s' % magnum_var].append(
            '%s_PLUGINS_AUDIOIMPORTER_DIR="%s"' %
            (magnum_var.upper(), magnum_plugins_audioimporter_dir))

        # copy C++ defines to Magnum::Magnum component; we want them to be available on all Magnum builds
        conf.env['DEFINES_%s_Magnum' % magnum_var] = copy.deepcopy(
            conf.env['DEFINES_%s' % magnum_var])

        # set component libs
        for component in requested_components:
            conf.env['INCLUDES_%s_%s' %
                     (magnum_var,
                      component)] = magnum_component_includes[component]
            conf.env['LIBPATH_%s_%s' %
                     (magnum_var,
                      component)] = magnum_component_libpaths[component]
            conf.env['LIB_%s_%s' %
                     (magnum_var,
                      component)] = magnum_component_libs[component]
            conf.env['EXEC_%s_%s' %
                     (magnum_var,
                      component)] = magnum_component_bins[component]
    except:
        if required:
            conf.fatal('Not found')
        conf.end_msg('Not found', 'RED')
        return
    return 1
예제 #26
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 = [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!",
    )
예제 #27
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')
예제 #28
0
def configure(conf):
    conf.load('compiler_c')

    path, version = get_path_and_version()
    conf.env.PURPLE_PATH = path
    conf.env.PURPLE_VERSION = version

    if conf.env.PURPLE_SSL:
        # Order matters: It seems like ssl-gnutls has to be loaded before
        # core-ssl to be found (see ssl.c:probe_ssl_plugins)
        conf.env.PURPLE_PLUGINS += ["ssl-" + conf.env.PURPLE_SSL, "ssl"]

        # TODO: conf.define("SSL_CERTIFICATE_DIR")
        conf.env.append_value("LIB_PURPLE_BUILD", ["gnutls"])

    plugins = conf.env.PURPLE_PLUGINS
    protocols = conf.env.PURPLE_PROTOCOLS

    if "jabber" in protocols:
        conf.env.PURPLE_SASL = True
        conf.load('sasl', tooldir='build_lib')
    else:
        conf.env.PURPLE_SASL = False

    conf.check_cfg(atleast_pkgconfig_version='0.1')
    conf.check_cfg(package='libxml-2.0', uselib_store='XML',
                   args=['--cflags', '--libs'])

    conf.env.append_value("DEFINES_PURPLE_BUILD", ["HAVE_CONFIG_H"])
    conf.env.append_value("INCLUDES_PURPLE_BUILD", ["libpurple_config", path])
    conf.env.append_value("LIB_PURPLE_BUILD", ["resolv"])

    # We are going to build a shared library
    conf.env.append_value("CFLAGS_PURPLE_BUILD", ["-fPIC"])

    headers = ["arpa/nameser_compat", "fcntl", "sys/time",
               "unistd", "locale", "signal", "stdint", "regex"]

    for i in headers:
        conf.check_cc(header_name=i + ".h", mandatory=False,
                      auto_add_header_name=True)

    conf.define("PURPLE_STATIC_PRPL", 1)
    conf.define("PURPLE_PLUGINS", 1)
    conf.define("HAVE_GETIFADDRS", 1)
    conf.define("HAVE_INET_NTOP", 1)
    conf.define("HAVE_INET_ATON", 1)
    conf.define("HAVE_GETADDRINFO", 1)
    conf.define("HAVE_STRUCT_TM_TM_ZONE", 1)
    conf.define("HAVE_TM_GMTOFF", 1)
    conf.define("HAVE_TIMEZONE", 1)
    conf.define("HAVE_TIMGM", 1)
    conf.define("HAVE_STRFTIME_Z_FORMAT", 1)
    conf.define("HAVE_FILENO", 1)
    conf.define("HAVE_STRUCT_SOCKADDR_SA_LEN", 1)
    conf.define("VERSION", conf.env.PURPLE_VERSION)
    conf.define("DISPLAY_VERSION", conf.env.PURPLE_VERSION)
    conf.define("DATADIR", ".")
    conf.define("SYSCONFDIR", ".")
    conf.define("PACKAGE_NAME", "libpurple")
    conf.define("HAVE_SSL", 1)
    conf.define("HAVE_ICONV", 1)
    conf.define("LIBDIR", ".")
    conf.define("SIZEOF_TIME_T", 4, quote=False)
    conf.define("HAVE_CONFIG_H", 1, quote=False)
    conf.define("HAVE_CYRUS_SASL", 1, quote=False)
    conf.define("HAVE_GNUTLS_PRIORITY_FUNCS", 1)
    conf.define("_GNU_SOURCE", 1, quote=False)

    proto_extern = "\\\n".join(
                        "extern gboolean purple_init_%s_plugin();" %
                            name.replace('-', '_')
                        for name in chain(plugins, protocols)
                        )

    proto_func = "\\\n".join(
                        "   purple_init_%s_plugin();" % name.replace('-', '_')
                        for name in chain(plugins, protocols)
                        )

    proto_init = """%s\\
void static_proto_init()\\
{\\
%s\\
}""" % (proto_extern, proto_func)

    conf.define("STATIC_PROTO_INIT", proto_init, quote=False)

    conf.write_config_header('libpurple_config/config.h')
예제 #29
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')
예제 #30
0
파일: protobuf.py 프로젝트: zhenkai/sync
def configure(conf):
    """
    """
    conf.check_cfg(package='protobuf', args=['--cflags', '--libs'], uselib_store='PROTOBUF', mandatory=True)

    conf.find_program ('protoc', var='PROTOC', path_list = conf.env['PATH'], mandatory = True)