如何将命令的输出分配给Makefile变量 [英] How to assign the output of a command to a Makefile variable
本文介绍了如何将命令的输出分配给Makefile变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅当安装的Python大于某个版本(例如2.5)时,我才需要有条件地执行一些make规则.
I need to execute some make rules conditionally, only if the Python installed is greater than a certain version (say 2.5).
我认为我可以做一些类似的事情:
I thought I could do something like executing:
python -c 'import sys; print int(sys.version_info >= (2,5))'
,然后在ifeq
make语句中使用输出(如果可以,则为'1',否则为'0').
and then using the output ('1' if ok, '0' otherwise) in a ifeq
make statement.
在一个简单的bash shell脚本中,它只是:
In a simple bash shell script it's just:
MY_VAR=`python -c 'import sys; print int(sys.version_info >= (2,5))'`
但是在Makefile中不起作用.
but that doesn't work in a Makefile.
有什么建议吗?我可以使用任何其他明智的解决方法来实现这一目标.
Any suggestions? I could use any other sensible workaround to achieve this.
推荐答案
像在MY_VAR=$(shell echo whatever)
me@Zack:~$make
MY_VAR IS whatever
me@Zack:~$ cat Makefile
MY_VAR := $(shell echo whatever)
all:
@echo MY_VAR IS $(MY_VAR)
这篇关于如何将命令的输出分配给Makefile变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文