Beispiel #1
0
def d_hook(self, node):
    """
	Compile *D* files. To get .di files as well as .o files, set the following::

		def build(bld):
			bld.program(source='foo.d', target='app', generate_headers=True)

	"""
    ext = Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe' and 'obj' or 'o'
    out = '%s.%d.%s' % (node.name, self.idx, ext)

    def create_compiled_task(self, name, node):
        task = self.create_task(name, node, node.parent.find_or_declare(out))
        try:
            self.compiled_tasks.append(task)
        except AttributeError:
            self.compiled_tasks = [task]
        return task

    if getattr(self, 'generate_headers', None):
        tsk = create_compiled_task(self, 'd_with_header', node)
        tsk.outputs.append(node.change_ext(self.env.DHEADER_ext))
    else:
        tsk = create_compiled_task(self, 'd', node)
    return tsk
Beispiel #2
0
def get_cc_version(conf,cc,gcc=False,icc=False):
	cmd=cc+['-dM','-E','-']
	try:
		p=subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
		p.stdin.write('\n')
		out=p.communicate()[0]
	except:
		conf.fatal('could not determine the compiler version %r'%cmd)
	if not isinstance(out,str):
		out=out
	if gcc:
		if out.find('__INTEL_COMPILER')>=0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__')<0:
			conf.fatal('Could not determine the compiler type')
	if icc and out.find('__INTEL_COMPILER')<0:
		conf.fatal('Not icc/icpc')
	k={}
	if icc or gcc:
		out=out.split('\n')
		import shlex
		for line in out:
			lst=shlex.split(line)
			if len(lst)>2:
				key=lst[1]
				val=lst[2]
				k[key]=val
		def isD(var):
			return var in k
		def isT(var):
			return var in k and k[var]!='0'
		if not conf.env.DEST_OS:
			conf.env.DEST_OS=''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS=MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__')and isD('__MACH__'):
				conf.env.DEST_OS='darwin'
			elif isD('__unix__'):
				conf.env.DEST_OS='generic'
		if isD('__ELF__'):
			conf.env.DEST_BINFMT='elf'
		elif isD('__WINNT__')or isD('__CYGWIN__'):
			conf.env.DEST_BINFMT='pe'
			conf.env.LIBDIR=conf.env['PREFIX']+'/bin'
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT='mac-o'
		if not conf.env.DEST_BINFMT:
			conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS)
		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i]
				break
		Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')]))
		conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
	return k
Beispiel #3
0
def get_cc_version(conf,cc,gcc=False,icc=False):
	cmd=cc+['-dM','-E','-']
	try:
		p=subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
		p.stdin.write('\n')
		out=p.communicate()[0]
	except:
		conf.fatal('could not determine the compiler version %r'%cmd)
	if not isinstance(out,str):
		out=out
	if gcc:
		if out.find('__INTEL_COMPILER')>=0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__')<0:
			conf.fatal('Could not determine the compiler type')
	if icc and out.find('__INTEL_COMPILER')<0:
		conf.fatal('Not icc/icpc')
	k={}
	if icc or gcc:
		out=out.split('\n')
		import shlex
		for line in out:
			lst=shlex.split(line)
			if len(lst)>2:
				key=lst[1]
				val=lst[2]
				k[key]=val
		def isD(var):
			return var in k
		def isT(var):
			return var in k and k[var]!='0'
		if not conf.env.DEST_OS:
			conf.env.DEST_OS=''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS=MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__')and isD('__MACH__'):
				conf.env.DEST_OS='darwin'
			elif isD('__unix__'):
				conf.env.DEST_OS='generic'
		if isD('__ELF__'):
			conf.env.DEST_BINFMT='elf'
		elif isD('__WINNT__')or isD('__CYGWIN__'):
			conf.env.DEST_BINFMT='pe'
			conf.env.LIBDIR=conf.env['PREFIX']+'/bin'
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT='mac-o'
		if not conf.env.DEST_BINFMT:
			conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS)
		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i]
				break
		Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')]))
		conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
	return k
Beispiel #4
0
def d_platform_flags(self):
    v = self.env
    if not v.DEST_OS:
        v.DEST_OS = Utils.unversioned_sys_platform()
    if Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe':
        v['dprogram_PATTERN'] = '%s.exe'
        v['dshlib_PATTERN'] = 'lib%s.dll'
        v['dstlib_PATTERN'] = 'lib%s.a'
    else:
        v['dprogram_PATTERN'] = '%s'
        v['dshlib_PATTERN'] = 'lib%s.so'
        v['dstlib_PATTERN'] = 'lib%s.a'
Beispiel #5
0
def d_platform_flags(self):
    v = self.env
    if not v.DEST_OS:
        v.DEST_OS = Utils.unversioned_sys_platform()
    if Utils.destos_to_binfmt(self.env.DEST_OS) == "pe":
        v["dprogram_PATTERN"] = "%s.exe"
        v["dshlib_PATTERN"] = "lib%s.dll"
        v["dstlib_PATTERN"] = "lib%s.a"
    else:
        v["dprogram_PATTERN"] = "%s"
        v["dshlib_PATTERN"] = "lib%s.so"
        v["dstlib_PATTERN"] = "lib%s.a"
Beispiel #6
0
def d_platform_flags(self):
	v=self.env
	if not v.DEST_OS:
		v.DEST_OS=Utils.unversioned_sys_platform()
	if Utils.destos_to_binfmt(self.env.DEST_OS)=='pe':
		v['dprogram_PATTERN']='%s.exe'
		v['dshlib_PATTERN']='lib%s.dll'
		v['dstlib_PATTERN']='lib%s.a'
	else:
		v['dprogram_PATTERN']='%s'
		v['dshlib_PATTERN']='lib%s.so'
		v['dstlib_PATTERN']='lib%s.a'
Beispiel #7
0
def d_platform_flags(self):
	"""
	Set the extensions dll/so for d programs and libraries
	"""
	v = self.env
	if not v.DEST_OS:
		v.DEST_OS = Utils.unversioned_sys_platform()
	if Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe':
		v['dprogram_PATTERN'] = '%s.exe'
		v['dshlib_PATTERN']   = 'lib%s.dll'
		v['dstlib_PATTERN']   = 'lib%s.a'
	else:
		v['dprogram_PATTERN'] = '%s'
		v['dshlib_PATTERN']   = 'lib%s.so'
		v['dstlib_PATTERN']   = 'lib%s.a'
Beispiel #8
0
def d_platform_flags(self):
	"""
	Set the extensions dll/so for d programs and libraries
	"""
	v = self.env
	if not v.DEST_OS:
		v.DEST_OS = Utils.unversioned_sys_platform()
	if Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe':
		v['dprogram_PATTERN'] = '%s.exe'
		v['dshlib_PATTERN']   = 'lib%s.dll'
		v['dstlib_PATTERN']   = 'lib%s.a'
	else:
		v['dprogram_PATTERN'] = '%s'
		v['dshlib_PATTERN']   = 'lib%s.so'
		v['dstlib_PATTERN']   = 'lib%s.a'
Beispiel #9
0
def d_hook(self,node):
	ext=Utils.destos_to_binfmt(self.env.DEST_OS)=='pe'and'obj'or'o'
	out='%s.%d.%s'%(node.name,self.idx,ext)
	def create_compiled_task(self,name,node):
		task=self.create_task(name,node,node.parent.find_or_declare(out))
		try:
			self.compiled_tasks.append(task)
		except AttributeError:
			self.compiled_tasks=[task]
		return task
	if getattr(self,'generate_headers',None):
		tsk=create_compiled_task(self,'d_with_header',node)
		tsk.outputs.append(node.change_ext(self.env['DHEADER_ext']))
	else:
		tsk=create_compiled_task(self,'d',node)
	return tsk
Beispiel #10
0
def d_platform_flags(self):
	v=self.env
	if not v.DEST_OS:
		v.DEST_OS=Utils.unversioned_sys_platform()
	binfmt=Utils.destos_to_binfmt(self.env.DEST_OS)
	if binfmt=='pe':
		v.dprogram_PATTERN='%s.exe'
		v.dshlib_PATTERN='lib%s.dll'
		v.dstlib_PATTERN='lib%s.a'
	elif binfmt=='mac-o':
		v.dprogram_PATTERN='%s'
		v.dshlib_PATTERN='lib%s.dylib'
		v.dstlib_PATTERN='lib%s.a'
	else:
		v.dprogram_PATTERN='%s'
		v.dshlib_PATTERN='lib%s.so'
		v.dstlib_PATTERN='lib%s.a'
Beispiel #11
0
def d_hook(self, node):
    ext = Utils.destos_to_binfmt(self.env.DEST_OS) == "pe" and "obj" or "o"
    out = "%s.%d.%s" % (node.name, self.idx, ext)

    def create_compiled_task(self, name, node):
        task = self.create_task(name, node, node.parent.find_or_declare(out))
        try:
            self.compiled_tasks.append(task)
        except AttributeError:
            self.compiled_tasks = [task]
        return task

    if getattr(self, "generate_headers", None):
        tsk = create_compiled_task(self, "d_with_header", node)
        tsk.outputs.append(node.change_ext(self.env["DHEADER_ext"]))
    else:
        tsk = create_compiled_task(self, "d", node)
    return tsk
Beispiel #12
0
def d_hook(self, node):
    ext = Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe' and 'obj' or 'o'
    out = '%s.%d.%s' % (node.name, self.idx, ext)

    def create_compiled_task(self, name, node):
        task = self.create_task(name, node, node.parent.find_or_declare(out))
        try:
            self.compiled_tasks.append(task)
        except AttributeError:
            self.compiled_tasks = [task]
        return task

    if getattr(self, 'generate_headers', None):
        tsk = create_compiled_task(self, 'd_with_header', node)
        tsk.outputs.append(node.change_ext(self.env.DHEADER_ext))
    else:
        tsk = create_compiled_task(self, 'd', node)
    return tsk
Beispiel #13
0
def d_platform_flags(self):
    """
    Sets the extensions dll/so for d programs and libraries
    """
    v = self.env
    if not v.DEST_OS:
        v.DEST_OS = Utils.unversioned_sys_platform()
    binfmt = Utils.destos_to_binfmt(self.env.DEST_OS)
    if binfmt == "pe":
        v.dprogram_PATTERN = "%s.exe"
        v.dshlib_PATTERN = "lib%s.dll"
        v.dstlib_PATTERN = "lib%s.a"
    elif binfmt == "mac-o":
        v.dprogram_PATTERN = "%s"
        v.dshlib_PATTERN = "lib%s.dylib"
        v.dstlib_PATTERN = "lib%s.a"
    else:
        v.dprogram_PATTERN = "%s"
        v.dshlib_PATTERN = "lib%s.so"
        v.dstlib_PATTERN = "lib%s.a"
Beispiel #14
0
def d_hook(self, node):
	"""
	Compile *D* files. To get .di files as well as .o files, set the following::

		def build(bld):
			bld.program(source='foo.d', target='app', generate_headers=True)

	"""
	ext = Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe' and 'obj' or 'o'
	out = '%s.%d.%s' % (node.name, self.idx, ext)
	def create_compiled_task(self, name, node):
		task = self.create_task(name, node, node.parent.find_or_declare(out))
		try:
			self.compiled_tasks.append(task)
		except AttributeError:
			self.compiled_tasks = [task]
		return task

	if getattr(self, 'generate_headers', None):
		tsk = create_compiled_task(self, 'd_with_header', node)
		tsk.outputs.append(node.change_ext(self.env['DHEADER_ext']))
	else:
		tsk = create_compiled_task(self, 'd', node)
	return tsk
Beispiel #15
0
def get_cc_version(conf, cc, gcc=False, icc=False):
    """
	Run the preprocessor to determine the compiler version

	The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*
	"""
    cmd = cc + ['-dM', '-E', '-']
    try:
        p = Utils.subprocess.Popen(cmd,
                                   stdin=Utils.subprocess.PIPE,
                                   stdout=Utils.subprocess.PIPE,
                                   stderr=Utils.subprocess.PIPE)
        p.stdin.write('\n'.encode())
        out = p.communicate()[0]
    except:
        conf.fatal('could not determine the compiler version %r' % cmd)

    if not isinstance(out, str):
        out = out.decode(sys.stdout.encoding)

    if gcc:
        if out.find('__INTEL_COMPILER') >= 0:
            conf.fatal('The intel compiler pretends to be gcc')
        if out.find('__GNUC__') < 0:
            conf.fatal('Could not determine the compiler type')

    if icc and out.find('__INTEL_COMPILER') < 0:
        conf.fatal('Not icc/icpc')

    k = {}
    if icc or gcc:
        out = out.split('\n')
        import shlex

        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        def isT(var):
            return var in k and k[var] != '0'

        # Some documentation is available at http://predef.sourceforge.net
        # The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ''
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD('__APPLE__') and isD('__MACH__'):
                conf.env.DEST_OS = 'darwin'
            elif isD('__unix__'
                     ):  # unix must be tested last as it's a generic fallback
                conf.env.DEST_OS = 'generic'

        if isD('__ELF__'):
            conf.env.DEST_BINFMT = 'elf'
        elif isD('__WINNT__') or isD('__CYGWIN__'):
            conf.env.DEST_BINFMT = 'pe'
            conf.env.LIBDIR = conf.env['PREFIX'] + '/bin'
        elif isD('__APPLE__'):
            conf.env.DEST_BINFMT = 'mac-o'

        if not conf.env.DEST_BINFMT:
            # Infer the binary format from the os name.
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break

        Logs.debug('ccroot: dest platform: ' + ' '.join([
            conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')
        ]))
        if icc:
            ver = k['__INTEL_COMPILER']
            conf.env['CC_VERSION'] = (ver[:-2], ver[-2], ver[-1])
        else:
            conf.env['CC_VERSION'] = (k['__GNUC__'], k['__GNUC_MINOR__'],
                                      k['__GNUC_PATCHLEVEL__'])
    return k
Beispiel #16
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
    """
	Runs the preprocessor to determine the gcc/icc/clang version

	The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*

	:raise: :py:class:`waflib.Errors.ConfigurationError`
	"""
    cmd = cc + ['-dM', '-E', '-']
    env = conf.env.env or None
    try:
        out, err = conf.cmd_and_log(cmd,
                                    output=0,
                                    input='\n'.encode(),
                                    env=env)
    except Exception:
        conf.fatal('Could not determine the compiler version %r' % cmd)

    if gcc:
        if out.find('__INTEL_COMPILER') >= 0:
            conf.fatal('The intel compiler pretends to be gcc')
        if out.find('__GNUC__') < 0 and out.find('__clang__') < 0:
            conf.fatal('Could not determine the compiler type')

    if icc and out.find('__INTEL_COMPILER') < 0:
        conf.fatal('Not icc/icpc')

    if clang and out.find('__clang__') < 0:
        conf.fatal('Not clang/clang++')
    if not clang and out.find('__clang__') >= 0:
        conf.fatal(
            'Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure'
        )

    k = {}
    if icc or gcc or clang:
        out = out.splitlines()
        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        # Some documentation is available at http://predef.sourceforge.net
        # The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ''
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD('__APPLE__') and isD('__MACH__'):
                conf.env.DEST_OS = 'darwin'
            elif isD('__unix__'
                     ):  # unix must be tested last as it's a generic fallback
                conf.env.DEST_OS = 'generic'

        if isD('__ELF__'):
            conf.env.DEST_BINFMT = 'elf'
        elif isD('__WINNT__') or isD('__CYGWIN__') or isD('_WIN32'):
            conf.env.DEST_BINFMT = 'pe'
            conf.env.LIBDIR = conf.env.BINDIR
        elif isD('__APPLE__'):
            conf.env.DEST_BINFMT = 'mac-o'

        if not conf.env.DEST_BINFMT:
            # Infer the binary format from the os name.
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break

        Logs.debug('ccroot: dest platform: ' + ' '.join([
            conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')
        ]))
        if icc:
            ver = k['__INTEL_COMPILER']
            conf.env.CC_VERSION = (ver[:-2], ver[-2], ver[-1])
        else:
            if isD('__clang__') and isD('__clang_major__'):
                conf.env.CC_VERSION = (k['__clang_major__'],
                                       k['__clang_minor__'],
                                       k['__clang_patchlevel__'])
            else:
                # older clang versions and gcc
                conf.env.CC_VERSION = (k['__GNUC__'], k['__GNUC_MINOR__'],
                                       k.get('__GNUC_PATCHLEVEL__', '0'))
    return k
Beispiel #17
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
    cmd = cc + ['-dM', '-E', '-']
    env = conf.env.env or None
    try:
        out, err = conf.cmd_and_log(cmd, output=0, input='\n', env=env)
    except Exception:
        conf.fatal('Could not determine the compiler version %r' % cmd)
    if gcc:
        if out.find('__INTEL_COMPILER') >= 0:
            conf.fatal('The intel compiler pretends to be gcc')
        if out.find('__GNUC__') < 0 and out.find('__clang__') < 0:
            conf.fatal('Could not determine the compiler type')
    if icc and out.find('__INTEL_COMPILER') < 0:
        conf.fatal('Not icc/icpc')
    if clang and out.find('__clang__') < 0:
        conf.fatal('Not clang/clang++')
    if not clang and out.find('__clang__') >= 0:
        conf.fatal(
            'Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure'
        )
    k = {}
    if icc or gcc or clang:
        out = out.splitlines()
        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ''
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD('__APPLE__') and isD('__MACH__'):
                conf.env.DEST_OS = 'darwin'
            elif isD('__unix__'):
                conf.env.DEST_OS = 'generic'
        if isD('__ELF__'):
            conf.env.DEST_BINFMT = 'elf'
        elif isD('__WINNT__') or isD('__CYGWIN__') or isD('_WIN32'):
            conf.env.DEST_BINFMT = 'pe'
            conf.env.LIBDIR = conf.env.BINDIR
        elif isD('__APPLE__'):
            conf.env.DEST_BINFMT = 'mac-o'
        if not conf.env.DEST_BINFMT:
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)
        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break
        Logs.debug('ccroot: dest platform: ' + ' '.join([
            conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')
        ]))
        if icc:
            ver = k['__INTEL_COMPILER']
            conf.env.CC_VERSION = (ver[:-2], ver[-2], ver[-1])
        else:
            if isD('__clang__') and isD('__clang_major__'):
                conf.env.CC_VERSION = (k['__clang_major__'],
                                       k['__clang_minor__'],
                                       k['__clang_patchlevel__'])
            else:
                conf.env.CC_VERSION = (k['__GNUC__'], k['__GNUC_MINOR__'],
                                       k.get('__GNUC_PATCHLEVEL__', '0'))
    return k
Beispiel #18
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
    cmd = cc + ['-dM', '-E', '-']
    env = conf.env.env or None
    try:
        p = Utils.subprocess.Popen(cmd,
                                   stdin=Utils.subprocess.PIPE,
                                   stdout=Utils.subprocess.PIPE,
                                   stderr=Utils.subprocess.PIPE,
                                   env=env)
        p.stdin.write('\n')
        out = p.communicate()[0]
    except Exception:
        conf.fatal('Could not determine the compiler version %r' % cmd)
    if not isinstance(out, str):
        out = out.decode(sys.stdout.encoding or 'iso8859-1')
    if gcc:
        if out.find('__INTEL_COMPILER') >= 0:
            conf.fatal('The intel compiler pretends to be gcc')
        if out.find('__GNUC__') < 0 and out.find('__clang__') < 0:
            conf.fatal('Could not determine the compiler type')
    if icc and out.find('__INTEL_COMPILER') < 0:
        conf.fatal('Not icc/icpc')
    if clang and out.find('__clang__') < 0:
        conf.fatal('Not clang/clang++')
    k = {}
    if icc or gcc or clang:
        out = out.splitlines()
        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        def isT(var):
            return var in k and k[var] != '0'

        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ''
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD('__APPLE__') and isD('__MACH__'):
                conf.env.DEST_OS = 'darwin'
            elif isD('__unix__'):
                conf.env.DEST_OS = 'generic'
        if isD('__ELF__'):
            conf.env.DEST_BINFMT = 'elf'
        elif isD('__WINNT__') or isD('__CYGWIN__') or isD('_WIN32'):
            conf.env.DEST_BINFMT = 'pe'
            conf.env.LIBDIR = conf.env.BINDIR
        elif isD('__APPLE__'):
            conf.env.DEST_BINFMT = 'mac-o'
        if not conf.env.DEST_BINFMT:
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)
        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break
        Logs.debug('ccroot: dest platform: ' + ' '.join([
            conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')
        ]))
        if icc:
            ver = k['__INTEL_COMPILER']
            conf.env['CC_VERSION'] = (ver[:-2], ver[-2], ver[-1])
        else:
            if isD('__clang__'):
                conf.env['CC_VERSION'] = (k['__clang_major__'],
                                          k['__clang_minor__'],
                                          k['__clang_patchlevel__'])
            else:
                try:
                    conf.env['CC_VERSION'] = (k['__GNUC__'],
                                              k['__GNUC_MINOR__'],
                                              k['__GNUC_PATCHLEVEL__'])
                except KeyError:
                    conf.env['CC_VERSION'] = (k['__GNUC__'],
                                              k['__GNUC_MINOR__'], 0)
    return k
Beispiel #19
0
def get_cc_version(conf, cc, gcc=False, icc=False):
    cmd = cc + ["-dM", "-E", "-"]
    try:
        p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        p.stdin.write("\n")
        out = p.communicate()[0]
    except:
        conf.fatal("could not determine the compiler version %r" % cmd)
    if not isinstance(out, str):
        out = out
    if gcc:
        if out.find("__INTEL_COMPILER") >= 0:
            conf.fatal("The intel compiler pretends to be gcc")
        if out.find("__GNUC__") < 0:
            conf.fatal("Could not determine the compiler type")
    if icc and out.find("__INTEL_COMPILER") < 0:
        conf.fatal("Not icc/icpc")
    k = {}
    if icc or gcc:
        out = out.split("\n")
        import shlex

        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        def isT(var):
            return var in k and k[var] != "0"

        mp1 = {
            "__linux__": "linux",
            "__GNU__": "gnu",
            "__FreeBSD__": "freebsd",
            "__NetBSD__": "netbsd",
            "__OpenBSD__": "openbsd",
            "__sun": "sunos",
            "__hpux": "hpux",
            "__sgi": "irix",
            "_AIX": "aix",
            "__CYGWIN__": "cygwin",
            "__MSYS__": "msys",
            "_UWIN": "uwin",
            "_WIN64": "win32",
            "_WIN32": "win32",
            "__POWERPC__": "powerpc",
        }
        for i in mp1:
            if isD(i):
                conf.env.DEST_OS = mp1[i]
                break
        else:
            if isD("__APPLE__") and isD("__MACH__"):
                conf.env.DEST_OS = "darwin"
            elif isD("__unix__"):
                conf.env.DEST_OS = "generic"
        if isD("__ELF__"):
            conf.env.DEST_BINFMT = "elf"
        elif isD("__WINNT__") or isD("__CYGWIN__"):
            conf.env.DEST_BINFMT = "pe"
            conf.env.LIBDIR = conf.env["PREFIX"] + "/bin"
        elif isD("__APPLE__"):
            conf.env.DEST_BINFMT = "mac-o"
        if not conf.env.DEST_BINFMT:
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)
        mp2 = {
            "__x86_64__": "x86_64",
            "__i386__": "x86",
            "__ia64__": "ia",
            "__mips__": "mips",
            "__sparc__": "sparc",
            "__alpha__": "alpha",
            "__arm__": "arm",
            "__hppa__": "hppa",
            "__powerpc__": "powerpc",
        }
        for i in mp2:
            if isD(i):
                conf.env.DEST_CPU = mp2[i]
                break
        Logs.debug(
            "ccroot: dest platform: " + " ".join([conf.env[x] or "?" for x in ("DEST_OS", "DEST_BINFMT", "DEST_CPU")])
        )
        conf.env["CC_VERSION"] = (k["__GNUC__"], k["__GNUC_MINOR__"], k["__GNUC_PATCHLEVEL__"])
    return k
Beispiel #20
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
    """
    Runs the preprocessor to determine the gcc/icc/clang version

    The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*

    :raise: :py:class:`waflib.Errors.ConfigurationError`
    """
    cmd = cc + ["-dM", "-E", "-"]
    env = conf.env.env or None
    try:
        out, err = conf.cmd_and_log(cmd, output=0, input=b"\n", env=env)
    except Errors.WafError:
        conf.fatal("Could not determine the compiler version %r" % cmd)

    if gcc:
        if out.find("__INTEL_COMPILER") >= 0:
            conf.fatal("The intel compiler pretends to be gcc")
        if out.find("__GNUC__") < 0 and out.find("__clang__") < 0:
            conf.fatal("Could not determine the compiler type")

    if icc and out.find("__INTEL_COMPILER") < 0:
        conf.fatal("Not icc/icpc")

    if clang and out.find("__clang__") < 0:
        conf.fatal("Not clang/clang++")
    if not clang and out.find("__clang__") >= 0:
        conf.fatal(
            "Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure"
        )

    k = {}
    if icc or gcc or clang:
        out = out.splitlines()
        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

        # Some documentation is available at http://predef.sourceforge.net
        # The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ""
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD("__APPLE__") and isD("__MACH__"):
                conf.env.DEST_OS = "darwin"
            elif isD("__unix__"
                     ):  # unix must be tested last as it's a generic fallback
                conf.env.DEST_OS = "generic"

        if isD("__ELF__"):
            conf.env.DEST_BINFMT = "elf"
        elif isD("__WINNT__") or isD("__CYGWIN__") or isD("_WIN32"):
            conf.env.DEST_BINFMT = "pe"
            if not conf.env.IMPLIBDIR:
                conf.env.IMPLIBDIR = conf.env.LIBDIR  # for .lib or .dll.a files
            conf.env.LIBDIR = conf.env.BINDIR
        elif isD("__APPLE__"):
            conf.env.DEST_BINFMT = "mac-o"

        if not conf.env.DEST_BINFMT:
            # Infer the binary format from the os name.
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break

        Logs.debug("ccroot: dest platform: " + " ".join([
            conf.env[x] or "?" for x in ("DEST_OS", "DEST_BINFMT", "DEST_CPU")
        ]))
        if icc:
            ver = k["__INTEL_COMPILER"]
            conf.env.CC_VERSION = (ver[:-2], ver[-2], ver[-1])
        else:
            if isD("__clang__") and isD("__clang_major__"):
                conf.env.CC_VERSION = (
                    k["__clang_major__"],
                    k["__clang_minor__"],
                    k["__clang_patchlevel__"],
                )
            else:
                # older clang versions and gcc
                conf.env.CC_VERSION = (
                    k["__GNUC__"],
                    k["__GNUC_MINOR__"],
                    k.get("__GNUC_PATCHLEVEL__", "0"),
                )
    return k
Beispiel #21
0
def get_cc_version(conf,cc,gcc=False,icc=False,clang=False):
	cmd=cc+['-dM','-E','-']
	env=conf.env.env or None
	try:
		out,err=conf.cmd_and_log(cmd,output=0,input='\n',env=env)
	except Exception:
		conf.fatal('Could not determine the compiler version %r'%cmd)
	if gcc:
		if out.find('__INTEL_COMPILER')>=0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__')<0 and out.find('__clang__')<0:
			conf.fatal('Could not determine the compiler type')
	if icc and out.find('__INTEL_COMPILER')<0:
		conf.fatal('Not icc/icpc')
	if clang and out.find('__clang__')<0:
		conf.fatal('Not clang/clang++')
	if not clang and out.find('__clang__')>=0:
		conf.fatal('Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure')
	k={}
	if icc or gcc or clang:
		out=out.splitlines()
		for line in out:
			lst=shlex.split(line)
			if len(lst)>2:
				key=lst[1]
				val=lst[2]
				k[key]=val
		def isD(var):
			return var in k
		if not conf.env.DEST_OS:
			conf.env.DEST_OS=''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS=MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__')and isD('__MACH__'):
				conf.env.DEST_OS='darwin'
			elif isD('__unix__'):
				conf.env.DEST_OS='generic'
		if isD('__ELF__'):
			conf.env.DEST_BINFMT='elf'
		elif isD('__WINNT__')or isD('__CYGWIN__')or isD('_WIN32'):
			conf.env.DEST_BINFMT='pe'
			conf.env.LIBDIR=conf.env.BINDIR
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT='mac-o'
		if not conf.env.DEST_BINFMT:
			conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS)
		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i]
				break
		Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')]))
		if icc:
			ver=k['__INTEL_COMPILER']
			conf.env['CC_VERSION']=(ver[:-2],ver[-2],ver[-1])
		else:
			if isD('__clang__')and isD('__clang_major__'):
				conf.env['CC_VERSION']=(k['__clang_major__'],k['__clang_minor__'],k['__clang_patchlevel__'])
			else:
				conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k.get('__GNUC_PATCHLEVEL__','0'))
	return k
Beispiel #22
0
def get_cc_version(conf,cc,gcc=False,icc=False,clang=False):
	cmd=cc+['-dM','-E','-']
	env=conf.env.env or None
	try:
		p=Utils.subprocess.Popen(cmd,stdin=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE,stderr=Utils.subprocess.PIPE,env=env)
		p.stdin.write('\n')
		out=p.communicate()[0]
	except Exception:
		conf.fatal('Could not determine the compiler version %r'%cmd)
	if not isinstance(out,str):
		out=out.decode(sys.stdout.encoding or'iso8859-1')
	if gcc:
		if out.find('__INTEL_COMPILER')>=0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__')<0 and out.find('__clang__')<0:
			conf.fatal('Could not determine the compiler type')
	if icc and out.find('__INTEL_COMPILER')<0:
		conf.fatal('Not icc/icpc')
	if clang and out.find('__clang__')<0:
		conf.fatal('Not clang/clang++')
	k={}
	if icc or gcc or clang:
		out=out.splitlines()
		for line in out:
			lst=shlex.split(line)
			if len(lst)>2:
				key=lst[1]
				val=lst[2]
				k[key]=val
		def isD(var):
			return var in k
		def isT(var):
			return var in k and k[var]!='0'
		if not conf.env.DEST_OS:
			conf.env.DEST_OS=''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS=MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__')and isD('__MACH__'):
				conf.env.DEST_OS='darwin'
			elif isD('__unix__'):
				conf.env.DEST_OS='generic'
		if isD('__ELF__'):
			conf.env.DEST_BINFMT='elf'
		elif isD('__WINNT__')or isD('__CYGWIN__')or isD('_WIN32'):
			conf.env.DEST_BINFMT='pe'
			conf.env.LIBDIR=conf.env.BINDIR
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT='mac-o'
		if not conf.env.DEST_BINFMT:
			conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS)
		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i]
				break
		Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')]))
		if icc:
			ver=k['__INTEL_COMPILER']
			conf.env['CC_VERSION']=(ver[:-2],ver[-2],ver[-1])
		else:
			if isD('__clang__'):
				conf.env['CC_VERSION']=(k['__clang_major__'],k['__clang_minor__'],k['__clang_patchlevel__'])
			else:
				try:
					conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
				except KeyError:
					conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],0)
	return k
Beispiel #23
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
	"""
	Runs the preprocessor to determine the gcc/icc/clang version

	The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*

	:raise: :py:class:`waflib.Errors.ConfigurationError`
	"""
	cmd = cc + ['-dM', '-E', '-']
	env = conf.env.env or None
	try:
		out, err = conf.cmd_and_log(cmd, output=0, input='\n'.encode(), env=env)
	except Errors.WafError:
		conf.fatal('Could not determine the compiler version %r' % cmd)

	if gcc:
		if out.find('__INTEL_COMPILER') >= 0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__') < 0 and out.find('__clang__') < 0:
			conf.fatal('Could not determine the compiler type')

	if icc and out.find('__INTEL_COMPILER') < 0:
		conf.fatal('Not icc/icpc')

	if clang and out.find('__clang__') < 0:
		conf.fatal('Not clang/clang++')
	if not clang and out.find('__clang__') >= 0:
		conf.fatal('Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure')

	k = {}
	if icc or gcc or clang:
		out = out.splitlines()
		for line in out:
			lst = shlex.split(line)
			if len(lst)>2:
				key = lst[1]
				val = lst[2]
				k[key] = val

		def isD(var):
			return var in k

		# Some documentation is available at http://predef.sourceforge.net
		# The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
		if not conf.env.DEST_OS:
			conf.env.DEST_OS = ''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS = MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__') and isD('__MACH__'):
				conf.env.DEST_OS = 'darwin'
			elif isD('__unix__'): # unix must be tested last as it's a generic fallback
				conf.env.DEST_OS = 'generic'

		if isD('__ELF__'):
			conf.env.DEST_BINFMT = 'elf'
		elif isD('__WINNT__') or isD('__CYGWIN__') or isD('_WIN32'):
			conf.env.DEST_BINFMT = 'pe'
			if not conf.env.IMPLIBDIR:
				conf.env.IMPLIBDIR = conf.env.LIBDIR # for .lib or .dll.a files
			conf.env.LIBDIR = conf.env.BINDIR
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT = 'mac-o'

		if not conf.env.DEST_BINFMT:
			# Infer the binary format from the os name.
			conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
				break

		Logs.debug('ccroot: dest platform: ' + ' '.join([conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')]))
		if icc:
			ver = k['__INTEL_COMPILER']
			conf.env.CC_VERSION = (ver[:-2], ver[-2], ver[-1])
		else:
			if isD('__clang__') and isD('__clang_major__'):
				conf.env.CC_VERSION = (k['__clang_major__'], k['__clang_minor__'], k['__clang_patchlevel__'])
			else:
				# older clang versions and gcc
				conf.env.CC_VERSION = (k['__GNUC__'], k['__GNUC_MINOR__'], k.get('__GNUC_PATCHLEVEL__', '0'))
	return k
Beispiel #24
0
def get_cc_version(conf, cc, gcc=False, icc=False):
	"""
	Run the preprocessor to determine the compiler version

	The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*
	"""
	cmd = cc + ['-dM', '-E', '-']
	try:
		p = Utils.subprocess.Popen(cmd, stdin=Utils.subprocess.PIPE, stdout=Utils.subprocess.PIPE, stderr=Utils.subprocess.PIPE)
		p.stdin.write('\n'.encode())
		out = p.communicate()[0]
	except:
		conf.fatal('could not determine the compiler version %r' % cmd)

	if not isinstance(out, str):
		out = out.decode(sys.stdout.encoding)

	if gcc:
		if out.find('__INTEL_COMPILER') >= 0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__') < 0:
			conf.fatal('Could not determine the compiler type')

	if icc and out.find('__INTEL_COMPILER') < 0:
		conf.fatal('Not icc/icpc')

	k = {}
	if icc or gcc:
		out = out.split('\n')
		import shlex

		for line in out:
			lst = shlex.split(line)
			if len(lst)>2:
				key = lst[1]
				val = lst[2]
				k[key] = val

		def isD(var):
			return var in k

		def isT(var):
			return var in k and k[var] != '0'

		# Some documentation is available at http://predef.sourceforge.net
		# The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
		if not conf.env.DEST_OS:
			conf.env.DEST_OS = ''
		for i in MACRO_TO_DESTOS:
			if isD(i):
				conf.env.DEST_OS = MACRO_TO_DESTOS[i]
				break
		else:
			if isD('__APPLE__') and isD('__MACH__'):
				conf.env.DEST_OS = 'darwin'
			elif isD('__unix__'): # unix must be tested last as it's a generic fallback
				conf.env.DEST_OS = 'generic'

		if isD('__ELF__'):
			conf.env.DEST_BINFMT = 'elf'
		elif isD('__WINNT__') or isD('__CYGWIN__'):
			conf.env.DEST_BINFMT = 'pe'
			conf.env.LIBDIR = conf.env['PREFIX'] + '/bin'
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT = 'mac-o'

		if not conf.env.DEST_BINFMT:
			# Infer the binary format from the os name.
			conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

		for i in MACRO_TO_DEST_CPU:
			if isD(i):
				conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
				break

		Logs.debug('ccroot: dest platform: ' + ' '.join([conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')]))
		if icc:
			ver = k['__INTEL_COMPILER']
			conf.env['CC_VERSION'] = (ver[:-2], ver[-2], ver[-1])
		else:
			conf.env['CC_VERSION'] = (k['__GNUC__'], k['__GNUC_MINOR__'], k['__GNUC_PATCHLEVEL__'])
	return k
Beispiel #25
0
def get_cc_version(conf, cc, gcc=False, icc=False):
	"""get the compiler version"""
	cmd = cc + ['-dM', '-E', '-']
	try:
		p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		p.stdin.write('\n'.encode())
		out = p.communicate()[0]
	except:
		conf.fatal('could not determine the compiler version %r' % cmd)

	if not isinstance(out, str):
		out = out.decode('utf-8')

	if gcc:
		if out.find('__INTEL_COMPILER') >= 0:
			conf.fatal('The intel compiler pretends to be gcc')
		if out.find('__GNUC__') < 0:
			conf.fatal('Could not determine the compiler type')

	if icc and out.find('__INTEL_COMPILER') < 0:
		conf.fatal('Not icc/icpc')

	k = {}
	if icc or gcc:
		out = out.split('\n')
		import shlex

		for line in out:
			lst = shlex.split(line)
			if len(lst)>2:
				key = lst[1]
				val = lst[2]
				k[key] = val

		def isD(var):
			return var in k

		def isT(var):
			return var in k and k[var] != '0'

		# Some documentation is available at http://predef.sourceforge.net
		# The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.
		mp1 = {
			'__linux__'   : 'linux',
			'__GNU__'     : 'gnu',
			'__FreeBSD__' : 'freebsd',
			'__NetBSD__'  : 'netbsd',
			'__OpenBSD__' : 'openbsd',
			'__sun'       : 'sunos',
			'__hpux'      : 'hpux',
			'__sgi'       : 'irix',
			'_AIX'        : 'aix',
			'__CYGWIN__'  : 'cygwin',
			'__MSYS__'    : 'msys',
			'_UWIN'       : 'uwin',
			'_WIN64'      : 'win32',
			'_WIN32'      : 'win32',
			'__POWERPC__' : 'powerpc',
			}

		for i in mp1:
			if isD(i):
				conf.env.DEST_OS = mp1[i]
				break
		else:
			if isD('__APPLE__') and isD('__MACH__'):
				conf.env.DEST_OS = 'darwin'
			elif isD('__unix__'): # unix must be tested last as it's a generic fallback
				conf.env.DEST_OS = 'generic'

		if isD('__ELF__'):
			conf.env.DEST_BINFMT = 'elf'
		elif isD('__WINNT__') or isD('__CYGWIN__'):
			conf.env.DEST_BINFMT = 'pe'
			conf.env.LIBDIR = conf.env['PREFIX'] + '/bin'
		elif isD('__APPLE__'):
			conf.env.DEST_BINFMT = 'mac-o'

		if not conf.env.DEST_BINFMT:
			# Infer the binary format from the os name.
			conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

		mp2 = {
				'__x86_64__'  : 'x86_64',
				'__i386__'    : 'x86',
				'__ia64__'    : 'ia',
				'__mips__'    : 'mips',
				'__sparc__'   : 'sparc',
				'__alpha__'   : 'alpha',
				'__arm__'     : 'arm',
				'__hppa__'    : 'hppa',
				'__powerpc__' : 'powerpc',
				}
		for i in mp2:
			if isD(i):
				conf.env.DEST_CPU = mp2[i]
				break

		Logs.debug('ccroot: dest platform: ' + ' '.join([conf.env[x] or '?' for x in ('DEST_OS', 'DEST_BINFMT', 'DEST_CPU')]))
		conf.env['CC_VERSION'] = (k['__GNUC__'], k['__GNUC_MINOR__'], k['__GNUC_PATCHLEVEL__'])
	return k
Beispiel #26
0
def get_cc_version(conf, cc, gcc=False, icc=False, clang=False):
    """
	Runs the preprocessor to determine the gcc/icc/clang version

	The variables CC_VERSION, DEST_OS, DEST_BINFMT and DEST_CPU will be set in *conf.env*

	:raise: :py:class:`waflib.Errors.ConfigurationError`
	"""
    cmd = cc + ["-dM", "-E", "-"]
    env = conf.env.env or None
    try:
        out, err = conf.cmd_and_log(cmd, output=0, input="\n".encode(), env=env)
    except Exception:
        conf.fatal("Could not determine the compiler version %r" % cmd)

    if gcc:
        if out.find("__INTEL_COMPILER") >= 0:
            conf.fatal("The intel compiler pretends to be gcc")
        if out.find("__GNUC__") < 0 and out.find("__clang__") < 0:
            conf.fatal("Could not determine the compiler type")

    if icc and out.find("__INTEL_COMPILER") < 0:
        conf.fatal("Not icc/icpc")

    if clang and out.find("__clang__") < 0:
        conf.fatal("Not clang/clang++")
    if not clang and out.find("__clang__") >= 0:
        conf.fatal("Could not find gcc/g++ (only Clang), if renamed try eg: CC=gcc48 CXX=g++48 waf configure")

    k = {}
    if icc or gcc or clang:
        out = out.splitlines()
        for line in out:
            lst = shlex.split(line)
            if len(lst) > 2:
                key = lst[1]
                val = lst[2]
                k[key] = val

        def isD(var):
            return var in k

            # Some documentation is available at http://predef.sourceforge.net
            # The names given to DEST_OS must match what Utils.unversioned_sys_platform() returns.

        if not conf.env.DEST_OS:
            conf.env.DEST_OS = ""
        for i in MACRO_TO_DESTOS:
            if isD(i):
                conf.env.DEST_OS = MACRO_TO_DESTOS[i]
                break
        else:
            if isD("__APPLE__") and isD("__MACH__"):
                conf.env.DEST_OS = "darwin"
            elif isD("__unix__"):  # unix must be tested last as it's a generic fallback
                conf.env.DEST_OS = "generic"

        if isD("__ELF__"):
            conf.env.DEST_BINFMT = "elf"
        elif isD("__WINNT__") or isD("__CYGWIN__") or isD("_WIN32"):
            conf.env.DEST_BINFMT = "pe"
            conf.env.LIBDIR = conf.env.BINDIR
        elif isD("__APPLE__"):
            conf.env.DEST_BINFMT = "mac-o"

        if not conf.env.DEST_BINFMT:
            # Infer the binary format from the os name.
            conf.env.DEST_BINFMT = Utils.destos_to_binfmt(conf.env.DEST_OS)

        for i in MACRO_TO_DEST_CPU:
            if isD(i):
                conf.env.DEST_CPU = MACRO_TO_DEST_CPU[i]
                break

        Logs.debug(
            "ccroot: dest platform: " + " ".join([conf.env[x] or "?" for x in ("DEST_OS", "DEST_BINFMT", "DEST_CPU")])
        )
        if icc:
            ver = k["__INTEL_COMPILER"]
            conf.env.CC_VERSION = (ver[:-2], ver[-2], ver[-1])
        else:
            if isD("__clang__") and isD("__clang_major__"):
                conf.env.CC_VERSION = (k["__clang_major__"], k["__clang_minor__"], k["__clang_patchlevel__"])
            else:
                # older clang versions and gcc
                conf.env.CC_VERSION = (k["__GNUC__"], k["__GNUC_MINOR__"], k.get("__GNUC_PATCHLEVEL__", "0"))
    return k