如果语句不正确,我试图获取 ifdef 语句上的退出代码,但我尝试使用 exit 1 和 $(call exit 1)
在以下代码中使用第一个时,我得到“Makefile:11:*缺少分隔符。停止。”
...
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
将为 true,
即使它被定义为空字符串。您可能更喜欢:
ifneq ($(PACKAGE),)
PACKAGEDIR = $(HOME)/$(PACKAGE)
else
$(error You must define the PACKAGE variable)
endif
确保变量设置为非空值。
并且,您的 GNU make 版本可能太旧,无法支持
$(error ...)
功能,尽管它已经存在很长时间了。
@exit 1
。一个例子:
ifdef PACKAGE
PACKAGEDIR = $(HOME)/$(PACKAGE)
else
@exit 1
endif