def pkg_check_modules(conf,uselib_name,expression,mandatory=True): pkg_config=conf.env['PKG_CONFIG'] if not pkg_config: if mandatory: conf.fatal("pkg-config is not available") else: return False argv=[pkg_config,'--cflags','--libs',expression] cmd=subprocess.Popen(argv,stdout=subprocess.PIPE) out,dummy=cmd.communicate() retval=cmd.wait() msg_checking=("pkg-config flags for %s"%(uselib_name,)) if Options.options.verbose: if retval==0: conf.check_message_custom(msg_checking,('(%s)'%expression),out) else: conf.check_message(msg_checking,('(%s)'%expression),False) else: conf.check_message(msg_checking,'',(retval==0),'') conf.log.write('%r: %r (exit code %i)\n'%(argv,out,retval)) if retval==0: config_c.parse_flags(out,uselib_name,conf.env) conf.env[uselib_name]=True return True else: conf.env[uselib_name]=False if mandatory: raise Configure.ConfigurationError('pkg-config check failed') else: return False
def detect_ode(conf): env = conf.env opt = Options.options ret = conf.find_program('ode-config') conf.check_message_1('Checking for ODE (optional)') if not ret: conf.check_message_2('not found', 'YELLOW') return 0 conf.check_message_2('ok') res = commands.getoutput('ode-config --cflags --libs') config_c.parse_flags(res, 'ODE', env) return 1
def detect_ode(conf): env = conf.env opt = Options.options ret = conf.find_program('ode-config') conf.check_message_1('Checking for ODE') if not ret: conf.check_message_2('not found', 'RED') return 0 conf.check_message_2('ok') res = commands.getoutput('ode-config --cflags --libs') config_c.parse_flags(res, 'ODE', env) return 1
def check_python_headers(conf, mandatory=True): """Check for headers and libraries necessary to extend or embed python. On success the environment variables xxx_PYEXT and xxx_PYEMBED are added for uselib PYEXT: for compiling python extensions PYEMBED: for embedding a python interpreter""" if not conf.env['CC_NAME'] and not conf.env['CXX_NAME']: conf.fatal('load a compiler first (gcc, g++, ..)') if not conf.env['PYTHON_VERSION']: conf.check_python_version() env = conf.env python = env['PYTHON'] if not python: conf.fatal('could not find the python executable') ## On Mac OSX we need to use mac bundles for python plugins if Options.platform == 'darwin': conf.check_tool('osx') try: # Get some python configuration variables using distutils v = 'prefix SO SYSLIBS LDFLAGS SHLIBS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDVERSION'.split() (python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS, python_SHLIBS, python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED, python_MACOSX_DEPLOYMENT_TARGET, python_LDVERSION) = \ _get_python_variables(python, ["get_config_var('%s') or ''" % x for x in v], ['from distutils.sysconfig import get_config_var']) except RuntimeError: conf.fatal("Python development headers not found (-v for details).") conf.log.write("""Configuration returned from %r: python_prefix = %r python_SO = %r python_SYSLIBS = %r python_LDFLAGS = %r python_SHLIBS = %r python_LIBDIR = %r python_LIBPL = %r INCLUDEPY = %r Py_ENABLE_SHARED = %r MACOSX_DEPLOYMENT_TARGET = %r LDVERSION = %r """ % (python, python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS, python_SHLIBS, python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED, python_MACOSX_DEPLOYMENT_TARGET, python_LDVERSION)) # Allow some python overrides from env vars for cross-compiling os_env = dict(os.environ) override_python_LDFLAGS = os_env.get('python_LDFLAGS', None) if override_python_LDFLAGS is not None: conf.log.write("python_LDFLAGS override from environment = %r\n" % (override_python_LDFLAGS)) python_LDFLAGS = override_python_LDFLAGS override_python_LIBDIR = os_env.get('python_LIBDIR', None) if override_python_LIBDIR is not None: conf.log.write("python_LIBDIR override from environment = %r\n" % (override_python_LIBDIR)) python_LIBDIR = override_python_LIBDIR if python_MACOSX_DEPLOYMENT_TARGET: conf.env['MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET conf.environ['MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET env['pyext_PATTERN'] = '%s'+python_SO # Check for python libraries for embedding if python_SYSLIBS is not None: for lib in python_SYSLIBS.split(): if lib.startswith('-l'): lib = lib[2:] # strip '-l' env.append_value('LIB_PYEMBED', lib) if python_SHLIBS is not None: for lib in python_SHLIBS.split(): if lib.startswith('-l'): env.append_value('LIB_PYEMBED', lib[2:]) # strip '-l' else: env.append_value('LINKFLAGS_PYEMBED', lib) if Options.platform != 'darwin' and python_LDFLAGS: parse_flags(python_LDFLAGS, 'PYEMBED', env) result = False if not python_LDVERSION: python_LDVERSION = env['PYTHON_VERSION'] name = 'python' + python_LDVERSION if python_LIBDIR is not None: path = [python_LIBDIR] conf.log.write("\n\n# Trying LIBDIR: %r\n" % path) result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if not result and python_LIBPL is not None: conf.log.write("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n") path = [python_LIBPL] result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if not result: conf.log.write("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n") path = [os.path.join(python_prefix, "libs")] name = 'python' + python_LDVERSION.replace('.', '') result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if result: env['LIBPATH_PYEMBED'] = path env.append_value('LIB_PYEMBED', name) else: conf.log.write("\n\n### LIB NOT FOUND\n") # under certain conditions, python extensions must link to # python libraries, not just python embedding programs. if (sys.platform == 'win32' or sys.platform.startswith('os2') or sys.platform == 'darwin' or Py_ENABLE_SHARED): env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED'] env['LIB_PYEXT'] = env['LIB_PYEMBED'] # We check that pythonX.Y-config exists, and if it exists we # use it to get only the includes, else fall back to distutils. python_config = conf.find_program( 'python%s-config' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])), var='PYTHON_CONFIG') if not python_config: python_config = conf.find_program( 'python-config-%s' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])), var='PYTHON_CONFIG') includes = [] if python_config: for incstr in Utils.cmd_output("%s --includes" % (python_config,)).strip().split(): # strip the -I or /I if (incstr.startswith('-I') or incstr.startswith('/I')): incstr = incstr[2:] # append include path, unless already given if incstr not in includes: includes.append(incstr) conf.log.write("Include path for Python extensions " "(found via python-config --includes): %r\n" % (includes,)) env['CPPPATH_PYEXT'] = includes env['CPPPATH_PYEMBED'] = includes else: conf.log.write("Include path for Python extensions " "(found via distutils module): %r\n" % (INCLUDEPY,)) env['CPPPATH_PYEXT'] = [INCLUDEPY] env['CPPPATH_PYEMBED'] = [INCLUDEPY] # Code using the Python API needs to be compiled with -fno-strict-aliasing if env['CC_NAME'] == 'gcc': env.append_value('CCFLAGS_PYEMBED', '-fno-strict-aliasing') env.append_value('CCFLAGS_PYEXT', '-fno-strict-aliasing') if env['CXX_NAME'] == 'gcc': env.append_value('CXXFLAGS_PYEMBED', '-fno-strict-aliasing') env.append_value('CXXFLAGS_PYEXT', '-fno-strict-aliasing') # See if it compiles conf.check(define_name='HAVE_PYTHON_H', uselib='PYEMBED', fragment=FRAG_2, errmsg='Could not find the python development headers', mandatory=mandatory)
def check_python_headers(conf, mandatory=True): """Check for headers and libraries necessary to extend or embed python. On success the environment variables xxx_PYEXT and xxx_PYEMBED are added for uselib PYEXT: for compiling python extensions PYEMBED: for embedding a python interpreter""" if not conf.env['CC_NAME'] and not conf.env['CXX_NAME']: conf.fatal('load a compiler first (gcc, g++, ..)') if not conf.env['PYTHON_VERSION']: conf.check_python_version() env = conf.env python = env['PYTHON'] if not python: conf.fatal('could not find the python executable') ## On Mac OSX we need to use mac bundles for python plugins if Options.platform == 'darwin': conf.check_tool('osx') try: # Get some python configuration variables using distutils v = 'prefix SO SYSLIBS LDFLAGS SHLIBS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET'.split( ) (python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS, python_SHLIBS, python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED, python_MACOSX_DEPLOYMENT_TARGET) = \ _get_python_variables(python, ["get_config_var('%s') or ''" % x for x in v], ['from distutils.sysconfig import get_config_var']) except RuntimeError: conf.fatal("Python development headers not found (-v for details).") conf.log.write("""Configuration returned from %r: python_prefix = %r python_SO = %r python_SYSLIBS = %r python_LDFLAGS = %r python_SHLIBS = %r python_LIBDIR = %r python_LIBPL = %r INCLUDEPY = %r Py_ENABLE_SHARED = %r MACOSX_DEPLOYMENT_TARGET = %r """ % (python, python_prefix, python_SO, python_SYSLIBS, python_LDFLAGS, python_SHLIBS, python_LIBDIR, python_LIBPL, INCLUDEPY, Py_ENABLE_SHARED, python_MACOSX_DEPLOYMENT_TARGET)) # Allow some python overrides from env vars for cross-compiling os_env = dict(os.environ) override_python_LDFLAGS = os_env.get('python_LDFLAGS', None) if override_python_LDFLAGS is not None: conf.log.write("python_LDFLAGS override from environment = %r\n" % (override_python_LDFLAGS)) python_LDFLAGS = override_python_LDFLAGS override_python_LIBDIR = os_env.get('python_LIBDIR', None) if override_python_LIBDIR is not None: conf.log.write("python_LIBDIR override from environment = %r\n" % (override_python_LIBDIR)) python_LIBDIR = override_python_LIBDIR if python_MACOSX_DEPLOYMENT_TARGET: conf.env['MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET conf.environ[ 'MACOSX_DEPLOYMENT_TARGET'] = python_MACOSX_DEPLOYMENT_TARGET env['pyext_PATTERN'] = '%s' + python_SO # Check for python libraries for embedding if python_SYSLIBS is not None: for lib in python_SYSLIBS.split(): if lib.startswith('-l'): lib = lib[2:] # strip '-l' env.append_value('LIB_PYEMBED', lib) if python_SHLIBS is not None: for lib in python_SHLIBS.split(): if lib.startswith('-l'): env.append_value('LIB_PYEMBED', lib[2:]) # strip '-l' else: env.append_value('LINKFLAGS_PYEMBED', lib) if Options.platform != 'darwin' and python_LDFLAGS: parse_flags(python_LDFLAGS, 'PYEMBED', env) result = False name = 'python' + env['PYTHON_VERSION'] if python_LIBDIR is not None: path = [python_LIBDIR] conf.log.write("\n\n# Trying LIBDIR: %r\n" % path) result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if not result and python_LIBPL is not None: conf.log.write( "\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n" ) path = [python_LIBPL] result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if not result: conf.log.write( "\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n" ) path = [os.path.join(python_prefix, "libs")] name = 'python' + env['PYTHON_VERSION'].replace('.', '') result = conf.check(lib=name, uselib='PYEMBED', libpath=path) if result: env['LIBPATH_PYEMBED'] = path env.append_value('LIB_PYEMBED', name) else: conf.log.write("\n\n### LIB NOT FOUND\n") # under certain conditions, python extensions must link to # python libraries, not just python embedding programs. if (sys.platform == 'win32' or sys.platform.startswith('os2') or sys.platform == 'darwin' or Py_ENABLE_SHARED): env['LIBPATH_PYEXT'] = env['LIBPATH_PYEMBED'] env['LIB_PYEXT'] = env['LIB_PYEMBED'] # We check that pythonX.Y-config exists, and if it exists we # use it to get only the includes, else fall back to distutils. python_config = conf.find_program( 'python%s-config' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])), var='PYTHON_CONFIG') if not python_config: python_config = conf.find_program( 'python-config-%s' % ('.'.join(env['PYTHON_VERSION'].split('.')[:2])), var='PYTHON_CONFIG') includes = [] if python_config: for incstr in Utils.cmd_output("%s --includes" % (python_config, )).strip().split(): # strip the -I or /I if (incstr.startswith('-I') or incstr.startswith('/I')): incstr = incstr[2:] # append include path, unless already given if incstr not in includes: includes.append(incstr) conf.log.write("Include path for Python extensions " "(found via python-config --includes): %r\n" % (includes, )) env['CPPPATH_PYEXT'] = includes env['CPPPATH_PYEMBED'] = includes else: conf.log.write("Include path for Python extensions " "(found via distutils module): %r\n" % (INCLUDEPY, )) env['CPPPATH_PYEXT'] = [INCLUDEPY] env['CPPPATH_PYEMBED'] = [INCLUDEPY] # Code using the Python API needs to be compiled with -fno-strict-aliasing if env['CC_NAME'] == 'gcc': env.append_value('CCFLAGS_PYEMBED', '-fno-strict-aliasing') env.append_value('CCFLAGS_PYEXT', '-fno-strict-aliasing') if env['CXX_NAME'] == 'gcc': env.append_value('CXXFLAGS_PYEMBED', '-fno-strict-aliasing') env.append_value('CXXFLAGS_PYEXT', '-fno-strict-aliasing') # See if it compiles conf.check(define_name='HAVE_PYTHON_H', uselib='PYEMBED', fragment=FRAG_2, errmsg='Could not find the python development headers', mandatory=mandatory)