Can I make a makefile abort outside of a rule?

非 Y 不嫁゛ 提交于 2019-12-06 04:45:15

exit is a shell command, so you could use the shell assignment operator (i.e.: !=) inside the Makefile to call exit:

TARGET != exit -1

This would be actually equivalent to:

TARGET := $(shell exit -1)

Note again that this calls a shell that in turns runs the shell's exit built-in, i.e.: it does not exit make. The typical approach for exiting while processing a makefile is to call GNU Make's error built-in function instead:

$(error Error-message-here)

Putting everything together:

ifeq ($(ENVIRONMENT),LOCAL)
 TARGET := local_target
else # indent with spaces, not a tab
 $(error ENVIRONMENT not set to LOCAL)
endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!