我有一个 makefile,当使用旧版本的 gmake 时,它会出现不明显的故障。我想有一个规则来检查版本至少是 3.82 或更高版本。我已经得到了以下规则,但比较是脆弱的,我真的想要一个允许更高版本的比较:
GMAKE_VERSION := $(shell gmake --version | head -n 1 | sed 's/GNU Make //')
.PHONY: testMake
testMake:
@if [ "$(GMAKE_VERSION)" != "3.82" ]; \
then \
echo >&2 "Unexpected gmakefile version " \
"$(GMAKE_VERSION), expecting 3.82 or later."; \
false; \
fi
Run Code Online (Sandbox Code Playgroud)
什么GNU makefile规则可以保证make的版本至少是v3.82?
这是我将如何实现它:
# Check Make version (we need at least GNU Make 3.82). Fortunately,
# 'undefine' directive has been introduced exactly in GNU Make 3.82.
ifeq ($(filter undefine,$(value .FEATURES)),)
$(error Unsupported Make version. \
The build system does not work properly with GNU Make $(MAKE_VERSION), \
please use GNU Make 3.82 or above.)
endif
Run Code Online (Sandbox Code Playgroud)
该检查基于测试.FEATURES内置变量。来自 GNU Make 3.82新闻文件:
新的 make 指令:
undefine允许您取消定义变量,使其看起来好像从未设置过。这两个$(flavor)和$(origin)函数将返回“未定义”对于这样的变量。要检测此功能,请undefine在.FEATURES特殊变量中搜索。