Пример #1
0
def check_python_version(conf, minver=None):
    assert minver is None or isinstance(minver, tuple)
    python = conf.env['PYTHON']
    assert python, ("python is %r !" % (python, ))
    cmd = [
        python, "-c", "import sys\nfor x in sys.version_info: print(str(x))"
    ]
    debug('python: Running python command %r' % cmd)
    proc = Utils.pproc.Popen(cmd, stdout=Utils.pproc.PIPE)
    lines = proc.communicate()[0].split()
    assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines),
                                                                lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3],
                   int(lines[4]))
    result = (minver is None) or (pyver_tuple >= minver)
    if result:
        pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
        conf.env['PYTHON_VERSION'] = pyver
        if 'PYTHONDIR' in conf.environ:
            pydir = conf.environ['PYTHONDIR']
        else:
            if sys.platform == 'win32':
                (
                    python_LIBDEST, pydir
                ) = _get_python_variables(python, [
                    "get_config_var('LIBDEST')",
                    "get_python_lib(standard_lib=0, prefix=%r)" %
                    conf.env['PREFIX']
                ], [
                    'from distutils.sysconfig import get_config_var, get_python_lib'
                ])
            else:
                python_LIBDEST = None
                (pydir, ) = _get_python_variables(python, [
                    "get_python_lib(standard_lib=0, prefix=%r)" %
                    conf.env['PREFIX']
                ], [
                    'from distutils.sysconfig import get_config_var, get_python_lib'
                ])
            if python_LIBDEST is None:
                if conf.env['LIBDIR']:
                    python_LIBDEST = os.path.join(conf.env['LIBDIR'],
                                                  "python" + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env['PREFIX'], "lib",
                                                  "python" + pyver)
        if hasattr(conf, 'define'):
            conf.define('PYTHONDIR', pydir)
        conf.env['PYTHONDIR'] = pydir
    pyver_full = '.'.join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.check_message_custom('Python version', '', pyver_full)
    else:
        minver_str = '.'.join(map(str, minver))
        conf.check_message('Python version',
                           ">= %s" % (minver_str, ),
                           result,
                           option=pyver_full)
    if not result:
        conf.fatal("Python too old.")
Пример #2
0
def check_python_module(conf, module_name):
    result = not Utils.pproc.Popen(
        [conf.env["PYTHON"], "-c", "import %s" % module_name], stderr=Utils.pproc.PIPE, stdout=Utils.pproc.PIPE
    ).wait()
    conf.check_message("Python module", module_name, result)
    if not result:
        conf.fatal("Could not find the python module %r" % module_name)
Пример #3
0
def check_perl_ext_devel(conf):
	"""
	Check for configuration needed to build perl extensions.

	Sets different xxx_PERLEXT variables in the environment.

	Also sets the ARCHDIR_PERL variable useful as installation path,
	which can be overridden by --with-perl-archdir
	"""
	if not conf.env.PERL:
		conf.fatal('perl detection is required first')

	def read_out(cmd):
		return Utils.to_list(Utils.cmd_output([conf.env.PERL, '-MConfig', '-e', cmd]))

	conf.env.LINKFLAGS_PERLEXT = read_out('print $Config{lddlflags}')
	conf.env.CPPPATH_PERLEXT   = read_out('print "$Config{archlib}/CORE"')
	conf.env.CCFLAGS_PERLEXT   = read_out('print "$Config{ccflags} $Config{cccdlflags}"')
	conf.env.XSUBPP            = read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
	conf.env.EXTUTILS_TYPEMAP  = read_out('print "$Config{privlib}/ExtUtils/typemap"')
	conf.env.perlext_PATTERN   = '%s.' + read_out('print $Config{dlext}')[0]

	if getattr(Options.options, 'perlarchdir', None):
		conf.env.ARCHDIR_PERL = Options.options.perlarchdir
	else:
		conf.env.ARCHDIR_PERL = read_out('print $Config{sitearch}')[0]
Пример #4
0
def find_config_dir(conf):
    '''find a directory to run tests in'''
    k = 0
    while k < 10000:
        dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
        try:
            shutil.rmtree(dir)
        except OSError:
            pass
        try:
            os.stat(dir)
        except:
            break
        k += 1

    try:
        os.makedirs(dir)
    except:
        conf.fatal('cannot create a configuration test folder %r' % dir)

    try:
        os.stat(dir)
    except:
        conf.fatal('cannot use the configuration test folder %r' % dir)
    return dir
Пример #5
0
def get_msvc_version(conf, compiler, version, target, vcvars):
    debug('msvc: get_msvc_version: %r %r %r', compiler, version, target)
    batfile = os.path.join(conf.blddir, 'waf-print-msvc.bat')
    f = open(batfile, 'w')
    f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
""" % (vcvars, target))
    f.close()
    sout = Utils.cmd_output(['cmd', '/E:on', '/V:on', '/C', batfile])
    lines = sout.splitlines()

    for x in ('Setting environment', 'Setting SDK environment',
              'Intel(R) C++ Compiler'):
        if lines[0].find(x) != -1:
            break
    else:
        debug('msvc: get_msvc_version: %r %r %r -> not found', compiler,
              version, target)
        conf.fatal(
            'msvc: Impossible to find a valid architecture for building (in get_msvc_version)'
        )

    for line in lines[1:]:
        if line.startswith('PATH='):
            path = line[5:]
            MSVC_PATH = path.split(';')
        elif line.startswith('INCLUDE='):
            MSVC_INCDIR = [i for i in line[8:].split(';') if i]
        elif line.startswith('LIB='):
            MSVC_LIBDIR = [i for i in line[4:].split(';') if i]

    # Check if the compiler is usable at all.
    # The detection may return 64-bit versions even on 32-bit systems, and these would fail to run.
    env = {}
    env.update(os.environ)
    env.update(PATH=path)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
    # delete CL if exists. because it could contain parameters wich can change cl's behaviour rather catastrophically.
    if env.has_key('CL'):
        del (env['CL'])

    try:
        p = pproc.Popen([cxx, '/help'],
                        env=env,
                        stdout=pproc.PIPE,
                        stderr=pproc.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception('return code: %r: %r' % (p.returncode, err))
    except Exception, e:
        debug('msvc: get_msvc_version: %r %r %r -> failure', compiler, version,
              target)
        debug(str(e))
        conf.fatal('msvc: cannot run the compiler (in get_msvc_version)')
Пример #6
0
def find_config_dir(conf):
    '''find a directory to run tests in'''
    k = 0
    while k < 10000:
        dir = os.path.join(conf.blddir, '.conf_check_%d' % k)
        try:
            shutil.rmtree(dir)
        except OSError:
            pass
        try:
            os.stat(dir)
        except:
            break
        k += 1

    try:
        os.makedirs(dir)
    except:
        conf.fatal('cannot create a configuration test folder %r' % dir)

    try:
        os.stat(dir)
    except:
        conf.fatal('cannot use the configuration test folder %r' % dir)
    return dir
Пример #7
0
def check_perl_ext_devel(conf):
    """
	Check for configuration needed to build perl extensions.

	Sets different xxx_PERLEXT variables in the environment.

	Also sets the ARCHDIR_PERL variable useful as installation path,
	which can be overridden by --with-perl-archdir
	"""
    if not conf.env.PERL:
        conf.fatal("perl detection is required first")

    def read_out(cmd):
        return Utils.to_list(Utils.cmd_output([conf.env.PERL, "-MConfig", "-e", cmd]))

    conf.env.LINKFLAGS_PERLEXT = read_out("print $Config{lddlflags}")
    conf.env.CPPPATH_PERLEXT = read_out('print "$Config{archlib}/CORE"')
    conf.env.CCFLAGS_PERLEXT = read_out('print "$Config{ccflags} $Config{cccdlflags}"')
    conf.env.XSUBPP = read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
    conf.env.EXTUTILS_TYPEMAP = read_out('print "$Config{privlib}/ExtUtils/typemap"')
    conf.env.perlext_PATTERN = "%s." + read_out("print $Config{dlext}")[0]

    if getattr(Options.options, "perlarchdir", None):
        conf.env.ARCHDIR_PERL = Options.options.perlarchdir
    else:
        conf.env.ARCHDIR_PERL = read_out("print $Config{sitearch}")[0]
Пример #8
0
def find_msvc(conf):
    if sys.platform != 'win32':
        conf.fatal(
            'MSVC module only works under native Win32 Python! cygwin is not supported yet'
        )
    v = conf.env
    compiler, version, path, includes, libdirs = detect_msvc(conf)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    has_msvc_manifest = (compiler == 'msvc' and float(version) >= 8) or (
        compiler == 'wsdk'
        and float(version) >= 6) or (compiler == 'intel'
                                     and float(version) >= 11)
    cxx = None
    if v.CXX: cxx = v.CXX
    elif 'CXX' in conf.environ: cxx = conf.environ['CXX']
    if not cxx:
        cxx = conf.find_program(compiler_name,
                                var='CXX',
                                path_list=path,
                                mandatory=True)
    cxx = conf.cmd_to_list(cxx)
    env = dict(conf.environ)
    env.update(PATH=';'.join(path))
    if not Utils.cmd_output([cxx, '/nologo', '/?'], silent=True, env=env):
        conf.fatal('the msvc compiler could not be identified')
    link = v.LINK_CXX
    if not link:
        link = conf.find_program(linker_name, path_list=path, mandatory=True)
    ar = v.AR
    if not ar:
        ar = conf.find_program(lib_name, path_list=path, mandatory=True)
    mt = v.MT
    if has_msvc_manifest:
        mt = conf.find_program('MT', path_list=path, mandatory=True)
    v.MSVC_MANIFEST = has_msvc_manifest
    v.PATH = path
    v.CPPPATH = includes
    v.LIBPATH = libdirs
    v.CC = v.CXX = cxx
    v.CC_NAME = v.CXX_NAME = 'msvc'
    v.LINK = v.LINK_CXX = link
    if not v.LINK_CC:
        v.LINK_CC = v.LINK_CXX
    v.AR = ar
    v.MT = mt
    v.MTFLAGS = v.ARFLAGS = ['/NOLOGO']
    conf.check_tool('winres')
    if not conf.env.WINRC:
        warn(
            'Resource compiler not found. Compiling resource file is disabled')
    try:
        v.prepend_value('CPPPATH', conf.environ['INCLUDE'])
    except KeyError:
        pass
    try:
        v.prepend_value('LIBPATH', conf.environ['LIB'])
    except KeyError:
        pass
Пример #9
0
def check_python_module(conf, module_name):
	"""
	Check if the selected python interpreter can import the given python module.
	"""
	result = not Utils.pproc.Popen([conf.env['PYTHON'], "-c", "import %s" % module_name],
			   stderr=Utils.pproc.PIPE, stdout=Utils.pproc.PIPE).wait()
	conf.check_message('Python module', module_name, result)
	if not result:
		conf.fatal('Could not find the python module %r' % module_name)
Пример #10
0
def check_python_module(conf, module_name):
	"""
	Check if the selected python interpreter can import the given python module.
	"""
	result = not Utils.pproc.Popen([conf.env['PYTHON'], "-c", "import %s" % module_name],
			   stderr=Utils.pproc.PIPE, stdout=Utils.pproc.PIPE).wait()
	conf.check_message('Python module', module_name, result)
	if not result:
		conf.fatal('Could not find the python module %r' % module_name)
Пример #11
0
def check_python_module(conf, module_name):
    result = not Utils.pproc.Popen(
        [conf.env['PYTHON'], "-c",
         "import %s" % module_name],
        stderr=Utils.pproc.PIPE,
        stdout=Utils.pproc.PIPE).wait()
    conf.check_message('Python module', module_name, result)
    if not result:
        conf.fatal('Could not find the python module %r' % module_name)
Пример #12
0
def check_python_module(conf,module_name):
	argv=[conf.env['PYTHON'],"-c","import %s"%module_name]
	proc=Utils.pproc.Popen(argv,stderr=Utils.pproc.PIPE)
	stderr=proc.stderr.read()
	retval=proc.wait()
	result=(retval==0)
	conf.check_message('Python module',module_name,result)
	if not result:
		conf.log.write("Process %r returned exit code %i:\n-- \n%s\n-- \n"%(argv,retval,stderr))
		conf.fatal("Python module not found.")
Пример #13
0
def get_msvc_version(conf, compiler, version, target, vcvars):
    debug("msvc: get_msvc_version: " + compiler + " " + version + " " + target + " ...")
    batfile = os.path.join(conf.blddir, "waf-print-msvc.bat")
    f = open(batfile, "w")
    f.write(
        """@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
"""
        % (vcvars, target)
    )
    f.close()
    sout = Utils.cmd_output(["cmd", "/E:on", "/V:on", "/C", batfile])
    lines = sout.splitlines()

    for x in ("Setting environment", "Setting SDK environment", "Intel(R) C++ Compiler"):
        if lines[0].find(x) != -1:
            break
    else:
        debug("msvc: get_msvc_version: %r %r %r -> not found" % (compiler, version, target))
        conf.fatal("msvc: Impossible to find a valid architecture for building (in get_msvc_version)")

    for line in lines[1:]:
        if line.startswith("PATH="):
            path = line[5:]
            MSVC_PATH = path.split(";")
        elif line.startswith("INCLUDE="):
            MSVC_INCDIR = [i for i in line[8:].split(";") if i]
        elif line.startswith("LIB="):
            MSVC_LIBDIR = [i for i in line[4:].split(";") if i]

            # Check if the compiler is usable at all.
            # The detection may return 64-bit versions even on 32-bit systems, and these would fail to run.
    env = {}
    env.update(os.environ)
    env.update(PATH=path)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
    # delete CL if exists. because it could contain parameters wich can change cl's behaviour rather catastrophically.
    if env.has_key("CL"):
        del (env["CL"])

    try:
        p = pproc.Popen([cxx, "/help"], env=env, stdout=pproc.PIPE, stderr=pproc.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception("return code: %r: %r" % (p.returncode, err))
    except Exception, e:
        debug("msvc: get_msvc_version: %r %r %r -> failure" % (compiler, version, target))
        debug(str(e))
        conf.fatal("msvc: cannot run the compiler (in get_msvc_version)")
Пример #14
0
def check_python_module(conf, module_name):
    argv = [conf.env['PYTHON'], "-c", "import %s" % module_name]
    proc = Utils.pproc.Popen(argv, stderr=Utils.pproc.PIPE)
    stderr = proc.stderr.read()
    retval = proc.wait()
    result = (retval == 0)
    conf.check_message('Python module', module_name, result)
    if not result:
        conf.log.write("Process %r returned exit code %i:\n-- \n%s\n-- \n" %
                       (argv, retval, stderr))
        conf.fatal("Python module not found.")
Пример #15
0
def check_ruby_ext_devel(conf):
	if not conf.env.RUBY:
		conf.fatal('ruby detection is required first')

	if not conf.env.CC_NAME and not conf.env.CXX_NAME:
		conf.fatal('load a c/c++ compiler first')

	version = tuple(map(int, conf.env.RUBY_VERSION.split(".")))

	def read_out(cmd):
		return Utils.to_list(Utils.cmd_output([conf.env.RUBY, '-rrbconfig', '-e', cmd]))

	def read_config(key):
		return read_out('puts Config::CONFIG[%r]' % key)

	ruby = conf.env['RUBY']
	archdir = read_config('archdir')
	cpppath = archdir
	if version >= (1, 9, 0):
		ruby_hdrdir = read_config('rubyhdrdir')
		cpppath += ruby_hdrdir
		cpppath += [os.path.join(ruby_hdrdir[0], read_config('arch')[0])]

	conf.check(header_name='ruby.h', includes=cpppath, mandatory=True, errmsg='could not find ruby header file')

	conf.env.LIBPATH_RUBYEXT = read_config('libdir')
	conf.env.LIBPATH_RUBYEXT += archdir
	conf.env.CPPPATH_RUBYEXT = cpppath
	conf.env.CCFLAGS_RUBYEXT = read_config("CCDLFLAGS")
	conf.env.rubyext_PATTERN = '%s.' + read_config('DLEXT')[0]

	# ok this is really stupid, but the command and flags are combined.
	# so we try to find the first argument...
	flags = read_config('LDSHARED')
	while flags and flags[0][0] != '-':
		flags = flags[1:]

	# we also want to strip out the deprecated ppc flags
	if len(flags) > 1 and flags[1] == "ppc":
		flags = flags[2:]

	conf.env.LINKFLAGS_RUBYEXT = flags
	conf.env.LINKFLAGS_RUBYEXT += read_config("LIBS")
	conf.env.LINKFLAGS_RUBYEXT += read_config("LIBRUBYARG_SHARED")

	if Options.options.rubyarchdir:
		conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
	else:
		conf.env.ARCHDIR_RUBY = read_config('sitearchdir')[0]

	if Options.options.rubylibdir:
		conf.env.LIBDIR_RUBY = Options.options.rubylibdir
	else:
		conf.env.LIBDIR_RUBY = read_config('sitelibdir')[0]
Пример #16
0
def check_ruby_ext_devel(conf):
	if not conf.env.RUBY:
		conf.fatal('ruby detection is required first')

	if not conf.env.CC_NAME and not conf.env.CXX_NAME:
		conf.fatal('load a c/c++ compiler first')

	version = tuple(map(int, conf.env.RUBY_VERSION.split(".")))

	def read_out(cmd):
		return Utils.to_list(Utils.cmd_output([conf.env.RUBY, '-rrbconfig', '-e', cmd]))

	def read_config(key):
		return read_out('puts Config::CONFIG[%r]' % key)

	ruby = conf.env['RUBY']
	archdir = read_config('archdir')
	cpppath = archdir
	if version >= (1, 9, 0):
		ruby_hdrdir = read_config('rubyhdrdir')
		cpppath += ruby_hdrdir
		cpppath += [os.path.join(ruby_hdrdir[0], read_config('arch')[0])]

	conf.check(header_name='ruby.h', includes=cpppath, mandatory=True, errmsg='could not find ruby header file')

	conf.env.LIBPATH_RUBYEXT = read_config('libdir')
	conf.env.LIBPATH_RUBYEXT += archdir
	conf.env.CPPPATH_RUBYEXT = cpppath
	conf.env.CCFLAGS_RUBYEXT = read_config("CCDLFLAGS")
	conf.env.rubyext_PATTERN = '%s.' + read_config('DLEXT')[0]

	# ok this is really stupid, but the command and flags are combined.
	# so we try to find the first argument...
	flags = read_config('LDSHARED')
	while flags and flags[0][0] != '-':
		flags = flags[1:]

	# we also want to strip out the deprecated ppc flags
	if len(flags) > 1 and flags[1] == "ppc":
		flags = flags[2:]

	conf.env.LINKFLAGS_RUBYEXT = flags
	conf.env.LINKFLAGS_RUBYEXT += read_config("LIBS")
	conf.env.LINKFLAGS_RUBYEXT += read_config("LIBRUBYARG_SHARED")

	if Options.options.rubyarchdir:
		conf.env.ARCHDIR_RUBY = Options.options.rubyarchdir
	else:
		conf.env.ARCHDIR_RUBY = read_config('sitearchdir')[0]

	if Options.options.rubylibdir:
		conf.env.LIBDIR_RUBY = Options.options.rubylibdir
	else:
		conf.env.LIBDIR_RUBY = read_config('sitelibdir')[0]
Пример #17
0
def get_msvc_version(conf, compiler, version, target, vcvars):
    debug('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
          target + ' ...')
    batfile = os.path.join(conf.blddir, 'waf-print-msvc.bat')
    f = open(batfile, 'w')
    f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
""" % (vcvars, target))
    f.close()
    sout = Utils.cmd_output(['cmd', '/E:on', '/V:on', '/C', batfile])
    lines = sout.splitlines()
    for x in ('Setting environment', 'Setting SDK environment',
              'Intel(R) C++ Compiler'):
        if lines[0].find(x) != -1:
            break
    else:
        debug('msvc: get_msvc_version: %r %r %r -> not found' %
              (compiler, version, target))
        conf.fatal(
            'msvc: Impossible to find a valid architecture for building (in get_msvc_version)'
        )
    for line in lines[1:]:
        if line.startswith('PATH='):
            path = line[5:]
            MSVC_PATH = path.split(';')
        elif line.startswith('INCLUDE='):
            MSVC_INCDIR = [i for i in line[8:].split(';') if i]
        elif line.startswith('LIB='):
            MSVC_LIBDIR = [i for i in line[4:].split(';') if i]
    env = {}
    env.update(os.environ)
    env.update(PATH=path)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
    if env.has_key('CL'):
        del (env['CL'])
    try:
        p = pproc.Popen([cxx, '/help'],
                        env=env,
                        stdout=pproc.PIPE,
                        stderr=pproc.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception('return code: %r: %r' % (p.returncode, err))
    except Exception, e:
        debug('msvc: get_msvc_version: %r %r %r -> failure' %
              (compiler, version, target))
        debug(str(e))
        conf.fatal('msvc: cannot run the compiler (in get_msvc_version)')
Пример #18
0
def detect(conf):
    if not conf.env.PYTHON:
        conf.env.PYTHON = sys.executable
    python = conf.find_program("python", var="PYTHON")
    if not python:
        conf.fatal("Could not find the path of the python executable")
    v = conf.env
    v["PYCMD"] = '"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"'
    v["PYFLAGS"] = ""
    v["PYFLAGS_OPT"] = "-O"
    v["PYC"] = getattr(Options.options, "pyc", 1)
    v["PYO"] = getattr(Options.options, "pyo", 1)
Пример #19
0
def detect(conf):
	if not conf.env.PYTHON:
		conf.env.PYTHON=sys.executable
	python=conf.find_program('python',var='PYTHON')
	if not python:
		conf.fatal('Could not find the path of the python executable')
	v=conf.env
	v['PYCMD']='"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"'
	v['PYFLAGS']=''
	v['PYFLAGS_OPT']='-O'
	v['PYC']=getattr(Options.options,'pyc',1)
	v['PYO']=getattr(Options.options,'pyo',1)
Пример #20
0
def detect(conf):
    if not conf.env.PYTHON:
        conf.env.PYTHON = sys.executable
    python = conf.find_program('python', var='PYTHON')
    if not python:
        conf.fatal('Could not find the path of the python executable')
    v = conf.env
    v['PYCMD'] = '"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"'
    v['PYFLAGS'] = ''
    v['PYFLAGS_OPT'] = '-O'
    v['PYC'] = getattr(Options.options, 'pyc', 1)
    v['PYO'] = getattr(Options.options, 'pyo', 1)
Пример #21
0
def get_msvc_version(conf, compiler, version, target, vcvars):
	debug('msvc: get_msvc_version: %r %r %r', compiler, version, target)
	batfile = os.path.join(conf.blddir, 'waf-print-msvc.bat')
	f = open(batfile, 'w')
	f.write("""@echo off
set INCLUDE=
set LIB=
call "{0!s}" {1!s}
echo PATH=%PATH%
echo INCLUDE=%INCLUDE%
echo LIB=%LIB%
""".format(vcvars, target))
	f.close()
	sout = Utils.cmd_output(['cmd', '/E:on', '/V:on', '/C', batfile])
	lines = sout.splitlines()

	for x in ('Setting environment', 'Setting SDK environment', 'Intel(R) C++ Compiler'):
		if lines[0].find(x) != -1:
			break
	else:
		debug('msvc: get_msvc_version: %r %r %r -> not found', compiler, version, target)
		conf.fatal('msvc: Impossible to find a valid architecture for building (in get_msvc_version)')

	for line in lines[1:]:
		if line.startswith('PATH='):
			path = line[5:]
			MSVC_PATH = path.split(';')
		elif line.startswith('INCLUDE='):
			MSVC_INCDIR = [i for i in line[8:].split(';') if i]
		elif line.startswith('LIB='):
			MSVC_LIBDIR = [i for i in line[4:].split(';') if i]

	# Check if the compiler is usable at all.
	# The detection may return 64-bit versions even on 32-bit systems, and these would fail to run.
	env = {}
	env.update(os.environ)
	env.update(PATH = path)
	compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
	cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
	# delete CL if exists. because it could contain parameters wich can change cl's behaviour rather catastrophically.
	if env.has_key('CL'):
		del(env['CL'])

	try:
		p = pproc.Popen([cxx, '/help'], env=env, stdout=pproc.PIPE, stderr=pproc.PIPE)
		out, err = p.communicate()
		if p.returncode != 0:
			raise Exception('return code: {0!r}: {1!r}'.format(p.returncode, err))
	except Exception, e:
		debug('msvc: get_msvc_version: %r %r %r -> failure', compiler, version, target)
		debug(str(e))
		conf.fatal('msvc: cannot run the compiler (in get_msvc_version)')
Пример #22
0
def detect(conf):
	java_path=os.environ['PATH'].split(os.pathsep)
	v=conf.env
	if os.environ.has_key('JAVA_HOME'):
		java_path=[os.path.join(os.environ['JAVA_HOME'],'bin')]+java_path
		conf.env['JAVA_HOME']=os.environ['JAVA_HOME']
	conf.find_program('javac',var='JAVAC',path_list=java_path)
	conf.find_program('java',var='JAVA',path_list=java_path)
	conf.find_program('jar',var='JAR',path_list=java_path)
	v['JAVA_EXT']=['.java']
	if os.environ.has_key('CLASSPATH'):
		v['CLASSPATH']=os.environ['CLASSPATH']
	if not v['JAR']:conf.fatal('jar is required for making java packages')
	if not v['JAVAC']:conf.fatal('javac is required for compiling java classes')
	v['JARCREATE']='cf'
def detect(conf):
	java_path=conf.environ['PATH'].split(os.pathsep)
	v=conf.env
	if'JAVA_HOME'in conf.environ:
		java_path=[os.path.join(conf.environ['JAVA_HOME'],'bin')]+java_path
		conf.env['JAVA_HOME']=[conf.environ['JAVA_HOME']]
	for x in'javac java jar'.split():
		conf.find_program(x,var=x.upper(),path_list=java_path)
		conf.env[x.upper()]=conf.cmd_to_list(conf.env[x.upper()])
	v['JAVA_EXT']=['.java']
	if'CLASSPATH'in conf.environ:
		v['CLASSPATH']=conf.environ['CLASSPATH']
	if not v['JAR']:conf.fatal('jar is required for making java packages')
	if not v['JAVAC']:conf.fatal('javac is required for compiling java classes')
	v['JARCREATE']='cf'
def setup_msvc(conf,versions):
	platforms=Utils.to_list(conf.env['MSVC_TARGETS'])or[i for i,j in all_msvc_platforms+all_icl_platforms+all_wince_platforms]
	desired_versions=conf.env['MSVC_VERSIONS']or[v for v,_ in versions][::-1]
	versiondict=dict(versions)
	for version in desired_versions:
		try:
			targets=dict(versiondict[version])
			for target in platforms:
				try:
					arch,(p1,p2,p3)=targets[target]
					compiler,version=version.split()
					return compiler,p1,p2,p3
				except KeyError:continue
		except KeyError:continue
	conf.fatal('msvc: Impossible to find a valid architecture for building (in setup_msvc)')
Пример #25
0
def detect(conf):
	java_path=conf.environ['PATH'].split(os.pathsep)
	v=conf.env
	if'JAVA_HOME'in conf.environ:
		java_path=[os.path.join(conf.environ['JAVA_HOME'],'bin')]+java_path
		conf.env['JAVA_HOME']=[conf.environ['JAVA_HOME']]
	for x in'javac java jar'.split():
		conf.find_program(x,var=x.upper(),path_list=java_path)
		conf.env[x.upper()]=conf.cmd_to_list(conf.env[x.upper()])
	v['JAVA_EXT']=['.java']
	if'CLASSPATH'in conf.environ:
		v['CLASSPATH']=conf.environ['CLASSPATH']
	if not v['JAR']:conf.fatal('jar is required for making java packages')
	if not v['JAVAC']:conf.fatal('javac is required for compiling java classes')
	v['JARCREATE']='cf'
Пример #26
0
Файл: perl.py Проект: NKSG/ns3
def check_perl_ext_devel(conf):
	if not conf.env.PERL:
		conf.fatal('perl detection is required first')
	def read_out(cmd):
		return Utils.to_list(Utils.cmd_output([conf.env.PERL,'-MConfig','-e',cmd]))
	conf.env.LINKFLAGS_PERLEXT=read_out('print $Config{lddlflags}')
	conf.env.CPPPATH_PERLEXT=read_out('print "$Config{archlib}/CORE"')
	conf.env.CCFLAGS_PERLEXT=read_out('print "$Config{ccflags} $Config{cccdlflags}"')
	conf.env.XSUBPP=read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
	conf.env.EXTUTILS_TYPEMAP=read_out('print "$Config{privlib}/ExtUtils/typemap"')
	conf.env.perlext_PATTERN='%s.'+read_out('print $Config{dlext}')[0]
	if getattr(Options.options,'perlarchdir',None):
		conf.env.ARCHDIR_PERL=Options.options.perlarchdir
	else:
		conf.env.ARCHDIR_PERL=read_out('print $Config{sitearch}')[0]
Пример #27
0
def get_msvc_version(conf,compiler,version,target,vcvars):
	debug('msvc: get_msvc_version: %r %r %r',compiler,version,target)
	batfile=os.path.join(conf.blddir,'waf-print-msvc.bat')
	f=open(batfile,'w')
	f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
"""%(vcvars,target))
	f.close()
	sout=Utils.cmd_output(['cmd','/E:on','/V:on','/C',batfile])
	lines=sout.splitlines()
	for x in('Setting environment','Setting SDK environment','Intel(R) C++ Compiler'):
		if lines[0].find(x)!=-1:
			break
	else:
		debug('msvc: get_msvc_version: %r %r %r -> not found',compiler,version,target)
		conf.fatal('msvc: Impossible to find a valid architecture for building (in get_msvc_version)')
	for line in lines[1:]:
		if line.startswith('PATH='):
			path=line[5:]
			MSVC_PATH=path.split(';')
		elif line.startswith('INCLUDE='):
			MSVC_INCDIR=[i for i in line[8:].split(';')if i]
		elif line.startswith('LIB='):
			MSVC_LIBDIR=[i for i in line[4:].split(';')if i]
	env={}
	env.update(os.environ)
	env.update(PATH=path)
	compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler)
	cxx=conf.find_program(compiler_name,path_list=MSVC_PATH)
	if env.has_key('CL'):
		del(env['CL'])
	try:
		p=pproc.Popen([cxx,'/help'],env=env,stdout=pproc.PIPE,stderr=pproc.PIPE)
		out,err=p.communicate()
		if p.returncode!=0:
			raise Exception('return code: %r: %r'%(p.returncode,err))
	except Exception as e:
		debug('msvc: get_msvc_version: %r %r %r -> failure',compiler,version,target)
		debug(str(e))
		conf.fatal('msvc: cannot run the compiler (in get_msvc_version)')
	else:
		debug('msvc: get_msvc_version: %r %r %r -> OK',compiler,version,target)
	return(MSVC_PATH,MSVC_INCDIR,MSVC_LIBDIR)
Пример #28
0
def setup_msvc(conf, versions):
	platforms = Utils.to_list(conf.env['MSVC_TARGETS']) or [i for i,j in all_msvc_platforms+all_icl_platforms+all_wince_platforms]
	desired_versions = conf.env['MSVC_VERSIONS'] or [v for v,_ in versions][::-1]
	versiondict = dict(versions)

	for version in desired_versions:
		try:
			targets = dict(versiondict [version])
			for target in platforms:
				try:
					arch,(p1,p2,p3) = targets[target]
					compiler,revision = version.split()
					return compiler,revision,p1,p2,p3
				except KeyError: continue
		except KeyError: continue
	conf.fatal('msvc: Impossible to find a valid architecture for building (in setup_msvc)')
Пример #29
0
def get_msvc_version(conf, compiler, version, target, vcvars):
    debug('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
          target + ' ...')
    batfile = os.path.join(conf.blddir, "waf-print-msvc.bat")
    f = open(batfile, 'w')
    f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
""" % (vcvars, target))
    f.close()
    sout = Utils.cmd_output(['cmd', '/E:on', '/V:on', '/C', batfile])
    lines = sout.splitlines()
    if lines[0].find("Setting environment") == -1 and lines[0].find(
            "Setting SDK environment") == -1 and lines[1].find(
                'Intel(R) C++ Compiler') == -1:
        debug('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
              target + ' -> not found')
        conf.fatal(
            'msvc: Impossible to find a valid architecture for building (in get_msvc_version)'
        )
    for line in lines[1:]:
        if line.startswith('PATH='):
            path = line[5:]
            MSVC_PATH = path.split(';')
        elif line.startswith('INCLUDE='):
            MSVC_INCDIR = [i for i in line[8:].split(';') if i]
        elif line.startswith('LIB='):
            MSVC_LIBDIR = [i for i in line[4:].split(';') if i]
    env = {}
    env.update(os.environ)
    env.update(PATH=path)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
    import pproc
    try:
        p = pproc.Popen([cxx], env=env, stdout=pproc.PIPE, stderr=pproc.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception('return code: ' + str(p.returncode) + ': ' + err)
    except Exception, e:
        print('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
              target + ' -> failed: ' + str(e))
        conf.fatal('msvc: Compiler is not runnable (in get_msvc_version)')
Пример #30
0
def check_python_version(conf, minver=None):
    assert minver is None or isinstance(minver, tuple)
    python = conf.env["PYTHON"]
    if not python:
        conf.fatal("could not find the python executable")
    cmd = [python, "-c", "import sys\nfor x in sys.version_info: print(str(x))"]
    debug("python: Running python command %r" % cmd)
    proc = Utils.pproc.Popen(cmd, stdout=Utils.pproc.PIPE)
    lines = proc.communicate()[0].split()
    assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))
    result = (minver is None) or (pyver_tuple >= minver)
    if result:
        pyver = ".".join([str(x) for x in pyver_tuple[:2]])
        conf.env["PYTHON_VERSION"] = pyver
        if "PYTHONDIR" in conf.environ:
            pydir = conf.environ["PYTHONDIR"]
        else:
            if sys.platform == "win32":
                (python_LIBDEST, pydir) = _get_python_variables(
                    python,
                    ["get_config_var('LIBDEST')", "get_python_lib(standard_lib=0, prefix=%r)" % conf.env["PREFIX"]],
                    ["from distutils.sysconfig import get_config_var, get_python_lib"],
                )
            else:
                python_LIBDEST = None
                (pydir,) = _get_python_variables(
                    python,
                    ["get_python_lib(standard_lib=0, prefix=%r)" % conf.env["PREFIX"]],
                    ["from distutils.sysconfig import get_config_var, get_python_lib"],
                )
            if python_LIBDEST is None:
                if conf.env["LIBDIR"]:
                    python_LIBDEST = os.path.join(conf.env["LIBDIR"], "python" + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env["PREFIX"], "lib", "python" + pyver)
        if hasattr(conf, "define"):
            conf.define("PYTHONDIR", pydir)
        conf.env["PYTHONDIR"] = pydir
    pyver_full = ".".join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.check_message_custom("Python version", "", pyver_full)
    else:
        minver_str = ".".join(map(str, minver))
        conf.check_message("Python version", ">= %s" % minver_str, result, option=pyver_full)
    if not result:
        conf.fatal("The python version is too old (%r)" % pyver_full)
Пример #31
0
def find_msvc(conf):
	if sys.platform!='win32':
		conf.fatal('MSVC module only works under native Win32 Python! cygwin is not supported yet')
	v=conf.env
	compiler,version,path,includes,libdirs=detect_msvc(conf)
	compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler)
	has_msvc_manifest=(compiler=='msvc'and float(version)>=8)or(compiler=='wsdk'and float(version)>=6)or(compiler=='intel'and float(version)>=11)
	cxx=None
	if v.CXX:cxx=v.CXX
	elif'CXX'in conf.environ:cxx=conf.environ['CXX']
	if not cxx:cxx=conf.find_program(compiler_name,var='CXX',path_list=path,mandatory=True)
	cxx=conf.cmd_to_list(cxx)
	env=dict(conf.environ)
	env.update(PATH=';'.join(path))
	if not Utils.cmd_output([cxx,'/nologo','/?'],silent=True,env=env):
		conf.fatal('the msvc compiler could not be identified')
	link=v.LINK_CXX
	if not link:
		link=conf.find_program(linker_name,path_list=path,mandatory=True)
	ar=v.AR
	if not ar:
		ar=conf.find_program(lib_name,path_list=path,mandatory=True)
	mt=v.MT
	if has_msvc_manifest:
		mt=conf.find_program('MT',path_list=path,mandatory=True)
	v.MSVC_MANIFEST=has_msvc_manifest
	v.PATH=path
	v.CPPPATH=includes
	v.LIBPATH=libdirs
	v.CC=v.CXX=cxx
	v.CC_NAME=v.CXX_NAME='msvc'
	v.LINK=v.LINK_CXX=link
	if not v.LINK_CC:
		v.LINK_CC=v.LINK_CXX
	v.AR=ar
	v.MT=mt
	v.MTFLAGS=v.ARFLAGS=['/NOLOGO']
	conf.check_tool('winres')
	if not conf.env.WINRC:
		warn('Resource compiler not found. Compiling resource file is disabled')
	try:v.prepend_value('CPPPATH',conf.environ['INCLUDE'])
	except KeyError:pass
	try:v.prepend_value('LIBPATH',conf.environ['LIB'])
	except KeyError:pass
Пример #32
0
def detect(conf):
	# If JAVA_PATH is set, we prepend it to the path list
	java_path = os.environ['PATH'].split(os.pathsep)
	v = conf.env

	if 'JAVA_HOME' in os.environ:
		java_path = [os.path.join(os.environ['JAVA_HOME'], 'bin')] + java_path
		conf.env['JAVA_HOME'] = os.environ['JAVA_HOME']

	conf.find_program('javac', var='JAVAC', path_list=java_path)
	conf.find_program('java', var='JAVA', path_list=java_path)
	conf.find_program('jar', var='JAR', path_list=java_path)
	v['JAVA_EXT'] = ['.java']

	if 'CLASSPATH' in os.environ:
		v['CLASSPATH'] = os.environ['CLASSPATH']

	if not v['JAR']: conf.fatal('jar is required for making java packages')
	if not v['JAVAC']: conf.fatal('javac is required for compiling java classes')
	v['JARCREATE'] = 'cf' # can use cvf
Пример #33
0
def find_msvc(conf):
    if sys.platform != 'win32':
        conf.fatal(
            'MSVC module only works under native Win32 Python! cygwin is not supported yet'
        )
    v = conf.env
    compiler, path, includes, libdirs = detect_msvc(conf)
    v['PATH'] = path
    v['CPPPATH'] = includes
    v['LIBPATH'] = libdirs
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = None
    if v['CXX']: cxx = v['CXX']
    elif 'CXX' in conf.environ: cxx = conf.environ['CXX']
    if not cxx:
        cxx = conf.find_program(compiler_name, var='CXX', path_list=path)
    if not cxx: conf.fatal('%s was not found (compiler)' % compiler_name)
    cxx = conf.cmd_to_list(cxx)
    env = dict(conf.environ)
    env.update(PATH=';'.join(path))
    if not Utils.cmd_output([cxx, '/nologo', '/?'], silent=True, env=env):
        conf.fatal('the msvc compiler could not be identified')
    v['CC'] = v['CXX'] = cxx
    v['CC_NAME'] = v['CXX_NAME'] = 'msvc'
    try:
        v.prepend_value('CPPPATH', conf.environ['INCLUDE'])
    except KeyError:
        pass
    try:
        v.prepend_value('LIBPATH', conf.environ['LIB'])
    except KeyError:
        pass
    if not v['LINK_CXX']:
        link = conf.find_program(linker_name, path_list=path)
        if link: v['LINK_CXX'] = link
        else: conf.fatal('%s was not found (linker)' % linker_name)
    v['LINK'] = link
    if not v['LINK_CC']: v['LINK_CC'] = v['LINK_CXX']
    if not v['AR']:
        stliblink = conf.find_program(lib_name, path_list=path)
        if not stliblink: return
        v['AR'] = stliblink
        v['ARFLAGS'] = ['/NOLOGO']
    manifesttool = conf.find_program('MT', path_list=path)
    if manifesttool:
        v['MT'] = manifesttool
        v['MTFLAGS'] = ['/NOLOGO']
    conf.check_tool('winres')
    if not conf.env['WINRC']:
        warn(
            'Resource compiler not found. Compiling resource file is disabled')
Пример #34
0
def check_perl_ext_devel(conf):
    if not conf.env.PERL:
        conf.fatal('perl detection is required first')

    def read_out(cmd):
        return Utils.to_list(
            Utils.cmd_output([conf.env.PERL, '-MConfig', '-e', cmd]))

    conf.env.LINKFLAGS_PERLEXT = read_out('print $Config{lddlflags}')
    conf.env.CPPPATH_PERLEXT = read_out('print "$Config{archlib}/CORE"')
    conf.env.CCFLAGS_PERLEXT = read_out(
        'print "$Config{ccflags} $Config{cccdlflags}"')
    conf.env.XSUBPP = read_out(
        'print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
    conf.env.EXTUTILS_TYPEMAP = read_out(
        'print "$Config{privlib}/ExtUtils/typemap"')
    conf.env.perlext_PATTERN = '%s.' + read_out('print $Config{dlext}')[0]
    if getattr(Options.options, 'perlarchdir', None):
        conf.env.ARCHDIR_PERL = Options.options.perlarchdir
    else:
        conf.env.ARCHDIR_PERL = read_out('print $Config{sitearch}')[0]
Пример #35
0
def check_jni_headers(conf):
    if not conf.env.CC_NAME and not conf.env.CXX_NAME:
        conf.fatal('load a compiler first (gcc, g++, ..)')
    if not conf.env.JAVA_HOME:
        conf.fatal('set JAVA_HOME in the system environment')
    javaHome = conf.env['JAVA_HOME'][0]
    b = Build.BuildContext()
    b.load_dirs(conf.srcdir, conf.blddir)
    dir = b.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
    f = dir.ant_glob('**/(jni|jni_md).h', flat=False)
    incDirs = [x.parent.abspath() for x in f]
    dir = b.root.find_dir(conf.env.JAVA_HOME[0])
    f = dir.ant_glob('**/*jvm.(so|dll)', flat=False)
    libDirs = [x.parent.abspath() for x in f] or [javaHome]
    for i, d in enumerate(libDirs):
        if conf.check(header_name='jni.h',
                      define_name='HAVE_JNI_H',
                      lib='jvm',
                      libpath=d,
                      includes=incDirs,
                      uselib_store='JAVA',
                      uselib='JAVA'):
            break
    else:
        conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Пример #36
0
def check_jni_headers(conf):
	"""
	Check for jni headers and libraries

	On success the environment variable xxx_JAVA is added for uselib
	"""

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

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

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

	b = Build.BuildContext()
	b.load_dirs(conf.srcdir, conf.blddir)
	dir = b.root.find_dir(conf.env.JAVA_HOME[0] + '/include')
	f = dir.ant_glob('**/(jni|jni_md).h', flat=False)
	incDirs = [x.parent.abspath() for x in f]

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

	for i, d in enumerate(libDirs):
		if conf.check(header_name='jni.h', define_name='HAVE_JNI_H', lib='jvm',
				libpath=d, includes=incDirs, uselib_store='JAVA', uselib='JAVA'):
			break
	else:
		conf.fatal('could not find lib jvm in %r (see config.log)' % libDirs)
Пример #37
0
def check_perl_version(conf, minver=None):
	"""
	Checks if perl is installed.

	If installed the variable PERL will be set in environment.

	Perl binary can be overridden by --with-perl-binary config variable

	"""

	if getattr(Options.options, 'perlbinary', None):
		conf.env.PERL = Options.options.perlbinary
	else:
		conf.find_program('perl', var='PERL', mandatory=True)

	try:
		version = Utils.cmd_output([conf.env.PERL, '-e', 'printf "%vd",$^V'])
	except:
		conf.fatal('could not determine the perl version')

	conf.env.PERL_VERSION = version
	cver = ''
	if minver:
		try:
			ver = tuple(map(int, version.split('.')))
		except:
			conf.fatal('unsupported perl version %r' % version)
		if ver < minver:
			conf.fatal('perl is too old')

		cver = '.'.join(map(str,minver))
	conf.check_message('perl', cver, True, version)
Пример #38
0
def get_msvc_version(conf,compiler,version,target,vcvars):
	debug('msvc: get_msvc_version: '+compiler+' '+version+' '+target+' ...')
	batfile=os.path.join(conf.blddir,"waf-print-msvc.bat")
	f=open(batfile,'w')
	f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
"""%(vcvars,target))
	f.close()
	sout=Utils.cmd_output(['cmd','/E:on','/V:on','/C',batfile])
	lines=sout.splitlines()
	if lines[0].find("Setting environment")==-1 and lines[0].find("Setting SDK environment")==-1 and lines[1].find('Intel(R) C++ Compiler')==-1:
		debug('msvc: get_msvc_version: '+compiler+' '+version+' '+target+' -> not found')
		conf.fatal('msvc: Impossible to find a valid architecture for building (in get_msvc_version)')
	for line in lines[1:]:
		if line.startswith('PATH='):
			path=line[5:]
			MSVC_PATH=path.split(';')
		elif line.startswith('INCLUDE='):
			MSVC_INCDIR=[i for i in line[8:].split(';')if i]
		elif line.startswith('LIB='):
			MSVC_LIBDIR=[i for i in line[4:].split(';')if i]
	env={}
	env.update(os.environ)
	env.update(PATH=path)
	compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler)
	cxx=conf.find_program(compiler_name,path_list=MSVC_PATH)
	import pproc
	try:
		p=pproc.Popen([cxx],env=env,stdout=pproc.PIPE,stderr=pproc.PIPE)
		out,err=p.communicate()
		if p.returncode!=0:
			raise Exception('return code: '+str(p.returncode)+': '+err)
	except Exception,e:
		print('msvc: get_msvc_version: '+compiler+' '+version+' '+target+' -> failed: '+str(e))
		conf.fatal('msvc: Compiler is not runnable (in get_msvc_version)')
Пример #39
0
def check_ruby_version(conf, minver=()):
	"""
	Checks if ruby is installed.
	If installed the variable RUBY will be set in environment.
	Ruby binary can be overridden by --with-ruby-binary config variable
	"""

	if Options.options.rubybinary:
		conf.env.RUBY = Options.options.rubybinary
	else:
		conf.find_program("ruby", var="RUBY", mandatory=True)

	ruby = conf.env.RUBY

	try:
		version = Utils.cmd_output([ruby, '-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
	except:
		conf.fatal('could not determine ruby version')
	conf.env.RUBY_VERSION = version

	try:
		ver = tuple(map(int, version.split(".")))
	except:
		conf.fatal('unsupported ruby version %r' % version)

	cver = ''
	if minver:
		if ver < minver:
			conf.fatal('ruby is too old')
		cver = ".".join([str(x) for x in minver])

	conf.check_message('ruby', cver, True, version)
Пример #40
0
def check_perl_version(conf, minver=None):
    """
	Checks if perl is installed.

	If installed the variable PERL will be set in environment.

	Perl binary can be overridden by --with-perl-binary config variable

	"""

    if getattr(Options.options, "perlbinary", None):
        conf.env.PERL = Options.options.perlbinary
    else:
        conf.find_program("perl", var="PERL", mandatory=True)

    try:
        version = Utils.cmd_output([conf.env.PERL, "-e", 'printf "%vd",$^V'])
    except:
        conf.fatal("could not determine the perl version")

    conf.env.PERL_VERSION = version
    cver = ""
    if minver:
        try:
            ver = tuple(map(int, version.split(".")))
        except:
            conf.fatal("unsupported perl version {0!r}".format(version))
        if ver < minver:
            conf.fatal("perl is too old")

        cver = ".".join(map(str, minver))
    conf.check_message("perl", cver, True, version)
Пример #41
0
def check_perl_version(conf, minver=None):
	"""
	Checks if perl is installed.

	If installed the variable PERL will be set in environment.

	Perl binary can be overridden by --with-perl-binary config variable

	"""

	if getattr(Options.options, 'perlbinary', None):
		conf.env.PERL = Options.options.perlbinary
	else:
		conf.find_program('perl', var='PERL', mandatory=True)

	try:
		version = Utils.cmd_output([conf.env.PERL, '-e', 'printf "%vd",$^V'])
	except:
		conf.fatal('could not determine the perl version')

	conf.env.PERL_VERSION = version
	cver = ''
	if minver:
		try:
			ver = tuple(map(int, version.split('.')))
		except:
			conf.fatal('unsupported perl version %r' % version)
		if ver < minver:
			conf.fatal('perl is too old')

		cver = '.'.join(map(str,minver))
	conf.check_message('perl', cver, True, version)
Пример #42
0
def check_ruby_version(conf, minver=()):
	"""
	Checks if ruby is installed.
	If installed the variable RUBY will be set in environment.
	Ruby binary can be overridden by --with-ruby-binary config variable
	"""

	if Options.options.rubybinary:
		conf.env.RUBY = Options.options.rubybinary
	else:
		conf.find_program("ruby", var="RUBY", mandatory=True)

	ruby = conf.env.RUBY

	try:
		version = Utils.cmd_output([ruby, '-e', 'puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
	except:
		conf.fatal('could not determine ruby version')
	conf.env.RUBY_VERSION = version

	try:
		ver = tuple(map(int, version.split(".")))
	except:
		conf.fatal('unsupported ruby version %r' % version)

	cver = ''
	if minver:
		if ver < minver:
			conf.fatal('ruby is too old')
		cver = ".".join([str(x) for x in minver])

	conf.check_message('ruby', cver, True, version)
Пример #43
0
def detect(conf):
    # If JAVA_PATH is set, we prepend it to the path list
    java_path = conf.environ["PATH"].split(os.pathsep)
    v = conf.env

    if "JAVA_HOME" in conf.environ:
        java_path = [os.path.join(conf.environ["JAVA_HOME"], "bin")] + java_path
        conf.env["JAVA_HOME"] = [conf.environ["JAVA_HOME"]]

    for x in "javac java jar".split():
        conf.find_program(x, var=x.upper(), path_list=java_path)
        conf.env[x.upper()] = conf.cmd_to_list(conf.env[x.upper()])
    v["JAVA_EXT"] = [".java"]

    if "CLASSPATH" in conf.environ:
        v["CLASSPATH"] = conf.environ["CLASSPATH"]

    if not v["JAR"]:
        conf.fatal("jar is required for making java packages")
    if not v["JAVAC"]:
        conf.fatal("javac is required for compiling java classes")
    v["JARCREATE"] = "cf"  # can use cvf
Пример #44
0
def check_python_version(conf,minver=None):
	assert minver is None or isinstance(minver,tuple)
	python=conf.env['PYTHON']
	assert python,("python is %r !"%(python,))
	cmd=[python,"-c","import sys\nfor x in sys.version_info: print(str(x))"]
	debug('python: Running python command %r'%cmd)
	proc=Utils.pproc.Popen(cmd,stdout=Utils.pproc.PIPE)
	lines=proc.communicate()[0].split()
	assert len(lines)==5,"found %i lines, expected 5: %r"%(len(lines),lines)
	pyver_tuple=(int(lines[0]),int(lines[1]),int(lines[2]),lines[3],int(lines[4]))
	result=(minver is None)or(pyver_tuple>=minver)
	if result:
		pyver='.'.join([str(x)for x in pyver_tuple[:2]])
		conf.env['PYTHON_VERSION']=pyver
		if'PYTHONDIR'in conf.environ:
			pydir=conf.environ['PYTHONDIR']
		else:
			if sys.platform=='win32':
				(python_LIBDEST,pydir)=_get_python_variables(python,["get_config_var('LIBDEST')","get_python_lib(standard_lib=0, prefix=%r)"%conf.env['PREFIX']],['from distutils.sysconfig import get_config_var, get_python_lib'])
			else:
				python_LIBDEST=None
				(pydir,)=_get_python_variables(python,["get_python_lib(standard_lib=0, prefix=%r)"%conf.env['PREFIX']],['from distutils.sysconfig import get_config_var, get_python_lib'])
			if python_LIBDEST is None:
				if conf.env['LIBDIR']:
					python_LIBDEST=os.path.join(conf.env['LIBDIR'],"python"+pyver)
				else:
					python_LIBDEST=os.path.join(conf.env['PREFIX'],"lib","python"+pyver)
		if hasattr(conf,'define'):
			conf.define('PYTHONDIR',pydir)
		conf.env['PYTHONDIR']=pydir
	pyver_full='.'.join(map(str,pyver_tuple[:3]))
	if minver is None:
		conf.check_message_custom('Python version','',pyver_full)
	else:
		minver_str='.'.join(map(str,minver))
		conf.check_message('Python version',">= %s"%(minver_str,),result,option=pyver_full)
	if not result:
		conf.fatal("Python too old.")
Пример #45
0
Файл: perl.py Проект: hef/samba
def check_perl_ext_devel(conf):
	"""
	Check for configuration needed to build perl extensions.

	Sets different xxx_PERLEXT variables in the environment.

	Also sets the ARCHDIR_PERL variable useful as installation path,
	which can be overridden by --with-perl-archdir
	"""
	if not conf.env.PERL:
		conf.fatal('perl detection is required first')

	def read_out(cmd):
		return Utils.to_list(Utils.cmd_output([conf.env.PERL, '-MConfig', '-e', cmd]))

	conf.env.LINKFLAGS_PERLEXT = read_out('print $Config{lddlflags}')
	conf.env.CPPPATH_PERLEXT   = read_out('print "$Config{archlib}/CORE"')
	conf.env.CCFLAGS_PERLEXT   = read_out('print "$Config{ccflags} $Config{cccdlflags}"')
	conf.env.XSUBPP            = read_out('print "$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}"')
	conf.env.EXTUTILS_TYPEMAP  = read_out('print "$Config{privlib}/ExtUtils/typemap"')
	conf.env.perlext_PATTERN   = '%s.' + read_out('print $Config{dlext}')[0]

	def try_any(keys):
		for k in keys:
			conf.start_msg("Checking for perl $Config{%s}:" % k)
			try:
				v = read_out('print $Config{%s}' % k)[0]
				conf.end_msg("'%s'" % (v), 'GREEN')
				return v
			except IndexError:
				conf.end_msg(False, 'YELLOW')
				pass
		return None

	perl_arch_install_dir = None
	if getattr(Options.options, 'perl_arch_install_dir', None):
		perl_arch_install_dir = Options.options.perl_arch_install_dir
	if perl_arch_install_dir is None:
		perl_arch_install_dir = try_any(['vendorarch', 'sitearch', 'archlib'])
	if perl_arch_install_dir is None:
		conf.fatal('No perl arch install directory autodetected.' +
			   'Please define it with --with-perl-arch-install-dir.')
	conf.start_msg("PERL_ARCH_INSTALL_DIR: ")
	conf.end_msg("'%s'" % (perl_arch_install_dir), 'GREEN')
	conf.env.PERL_ARCH_INSTALL_DIR = perl_arch_install_dir

	perl_lib_install_dir = None
	if getattr(Options.options, 'perl_lib_install_dir', None):
		perl_lib_install_dir = Options.options.perl_lib_install_dir
	if perl_lib_install_dir is None:
		perl_lib_install_dir = try_any(['vendorlib', 'sitelib', 'privlib'])
	if perl_lib_install_dir is None:
		conf.fatal('No perl lib install directory autodetected. ' +
			   'Please define it with --with-perl-lib-install-dir.')
	conf.start_msg("PERL_LIB_INSTALL_DIR: ")
	conf.end_msg("'%s'" % (perl_lib_install_dir), 'GREEN')
	conf.env.PERL_LIB_INSTALL_DIR = perl_lib_install_dir
def find_msvc(conf):
	if sys.platform!='win32':
		conf.fatal('MSVC module only works under native Win32 Python! cygwin is not supported yet')
	v=conf.env
	compiler,path,includes,libdirs=detect_msvc(conf)
	v['PATH']=path
	v['CPPPATH']=includes
	v['LIBPATH']=libdirs
	compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler)
	cxx=None
	if v['CXX']:cxx=v['CXX']
	elif'CXX'in conf.environ:cxx=conf.environ['CXX']
	if not cxx:cxx=conf.find_program(compiler_name,var='CXX',path_list=path)
	if not cxx:conf.fatal('%s was not found (compiler)'%compiler_name)
	cxx=conf.cmd_to_list(cxx)
	env=dict(conf.environ)
	env.update(PATH=';'.join(path))
	if not Utils.cmd_output([cxx,'/nologo','/?'],silent=True,env=env):
		conf.fatal('the msvc compiler could not be identified')
	v['CC']=v['CXX']=cxx
	v['CC_NAME']=v['CXX_NAME']='msvc'
	try:v.prepend_value('CPPPATH',conf.environ['INCLUDE'])
	except KeyError:pass
	try:v.prepend_value('LIBPATH',conf.environ['LIB'])
	except KeyError:pass
	if not v['LINK_CXX']:
		link=conf.find_program(linker_name,path_list=path)
		if link:v['LINK_CXX']=link
		else:conf.fatal('%s was not found (linker)'%linker_name)
	v['LINK']=link
	if not v['LINK_CC']:v['LINK_CC']=v['LINK_CXX']
	if not v['AR']:
		stliblink=conf.find_program(lib_name,path_list=path)
		if not stliblink:return
		v['AR']=stliblink
		v['ARFLAGS']=['/NOLOGO']
	manifesttool=conf.find_program('MT',path_list=path)
	if manifesttool:
		v['MT']=manifesttool
		v['MTFLAGS']=['/NOLOGO']
	conf.check_tool('winres')
	if not conf.env['WINRC']:
		warn('Resource compiler not found. Compiling resource file is disabled')
Пример #47
0
def check_perl_version(conf, minver=None):
    if getattr(Options.options, 'perlbinary', None):
        conf.env.PERL = Options.options.perlbinary
    else:
        conf.find_program('perl', var='PERL', mandatory=True)
    try:
        version = Utils.cmd_output([conf.env.PERL, '-e', 'printf "%vd",$^V'])
    except:
        conf.fatal('could not determine the perl version')
    conf.env.PERL_VERSION = version
    cver = ''
    if minver:
        try:
            ver = tuple(map(int, version.split('.')))
        except:
            conf.fatal('unsupported perl version %r' % version)
        if ver < minver:
            conf.fatal('perl is too old')
        cver = '.'.join(map(str, minver))
    conf.check_message('perl', cver, True, version)
Пример #48
0
Файл: perl.py Проект: NKSG/ns3
def check_perl_version(conf,minver=None):
	if getattr(Options.options,'perlbinary',None):
		conf.env.PERL=Options.options.perlbinary
	else:
		conf.find_program('perl',var='PERL',mandatory=True)
	try:
		version=Utils.cmd_output([conf.env.PERL,'-e','printf "%vd",$^V'])
	except:
		conf.fatal('could not determine the perl version')
	conf.env.PERL_VERSION=version
	cver=''
	if minver:
		try:
			ver=tuple(map(int,version.split('.')))
		except:
			conf.fatal('unsupported perl version %r'%version)
		if ver<minver:
			conf.fatal('perl is too old')
		cver='.'.join(map(str,minver))
	conf.check_message('perl',cver,True,version)
Пример #49
0
def check_ruby_version(conf,minver=()):
	if Options.options.rubybinary:
		conf.env.RUBY=Options.options.rubybinary
	else:
		conf.find_program("ruby",var="RUBY",mandatory=True)
	ruby=conf.env.RUBY
	try:
		version=Utils.cmd_output([ruby,'-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
	except:
		conf.fatal('could not determine ruby version')
	conf.env.RUBY_VERSION=version
	try:
		ver=tuple(map(int,version.split(".")))
	except:
		conf.fatal('unsupported ruby version %r'%version)
	cver=''
	if minver:
		if ver<minver:
			conf.fatal('ruby is too old')
		cver=".".join([str(x)for x in minver])
	conf.check_message('ruby',cver,True,version)
Пример #50
0
Файл: ruby.py Проект: NKSG/ns3
def check_ruby_version(conf,minver=()):
	if Options.options.rubybinary:
		conf.env.RUBY=Options.options.rubybinary
	else:
		conf.find_program("ruby",var="RUBY",mandatory=True)
	ruby=conf.env.RUBY
	try:
		version=Utils.cmd_output([ruby,'-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
	except:
		conf.fatal('could not determine ruby version')
	conf.env.RUBY_VERSION=version
	try:
		ver=tuple(map(int,version.split(".")))
	except:
		conf.fatal('unsupported ruby version %r'%version)
	cver=''
	if minver:
		if ver<minver:
			conf.fatal('ruby is too old')
		cver=".".join(str(x)for x in minver)
	conf.check_message('ruby',cver,True,version)
Пример #51
0
def find_msvc(conf):
    # due to path format limitations, limit operation only to native Win32. Yeah it sucks.
    if sys.platform != 'win32':
        conf.fatal(
            'MSVC module only works under native Win32 Python! cygwin is not supported yet'
        )

    v = conf.env

    compiler, version, path, includes, libdirs = detect_msvc(conf)

    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    has_msvc_manifest = (compiler == 'msvc' and float(version) >= 8) or (
        compiler == 'wsdk'
        and float(version) >= 6) or (compiler == 'intel'
                                     and float(version) >= 11)

    # compiler
    cxx = None
    if v.CXX: cxx = v.CXX
    elif 'CXX' in conf.environ: cxx = conf.environ['CXX']
    if not cxx:
        cxx = conf.find_program(compiler_name,
                                var='CXX',
                                path_list=path,
                                mandatory=True)
    cxx = conf.cmd_to_list(cxx)

    # before setting anything, check if the compiler is really msvc
    env = dict(conf.environ)
    env.update(PATH=';'.join(path))
    if not Utils.cmd_output([cxx, '/nologo', '/?'], silent=True, env=env):
        conf.fatal('the msvc compiler could not be identified')

    link = v.LINK_CXX
    if not link:
        link = conf.find_program(linker_name, path_list=path, mandatory=True)
    ar = v.AR
    if not ar:
        ar = conf.find_program(lib_name, path_list=path, mandatory=True)

    # manifest tool. Not required for VS 2003 and below. Must have for VS 2005 and later
    mt = v.MT
    if has_msvc_manifest:
        mt = conf.find_program('MT', path_list=path, mandatory=True)

    # no more possibility of failure means the data state will be consistent
    # we may store the data safely now

    v.MSVC_MANIFEST = has_msvc_manifest
    v.PATH = path
    v.CPPPATH = includes
    v.LIBPATH = libdirs

    # c/c++ compiler
    v.CC = v.CXX = cxx
    v.CC_NAME = v.CXX_NAME = 'msvc'

    v.LINK = v.LINK_CXX = link
    if not v.LINK_CC:
        v.LINK_CC = v.LINK_CXX

    v.AR = ar
    v.MT = mt
    v.MTFLAGS = v.ARFLAGS = ['/NOLOGO']

    conf.check_tool('winres')

    if not conf.env.WINRC:
        warn(
            'Resource compiler not found. Compiling resource file is disabled')

    # environment flags
    try:
        v.prepend_value('CPPPATH', conf.environ['INCLUDE'])
    except KeyError:
        pass
    try:
        v.prepend_value('LIBPATH', conf.environ['LIB'])
    except KeyError:
        pass
Пример #52
0
def check_python_headers(conf,mandatory=True):
	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')
	if Options.platform=='darwin':
		conf.check_tool('osx')
	try:
		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')"%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))
	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
	if python_SYSLIBS is not None:
		for lib in python_SYSLIBS.split():
			if lib.startswith('-l'):
				lib=lib[2:]
			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:])
			else:
				env.append_value('LINKFLAGS_PYEMBED',lib)
	if Options.platform!='darwin'and python_LDFLAGS:
		env.append_value('LINKFLAGS_PYEMBED',python_LDFLAGS.split())
	result=False
	name='python'+env['PYTHON_VERSION']
	if python_LIBDIR is not None:
		path=[python_LIBDIR]
		conf.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")
	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']
	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 %s --includes"%(python,python_config)).strip().split():
			if(incstr.startswith('-I')or incstr.startswith('/I')):
				incstr=incstr[2:]
			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]
	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')
	conf.check(define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG_2,errmsg='Could not find the python development headers',mandatory=mandatory)
Пример #53
0
def find_msvc(conf):
    # due to path format limitations, limit operation only to native Win32. Yeah it sucks.
    if sys.platform != 'win32':
        conf.fatal(
            'MSVC module only works under native Win32 Python! cygwin is not supported yet'
        )

    v = conf.env

    compiler, path, includes, libdirs = detect_msvc(conf)
    v['PATH'] = path
    v['CPPPATH'] = includes
    v['LIBPATH'] = libdirs

    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)

    # compiler
    cxx = None
    if v['CXX']: cxx = v['CXX']
    elif 'CXX' in conf.environ: cxx = conf.environ['CXX']
    if not cxx:
        cxx = conf.find_program(compiler_name, var='CXX', path_list=path)
    if not cxx: conf.fatal('%s was not found (compiler)' % compiler_name)
    cxx = conf.cmd_to_list(cxx)

    # before setting anything, check if the compiler is really msvc
    env = dict(conf.environ)
    env.update(PATH=';'.join(path))
    if not Utils.cmd_output([cxx, '/nologo', '/?'], silent=True, env=env):
        conf.fatal('the msvc compiler could not be identified')

    # c/c++ compiler
    v['CC'] = v['CXX'] = cxx
    v['CC_NAME'] = v['CXX_NAME'] = 'msvc'

    # environment flags
    try:
        v.prepend_value('CPPPATH', conf.environ['INCLUDE'])
    except KeyError:
        pass
    try:
        v.prepend_value('LIBPATH', conf.environ['LIB'])
    except KeyError:
        pass

    # linker
    if not v['LINK_CXX']:
        link = conf.find_program(linker_name, path_list=path)
        if link: v['LINK_CXX'] = link
        else: conf.fatal('%s was not found (linker)' % linker_name)
    v['LINK'] = link

    if not v['LINK_CC']: v['LINK_CC'] = v['LINK_CXX']

    # staticlib linker
    if not v['AR']:
        stliblink = conf.find_program(lib_name, path_list=path)
        if not stliblink: return
        v['AR'] = stliblink
        v['ARFLAGS'] = ['/NOLOGO']

    # manifest tool. Not required for VS 2003 and below. Must have for VS 2005 and later
    manifesttool = conf.find_program('MT', path_list=path)
    if manifesttool:
        v['MT'] = manifesttool
        v['MTFLAGS'] = ['/NOLOGO']

    conf.check_tool('winres')

    if not conf.env['WINRC']:
        warn(
            'Resource compiler not found. Compiling resource file is disabled')
Пример #54
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
    python = env['PYTHON']
    assert python, ("python is %r !" % (python, ))
    if Options.platform == 'darwin':
        conf.check_tool('osx')
    try:
        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')" % 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))
    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
    if python_SYSLIBS is not None:
        for lib in python_SYSLIBS.split():
            if lib.startswith('-l'):
                lib = lib[2:]
            env.append_value('LIB_PYEMBED', lib)
    if python_SHLIBS is not None:
        for lib in python_SHLIBS.split():
            if lib.startswith('-l'):
                lib = lib[2:]
            env.append_value('LIB_PYEMBED', lib)
    if Options.platform != 'darwin' and python_LDFLAGS:
        env.append_value('LINKFLAGS_PYEMBED', python_LDFLAGS.split())
    result = False
    name = 'python' + env['PYTHON_VERSION']
    if python_LIBDIR is not None:
        path = [python_LIBDIR]
        conf.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")
    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']
    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():
            if (incstr.startswith('-I') or incstr.startswith('/I')):
                incstr = incstr[2:]
            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]
    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')
    test_env = env.copy()
    a = test_env.append_value
    a('CPPPATH', env['CPPPATH_PYEMBED'])
    a('LIBPATH', env['LIBPATH_PYEMBED'])
    a('LIB', env['LIB_PYEMBED'])
    a('LINKFLAGS', env['LINKFLAGS_PYEMBED'])
    a('CXXFLAGS', env['CXXFLAGS_PYEMBED'])
    a('CCFLAGS', env['CCFLAGS_PYEMBED'])
    conf.check(header_name='Python.h',
               define_name='HAVE_PYTHON_H',
               env=test_env,
               fragment=FRAG_2,
               errmsg='Could not find the python development headers',
               mandatory=1)
Пример #55
0
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)
Пример #56
0
def check_python_version(conf, minver=None):
    """
	Check if the python interpreter is found matching a given minimum version.
	minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.

	If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
	(eg. '2.4') of the actual python version found, and PYTHONDIR is
	defined, pointing to the site-packages directory appropriate for
	this python version, where modules/packages/extensions should be
	installed.
	"""
    assert minver is None or isinstance(minver, tuple)
    python = conf.env['PYTHON']
    if not python:
        conf.fatal('could not find the python executable')

    # Get python version string
    cmd = [
        python, "-c", "import sys\nfor x in sys.version_info: print(str(x))"
    ]
    debug('python: Running python command %r' % cmd)
    proc = Utils.pproc.Popen(cmd, stdout=Utils.pproc.PIPE, shell=False)
    lines = proc.communicate()[0].split()
    assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines),
                                                                lines)
    pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3],
                   int(lines[4]))

    # compare python version with the minimum required
    result = (minver is None) or (pyver_tuple >= minver)

    if result:
        # define useful environment variables
        pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
        conf.env['PYTHON_VERSION'] = pyver

        if 'PYTHONDIR' in conf.environ:
            pydir = conf.environ['PYTHONDIR']
        else:
            if sys.platform == 'win32':
                (python_LIBDEST, pydir) = \
                  _get_python_variables(python,
                         ["get_config_var('LIBDEST') or ''",
                          "get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']],
                         ['from distutils.sysconfig import get_config_var, get_python_lib'])
            else:
                python_LIBDEST = None
                (pydir,) = \
                  _get_python_variables(python,
                         ["get_python_lib(standard_lib=0, prefix=%r) or ''" % conf.env['PREFIX']],
                         ['from distutils.sysconfig import get_config_var, get_python_lib'])
            if python_LIBDEST is None:
                if conf.env['LIBDIR']:
                    python_LIBDEST = os.path.join(conf.env['LIBDIR'],
                                                  "python" + pyver)
                else:
                    python_LIBDEST = os.path.join(conf.env['PREFIX'], "lib",
                                                  "python" + pyver)

        if 'PYTHONARCHDIR' in conf.environ:
            pyarchdir = conf.environ['PYTHONARCHDIR']
        else:
            (pyarchdir, ) = _get_python_variables(python, [
                "get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''"
                % conf.env['PREFIX']
            ], [
                'from distutils.sysconfig import get_config_var, get_python_lib'
            ])
            if not pyarchdir:
                pyarchdir = pydir

        if hasattr(conf, 'define'
                   ):  # conf.define is added by the C tool, so may not exist
            conf.define('PYTHONDIR', pydir)
            conf.define('PYTHONARCHDIR', pyarchdir)

        conf.env['PYTHONDIR'] = pydir

    # Feedback
    pyver_full = '.'.join(map(str, pyver_tuple[:3]))
    if minver is None:
        conf.check_message_custom('Python version', '', pyver_full)
    else:
        minver_str = '.'.join(map(str, minver))
        conf.check_message('Python version',
                           ">= %s" % minver_str,
                           result,
                           option=pyver_full)

    if not result:
        conf.fatal('The python version is too old (%r)' % pyver_full)