Gnu make:在命令中为某些目标添加一个标志
Gnu make: Add a flag in a command for certain targets
我有以下 make
脚本(摘录):
debug/abc-%.txt:
python buildtxt.py --firstFlag <second flag>
如果 %
为 debug
,则 <second flag>
应为 --debug
,否则为空(即无标志)。这种行为可以简单地在 buildtxt.py
中实现,但我认为这样做更模块化。
我怎样才能轻松实现它?
你想要$(if $(filter debug,$*),--debug)
.
$*
扩展为匹配 %
的字符串。没有 built-in 函数来比较字符串是否相等,因此我们使用 filter
来比较。
我有以下 make
脚本(摘录):
debug/abc-%.txt:
python buildtxt.py --firstFlag <second flag>
如果 %
为 debug
,则 <second flag>
应为 --debug
,否则为空(即无标志)。这种行为可以简单地在 buildtxt.py
中实现,但我认为这样做更模块化。
我怎样才能轻松实现它?
你想要$(if $(filter debug,$*),--debug)
.
$*
扩展为匹配 %
的字符串。没有 built-in 函数来比较字符串是否相等,因此我们使用 filter
来比较。