根据两个 shell 变量的状态退出 Makefile
在 make checksource
期间,$CROSS_COMPILE
应为 "whatever"
。如果 $CROSS_COMPILE
未设置,make
应该抛出错误并退出。
我的 Makefile
中有以下规则:
.PHONY: checksource
all: checksource default
checksource:
$(if $(and $(ifeq ($(CROSS_COMPILE), whatever)), $(ifeq ($(VARIABLE),))), \
($(shell echo "Error! VARIABLE not defined!") \
$(shell exit 2)))
现在,如果 $CROSS_COMPILE
设置为任意值并且 $VARIABLE
未定义,则 make
不退出。
$CROSS_COMPILE
:
$> echo $CROSS_COMPILE
whatever
$>
$VARIABLE
未定义:
$> echo $VARIABLE
$>
我可以使用嵌套的ifeq
,但我想让它变得漂亮(并了解更多信息)关于 Makefile
操作)。
During make checksource
, $CROSS_COMPILE
should be "whatever"
. If $CROSS_COMPILE
is not set, make
should throw an error and exit.
I have the following rule in my Makefile
:
.PHONY: checksource
all: checksource default
checksource:
$(if $(and $(ifeq ($(CROSS_COMPILE), whatever)), $(ifeq ($(VARIABLE),))), \
($(shell echo "Error! VARIABLE not defined!") \
$(shell exit 2)))
Right now if $CROSS_COMPILE
is set to whatever and $VARIABLE
is undefined, the make
doesn't exit.
$CROSS_COMPILE
:
gt; echo $CROSS_COMPILE
whatever
gt;
$VARIABLE
is not defined:
gt; echo $VARIABLE
gt;
I could use a nested ifeq
, but I want to make it pretty (and learn a bit more about Makefile
operations).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不存在
$(ifeq)
这样的东西。我仍然认为你应该在 makefile 本身中进行检查,而不是作为目标之一:如果你决定避免嵌套
ifeq
:但我看不出这是一个改进。如果您想在目标中执行此操作,只需使用 shell,而不必担心 make 函数:
我仍然会选择第一个选项,因为您可以在
stat
全部完成之前停止 make检查Makefile
中的文件名并决定开始执行checksource
。There is no such thing as
$(ifeq)
. I still think you should do the check in the makefile itself, not as one of the targets:And if you're set on avoiding nested
ifeq
:But I fail to see how that's an improvement. If you want to do it in a target, just use the shell and don't bother with make functions:
I'd still go with the first option, because you can stop make before it
stat
s all the files names inMakefile
and decides to start executingchecksource
.在 make 中执行此操作始终比使用 shell 更好(无论是通过 $(shell) 还是配方)。如果您确实在配方中进行了检查,则意味着 Makefile 可以包含不需要此特定断言的其他目标。
PS 如果您使用
--warn-undefined-variables
运行原始 make,您可能已经知道为什么宏无法正确扩展:Doing it in make is always better than using the shell (whether via
$(shell)
or a recipe). If you do do the check in a recipe, then it means that the Makefile can contain other targets that do not need this particular assert.P.S. If you ran your original make with
--warn-undefined-variables
you may have got some clue why your macros were not expanding properly: