立即在配方中进行变量扩展 [英] Immediate variable expansion in recipe
本文介绍了立即在配方中进行变量扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个构建系统,我需要在目标配方中立即进行变量扩展.
I'm making a build system and I need immediate variable expansion in a recipe of a target.
我的(简化的)makefile:
My (simplified) makefile:
VAR=one
all:
@echo one is $(VAR)
VAR=two
当我运行make
时,输出为:
one is two
期望输出(配方中的延迟扩展),但不期望.
The output is expected (deferred expansion in recipe) but not desired.
使其工作的一种方法是跟随makefile.但是,这会使配方始终执行,这也是不希望的:
One way to make it work is following makefile. However, this makes the recipe to be executed always, also not desired:
VAR=one
all: $(VAR)
@echo one is $(VAR)
$(VAR):
$(eval VAR=$@)
VAR=two
有人吗?
推荐答案
您可以使用类似的东西来获取所需的东西.它使用特定于目标的变量值来在分析时捕获变量时间.
You can use something like this to get what you want. It uses target-specific variable values to capture the variable at parse-time.
$ cat Makefile
VAR=one
all: tgtone tgttwo
tgtone: VAR:=$(VAR)
tgtone:
@echo $@: VAR is $(VAR)
tgttwo:
@echo $@: VAR is $(VAR)
VAR=two
$ make
tgtone: VAR is one
tgttwo: VAR is two
这篇关于立即在配方中进行变量扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文