我想使用$(error ...)
来在特定前提条件不满足时终止我的make过程。当test -d /foobar
失败时,fails_to_work
目标应该中止。
BAD.mk
all: this_works fails_to_work
this_works:
@echo echo works...
@test -d ~ || echo ~ is not a directory
@test -d /foobar || echo /foobar is not a directory
fails_to_work:
@echo error does not work...
@test -d ~ || $(error ~ is not a directory)
@test -d /foobar || $(error /foobar is not a directory)
$ make -f BAD.mk
转译为中文后为:$ make -f BAD.mk
。echo works...
/foobar is not a directory
BAD.mk:9: *** ~ is not a directory. Stop.
正如您所看到的,甚至连“error does not work…”也没有被输出到屏幕上。 fails_to_work
的解决方案在开始之前就失败了。我该怎么解决?我的一个用例是@test -d $(MY_ENV_VAR)
,但我不认为这与示例中给出的硬编码路径有什么区别。
更新(版本信息)
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
if ! test -d /foobar ; then echo "/foobar is not a directory"; exit 1; fi
),但是您的第二个建议无效。即使有一个有效的目录,错误仍然会出现。 - Chris Betti