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



我想在我的GNU makefile中做以下事情:

ifndef TOP
  abort Error TOP not defined
endif

如果没有定义所有必需的变量,是否有一种方法可以用一个简单的消息终止到终端?

$(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. 

最新更新