waf如何使用多版本tricore-gcc.exe编译器
How to use multiple version of tricore-gcc.exe compilers with waf
我想对 windows OS
中的不同项目使用不同的 tricore-gcc.exe
这两个 tricore-gcc.exe
在以下路径中,但不在 PATH 中:
C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe
C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe
我的问题是如何在waf中配置它?
compiler_c
是否只搜索msvc
、gcc
和clang
?
感谢任何建议!
(我在 Whosebug 中搜索过,例如 但我没有找到关于如何在 Windows 中设置绝对路径的答案)
我的wscript
:
def options(opt):
print("start opt ------------------")
opt.load('compiler_c')
def configure(conf):
# here we are in default variant/env
# we load the default compiler, probably gcc
conf.load('compiler_c')
# config for tricore 4.6.3 variant
print("start ------------------")
conf.setenv('t463')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# config for tricore 4.9.2 variant
print("start ------------------")
conf.setenv('t492')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# back to default config
conf.setenv('')
def build(bld):
bld.program(source = 'main.c', target = 'myexe')
# this create variants commands and build directories
from waflib.Build import (
BuildContext,
CleanContext,
InstallContext,
UninstallContext,
)
for variant in ['t463', 't492']:
for context in [BuildContext, CleanContext, InstallContext, UninstallContext]:
name = context.__name__.replace('Context','').lower()
class tmp(context):
cmd = name + '_' + variant
variant = variant
我测试了一下,得到结果:
D:\CX_waf\test1>python waf configure
start opt ------------------
Setting top to : D:\CX_waf\test1
Setting out to : D:\CX_waf\test1\build
Checking for 'msvc' (C compiler) : not found
Checking for 'gcc' (C compiler) : not found
Checking for 'clang' (C compiler) : not found
could not configure a C compiler!
(complete log in D:\CX_waf\test1\build\config.log)
config.log
:
# project configured on Tue Dec 29 14:42:29 2020 by
# waf 2.0.21 (abi 20, python 30803f0 on win32)
# using waf configure
#
----------------------------------------
Setting top to D:\CX_waf\test1
----------------------------------------
Setting out to D:\CX_waf\test1\build
----------------------------------------
Checking for 'msvc' (C compiler)
['C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe', '-products', '*', '-legacy', '-format', 'json']
from D:\CX_waf\test1: msvc: Impossible to find a valid architecture for building [] - []
not found
----------------------------------------
Checking for 'gcc' (C compiler)
find program=['gcc', 'cc'] paths=['C:\Testwell\CTC', 'C:\Java\j2sdk1.4.2_11\bin', 'C:\Windows\system32', 'C:\Windows', 'C:\Windows\System32\Wbem', 'C:\Windows\System32\WindowsPowerShell\v1.0\', 'C:\Program Files\Intel\WiFi\bin\', 'C:\Program Files\Common Files\Intel\WirelessCommon\', 'C:\Program Files (x86)\Common Files\ETAS\3rdParty1.0', 'C:\Program Files (x86)\Toolbase Client', 'C:\Users\xia.chen\AppData\Local\Programs\Microsoft VS Code\bin', 'C:\Users\xia.chen\AppData\Local\Programs\Git\cmd', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin', 'D:\tools\Python38', 'D:\tools\Python38\Scripts', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin'] var='CC' -> None
from D:\CX_waf\test1: Could not find the program ['gcc', 'cc']
not found
----------------------------------------
Checking for 'clang' (C compiler)
find program=['clang'] paths=['C:\Testwell\CTC', 'C:\Java\j2sdk1.4.2_11\bin', 'C:\Windows\system32', 'C:\Windows', 'C:\Windows\System32\Wbem', 'C:\Windows\System32\WindowsPowerShell\v1.0\', 'C:\Program Files\Intel\WiFi\bin\', 'C:\Program Files\Common Files\Intel\WirelessCommon\', 'C:\Program Files (x86)\Common Files\ETAS\3rdParty1.0', 'C:\Program Files (x86)\Toolbase Client', 'C:\Users\xia.chen\AppData\Local\Programs\Microsoft VS Code\bin', 'C:\Users\xia.chen\AppData\Local\Programs\Git\cmd', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin', 'D:\tools\Python38', 'D:\tools\Python38\Scripts', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin'] var='CC' -> None
from D:\CX_waf\test1: Could not find the program ['clang']
not found
from D:\CX_waf\test1: could not configure a C compiler!
是的,waf 只检测 compiler_c 中定义的受支持的编译器。
如果你的编译器是“兼容的”,因为 clang 与 gcc 兼容(即它的命令行工作相同)那么你只需要定义 CC
:
from waflib import Logs
# this is to check only for gcc-like compiler, on win32, compiler_c begins with msvc
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['gcc']
def options(opt):
opt.load('compiler_c')
def configure(conf):
conf.setenv('t463')
conf.env.CC = ['c:/toolchains/tricore/v4.6.3.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
conf.setenv('t492')
conf.env.CC = ['c:/toolchains/tricore/v4.9.2.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
def build(bld):
Logs.info("Using compiler {}".format(bld.env.CC))
bld.program(source = 'main.c', target = 'myexe')
注意:我在 Linux 上测试过,没有可用的 win32 机器:)
要检测新的“不兼容”编译器,您必须执行以下操作:
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['tricore', 'msvc', 'gcc']
def options(opt):
opt.load('compiler_c')
def configure(cnf):
cnf.load('compiler_c')
def build(bld):
bld.program(source='main.c', target='myexe')
并定义一个tricore
工具来检测编译器:
# from waflib/Tools/clang.py
from waflib.Tools import ccroot, ar, gcc
from waflib.Configure import conf
@conf
def find_tricore(conf):
cc = conf.find_program('tricore', var='CC')
conf.get_cc_version(cc)
conf.env.CC_NAME = 'tricore'
def configure(conf):
conf.find_tricore()
conf.find_ar()
conf.gcc_common_flags()
conf.gcc_modifier_platform()
conf.cc_load_tools()
conf.cc_add_flags()
conf.link_add_flags()
您可以查看 gcc.py
、clang.py
、suncc.py
或 icc.py
以获得像 gcc
这样的编译器。查看 msvc.py
以了解与 gcc
真正不同的编译器。
我想对 windows OS
中的不同项目使用不同的tricore-gcc.exe
这两个 tricore-gcc.exe
在以下路径中,但不在 PATH 中:
C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe
C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe
我的问题是如何在waf中配置它?
compiler_c
是否只搜索msvc
、gcc
和clang
?
感谢任何建议!
(我在 Whosebug 中搜索过,例如
我的wscript
:
def options(opt):
print("start opt ------------------")
opt.load('compiler_c')
def configure(conf):
# here we are in default variant/env
# we load the default compiler, probably gcc
conf.load('compiler_c')
# config for tricore 4.6.3 variant
print("start ------------------")
conf.setenv('t463')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.6.3.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# config for tricore 4.9.2 variant
print("start ------------------")
conf.setenv('t492')
conf.env.CC = ['C:\HighTec\toolchains\tricore\v4.9.2.0\bin\tricore-gcc.exe']
conf.load('compiler_c')
# back to default config
conf.setenv('')
def build(bld):
bld.program(source = 'main.c', target = 'myexe')
# this create variants commands and build directories
from waflib.Build import (
BuildContext,
CleanContext,
InstallContext,
UninstallContext,
)
for variant in ['t463', 't492']:
for context in [BuildContext, CleanContext, InstallContext, UninstallContext]:
name = context.__name__.replace('Context','').lower()
class tmp(context):
cmd = name + '_' + variant
variant = variant
我测试了一下,得到结果:
D:\CX_waf\test1>python waf configure
start opt ------------------
Setting top to : D:\CX_waf\test1
Setting out to : D:\CX_waf\test1\build
Checking for 'msvc' (C compiler) : not found
Checking for 'gcc' (C compiler) : not found
Checking for 'clang' (C compiler) : not found
could not configure a C compiler!
(complete log in D:\CX_waf\test1\build\config.log)
config.log
:
# project configured on Tue Dec 29 14:42:29 2020 by
# waf 2.0.21 (abi 20, python 30803f0 on win32)
# using waf configure
#
----------------------------------------
Setting top to D:\CX_waf\test1
----------------------------------------
Setting out to D:\CX_waf\test1\build
----------------------------------------
Checking for 'msvc' (C compiler)
['C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe', '-products', '*', '-legacy', '-format', 'json']
from D:\CX_waf\test1: msvc: Impossible to find a valid architecture for building [] - []
not found
----------------------------------------
Checking for 'gcc' (C compiler)
find program=['gcc', 'cc'] paths=['C:\Testwell\CTC', 'C:\Java\j2sdk1.4.2_11\bin', 'C:\Windows\system32', 'C:\Windows', 'C:\Windows\System32\Wbem', 'C:\Windows\System32\WindowsPowerShell\v1.0\', 'C:\Program Files\Intel\WiFi\bin\', 'C:\Program Files\Common Files\Intel\WirelessCommon\', 'C:\Program Files (x86)\Common Files\ETAS\3rdParty1.0', 'C:\Program Files (x86)\Toolbase Client', 'C:\Users\xia.chen\AppData\Local\Programs\Microsoft VS Code\bin', 'C:\Users\xia.chen\AppData\Local\Programs\Git\cmd', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin', 'D:\tools\Python38', 'D:\tools\Python38\Scripts', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin'] var='CC' -> None
from D:\CX_waf\test1: Could not find the program ['gcc', 'cc']
not found
----------------------------------------
Checking for 'clang' (C compiler)
find program=['clang'] paths=['C:\Testwell\CTC', 'C:\Java\j2sdk1.4.2_11\bin', 'C:\Windows\system32', 'C:\Windows', 'C:\Windows\System32\Wbem', 'C:\Windows\System32\WindowsPowerShell\v1.0\', 'C:\Program Files\Intel\WiFi\bin\', 'C:\Program Files\Common Files\Intel\WirelessCommon\', 'C:\Program Files (x86)\Common Files\ETAS\3rdParty1.0', 'C:\Program Files (x86)\Toolbase Client', 'C:\Users\xia.chen\AppData\Local\Programs\Microsoft VS Code\bin', 'C:\Users\xia.chen\AppData\Local\Programs\Git\cmd', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin', 'D:\tools\Python38', 'D:\tools\Python38\Scripts', 'C:\HighTec\toolchains\tricore\v4.9.2.0\bin'] var='CC' -> None
from D:\CX_waf\test1: Could not find the program ['clang']
not found
from D:\CX_waf\test1: could not configure a C compiler!
是的,waf 只检测 compiler_c 中定义的受支持的编译器。
如果你的编译器是“兼容的”,因为 clang 与 gcc 兼容(即它的命令行工作相同)那么你只需要定义 CC
:
from waflib import Logs
# this is to check only for gcc-like compiler, on win32, compiler_c begins with msvc
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['gcc']
def options(opt):
opt.load('compiler_c')
def configure(conf):
conf.setenv('t463')
conf.env.CC = ['c:/toolchains/tricore/v4.6.3.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
conf.setenv('t492')
conf.env.CC = ['c:/toolchains/tricore/v4.9.2.0/bin/tricore-gcc.exe']
conf.load('compiler_c')
def build(bld):
Logs.info("Using compiler {}".format(bld.env.CC))
bld.program(source = 'main.c', target = 'myexe')
注意:我在 Linux 上测试过,没有可用的 win32 机器:)
要检测新的“不兼容”编译器,您必须执行以下操作:
from waflib.Tools.compiler_c import c_compiler
c_compiler['win32'] = ['tricore', 'msvc', 'gcc']
def options(opt):
opt.load('compiler_c')
def configure(cnf):
cnf.load('compiler_c')
def build(bld):
bld.program(source='main.c', target='myexe')
并定义一个tricore
工具来检测编译器:
# from waflib/Tools/clang.py
from waflib.Tools import ccroot, ar, gcc
from waflib.Configure import conf
@conf
def find_tricore(conf):
cc = conf.find_program('tricore', var='CC')
conf.get_cc_version(cc)
conf.env.CC_NAME = 'tricore'
def configure(conf):
conf.find_tricore()
conf.find_ar()
conf.gcc_common_flags()
conf.gcc_modifier_platform()
conf.cc_load_tools()
conf.cc_add_flags()
conf.link_add_flags()
您可以查看 gcc.py
、clang.py
、suncc.py
或 icc.py
以获得像 gcc
这样的编译器。查看 msvc.py
以了解与 gcc
真正不同的编译器。