目标下的 makefile 变量赋值

2024-01-14

我在 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)>

我的任务是获取“ids.log”中的第一行并将其保存在变量 id1 中,以便我可以使用接下来要在此目标中执行的命令中的值。

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

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


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

例如:

ids.log:
    echo 1 > ids.log

target: ids.log
    $(eval id1 := $(shell cat ids.log | head -1))
    @echo id is $(id1)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

目标下的 makefile 变量赋值 的相关文章