如果不满足某些先决条件,我该如何终止我的构建?

时间:2014-08-15 12:56:50

标签: makefile gnu-make

我想在我的GNU makefile中执行以下操作:

ifndef TOP
  abort Error TOP not defined
endif

如果没有定义所有必需的变量,是否可以通过简单的消息终止终端?

1 个答案:

答案 0 :(得分:2)

$(error Error TOP not defined)

来自http://www.gnu.org/software/make/manual/make.html#Make-Control-Functions

$(error text...)
Generates a fatal error where the message is text. Note that the error is generated whenever this function is evaluated. So, if you put it inside a recipe or on the right side of a recursive variable assignment, it won't be evaluated until later. The text will be expanded before the error is generated.
For example,

          ifdef ERROR1
          $(error error is $(ERROR1))
          endif
will generate a fatal error during the read of the makefile if the make variable ERROR1 is defined. Or,

          ERR = $(error found an error!)

          .PHONY: err
          err: ; $(ERR)
will generate a fatal error while make is running, if the err target is invoked.