makefile ifeq比较了外壳的输出
我正在尝试比较Makefile评估价值的输出(GNU Make)。但是,即使回声值为0
,ifeq
块也不认为它是相等的,如果我只是将0
作为比较器。
但是,如果我将以下内容作为比较器$(Shell Echo 0)
,则ifeq
将接受它作为同等值。
需要明确的是,以下是我将要实现的“模拟”(请记住$(eval Zero_value:= $(Shell Echo 0))
只是一个“模型”,命令替换$(shell echo 0))
在某个时候将输出0
。
zero-test:
$(eval ZERO_VALUE := $(shell echo 0))
echo "Echo-ed value: ${ZERO_VALUE}"
ifeq ($(ZERO_VALUE),$(shel echo 0))
echo "1st approach Value is zero"
else
echo "1st approach Value is not zero"
endif
ifeq ($(ZERO_VALUE),0)
echo "2nd approach Value is zero"
else
echo "2nd approach Value is not zero"
endif
进行进行零测试时的输出
是:
Echo-ed value: 0
1st approach Value is zero
2nd approach Value is not zero
最后,我的主要问题是:
- 为什么当“回声”值实际上是
0
时,被认为是平等的吗? - 有可能让我的第二种方法工作吗?只需对此感到更自然:)
此外,以下是我的make -v
输出:
❯ make -v
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
I am trying to compare output from evaluated value on a Makefile ( GNU make ). However, even when the echo-ed value is 0
, the ifeq
block not consider it is equal if I just put 0
as the comparator.
But if I put following as a comparator $(shell echo 0)
, then ifeq
will accept it as an equal value.
To be clear, following is a "mock" what I am going to achieve ( keep in mind that $(eval ZERO_VALUE := $(shell echo 0))
is just a "mockup", there will a command replacing $(shell echo 0))
there, which will output 0
at some point.
zero-test:
$(eval ZERO_VALUE := $(shell echo 0))
echo "Echo-ed value: ${ZERO_VALUE}"
ifeq ($(ZERO_VALUE),$(shel echo 0))
echo "1st approach Value is zero"
else
echo "1st approach Value is not zero"
endif
ifeq ($(ZERO_VALUE),0)
echo "2nd approach Value is zero"
else
echo "2nd approach Value is not zero"
endif
The output when doing make zero-test
would be:
Echo-ed value: 0
1st approach Value is zero
2nd approach Value is not zero
Finally, my main questions are:
- Why
($(ZERO_VALUE),0)
is not considered equal while the "echo-ed" value is actually0
? - Is it possible to have my 2nd approach work? Just feel more natural with that :)
In addition, following is my make -v
output:
❯ make -v
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到了几个问题:
尝试解决上述问题:
如果您必须在食谱中传达零value,则应考虑使用oneshell或使用文件代替变量,因为它们持续在子壳调用中。
I see several problems:
Attempts to fix above problems:
If you must communicate ZERO_VALUE within the recipe you should consider either using ONESHELL, or use files instead of variables since they persist across subshell invocations.