Variables 目标下的makefile变量赋值

Variables 目标下的makefile变量赋值,variables,makefile,eval,Variables,Makefile,Eval,我在Makefile中的目标中运行以下命令 target1: <run some command which creates ids.log> $(eval id1 := $(shell cat ids.log | head -1)) @echo id is $(id1) <some other command which uses the value $(id1)> target1: $(评估id1:=$

我在Makefile中的目标中运行以下命令

target1:
        <run some command which creates ids.log>
        $(eval id1 := $(shell cat ids.log | head -1))
        @echo id is $(id1)
        <some other command which uses the value $(id1)>
target1:
$(评估id1:=$(shell cat id.log | head-1))
@回显id为$(id1)
我的任务是获取“ids.log”中的第一行,并将其保存在变量id1中,这样我就可以使用我将在此目标中执行的下一个命令中的值

我在运行这个命令“cat:ids.log:没有这样的文件或目录”时出错。看起来$(eval..)命令是在make开始时执行的,而不是作为目标make的一部分执行的。由于ids.log是在完成目标make之后才创建的,因此我们得到了这个错误


有谁能帮助我获取我执行的shell命令的值,并将其放入一个变量中,以便按需使用吗?

有一个单独的目标,首先生成
id.log
,然后将其作为
目标的依赖项

例如:

ids.log:
    echo 1 > ids.log

target: ids.log
    $(eval id1 := $(shell cat ids.log | head -1))
    @echo id is $(id1)

非常感谢,西蒙。它起作用了。有没有一种方法可以在不添加依赖项的情况下做到这一点?我想在后续命令中使用
$(id1)
的地方用backticks中的
cat ids.log | head-1
替换掉,但我认为我在答案中给出的解决方案更干净。@SimonGibbons Hi,谢谢你的回答。我用
echo$(shell whoami)>whoami.log尝试了它,但没有成功。知道如何从命令中获取目标值吗?