我需要有条件地执行一些make规则,只有当安装的Python大于某个版本(比如2.5)。
我想我可以做一些类似执行的事情:
python -c 'import sys; print int(sys.version_info >= (2,5))'
然后在ifeq make语句中使用输出(ok时为'1',否则为'0')。
在一个简单的bash shell脚本中,它只是:
MY_VAR=`python -c 'import sys; print int(sys.version_info >= (2,5))'`
但这在Makefile中不起作用。
有什么建议吗?我可以使用任何其他明智的解决办法来实现这一点。
With GNU Make, you can use shell and eval to store, run, and assign output from arbitrary command line invocations. The difference between the example below and those which use := is the := assignment happens once (when it is encountered) and for all. Recursively expanded variables set with = are a bit more "lazy"; references to other variables remain until the variable itself is referenced, and the subsequent recursive expansion takes place each time the variable is referenced, which is desirable for making "consistent, callable, snippets". See the manual on setting variables for more info.
# Generate a random number.
# This is not run initially.
GENERATE_ID = $(shell od -vAn -N2 -tu2 < /dev/urandom)
# Generate a random number, and assign it to MY_ID
# This is not run initially.
SET_ID = $(eval MY_ID=$(GENERATE_ID))
# You can use .PHONY to tell make that we aren't building a target output file
.PHONY: mytarget
mytarget:
# This is empty when we begin
@echo $(MY_ID)
# This recursively expands SET_ID, which calls the shell command and sets MY_ID
$(SET_ID)
# This will now be a random number
@echo $(MY_ID)
# Recursively expand SET_ID again, which calls the shell command (again) and sets MY_ID (again)
$(SET_ID)
# This will now be a different random number
@echo $(MY_ID)