目标下的makefile变量赋值

Nav*_*uni 4 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)>
Run Code Online (Sandbox Code Playgroud)

我的任务是获取"ids.log"中的第一行并将其保存在变量id1中,这样我就可以使用我将在此目标中执行的命令中的值.

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

任何人都可以帮助我如何获取我执行的shell命令的值并将其放入变量以供按需使用?

Sim*_*ons 5

ids.log首先制作一个单独的目标,然后将其作为依赖项target.

例如:

ids.log:
    echo 1 > ids.log

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