如果 ifdef 语句不正确,我会尝试获取退出代码,但我尝试使用 exit 1 和 $(call exit 1)
在以下代码中使用第一个时,我得到“Makefile:11: * missing separator. Stop.”
...
ifdef PACKAGE
PACKAGEDIR = $(HOME)/$(PACKAGE)
else
exit 1
endif
...
通过使用 $(call exit 1)
我没有收到错误,但 makefile 仍然继续执行。
我想要完成的是在 else 上退出 Makefile,错误代码为 1
谢谢
最佳答案
正如 geekosaur 所说,您不能将像 exit 1
这样的 shell 命令作为 makefile 操作。 Makefile 不是 shell 脚本,尽管它们可以包含 shell 脚本。 Shell 命令只能出现在目标配方中,不能出现在其他任何地方。
如果你有足够新的 GNU make 版本,你可以使用 $(error ...)
函数,像这样:
ifdef PACKAGE
PACKAGEDIR = $(HOME)/$(PACKAGE)
else
$(error You must define the PACKAGE variable)
endif
另外请注意,如果变量被定义,ifdef
将为真,即使它被定义为空字符串。您可能更喜欢:
ifneq ($(PACKAGE),)
PACKAGEDIR = $(HOME)/$(PACKAGE)
else
$(error You must define the PACKAGE variable)
endif
确保变量设置为非空值。
而且,您的 GNU make 版本可能太旧,无法支持 $(error ...)
功能,尽管它已经存在了很长时间。
关于makefile - 在 Makefile if 语句中获取退出代码 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292132/