目标下的makefile变量分配 [英] makefile variable assignment under a target

查看:96
本文介绍了目标下的makefile变量分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was running the following commands in a target in my 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中,以便我可以在将在此目标中接下来执行的命令中使用该值.

My task is to get the first line in "ids.log" and keep it in a variable id1, so that I can use the value in the command I will execute next in this target.

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

I get an error running this command "cat: ids.log: No such file or directory". Looks like $(eval .. ) command is executed at the beginning of make rather than as part of the target make. And since the ids.log is not created until the target make is done, we get this error.

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

Can anyone help in how to get the value of the shell command I execute and put it in a variable for use on demand?

推荐答案

有一个单独的目标,该目标首先使ids.log成为目标,然后将其作为对target的依赖.

Have a separate target that makes ids.log first then have that as a dependency to target.

例如:

ids.log:
    echo 1 > ids.log

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

这篇关于目标下的makefile变量分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆