【发布时间】:2018-08-16 00:25:50
【问题描述】:
我是构建 Makefile 的新手,我正在尝试确定如果变量为空,构建目标将如何失败。我希望能够将变量作为环境变量或作为 make 参数传递。
假设我有一个这样的 makefile:
VER ?=
step0:
echo "step0 should work"
step1:
echo "step1 should enforce variable"
ifeq($(VER), "")
$(error VER is not set)
endif
echo "Success: Value of Ver ${VER}"
step2:
echo "step2 should work"
我希望能够运行以下测试用例:
VER="foo" make step1
# should result in printing the "Success:" line
或
export VER=foo
make step1
# should result in printing the "Success:" line
或
make step1 VER=foo
# should result in printing the "Success:" line
或
make step1
# should result in printing "VER is not set"
但是,当我使用上述任何方法运行 make step 时,我总是会收到 VER is not set 错误。
简而言之,我如何测试特定 make 目标中的变量并在未设置时以错误消息响应? (但其他 make 目标不会关心变量是否设置)
【问题讨论】:
标签: bash makefile build scripting gnu-make