我有一个项目,其Makefile使用了仅适用于GNU Make的功能。遗憾的是,在运行make命令时,我们必须支持一些还不支持GNU make的平台。
我的一个同事曾因此受挫,当一个非GNU make实现未正确构建代码时(它将自动变量扩展为空字符串),他并没有发出任何声音。我想通过生成明确的错误消息来防止再次发生这种情况。
在Makefile中,我应该写些什么来区分GNU make和非GNU make,打印清晰的错误信息并退出呢?
我已经想出了一个解决方法,即将真正的Makefile重命名为GNUmakefile,并在Makefile中放置一个小型存根,但我更希望有更直接的方法。
Beta和Dan Moulding的答案看起来非常好且简单,但在AIX 6.1上,make实现无法处理它们中的任何一个。
我的一个同事曾因此受挫,当一个非GNU make实现未正确构建代码时(它将自动变量扩展为空字符串),他并没有发出任何声音。我想通过生成明确的错误消息来防止再次发生这种情况。
在Makefile中,我应该写些什么来区分GNU make和非GNU make,打印清晰的错误信息并退出呢?
我已经想出了一个解决方法,即将真正的Makefile重命名为GNUmakefile,并在Makefile中放置一个小型存根,但我更希望有更直接的方法。
Beta和Dan Moulding的答案看起来非常好且简单,但在AIX 6.1上,make实现无法处理它们中的任何一个。
$ cat testmake
foo:
touch foo
ifeq ($(shell $(MAKE) -v | grep GNU),)
$(error this is not GNU Make)
endif
ifeq "${MAKE_VERSION}" ""
$(info GNU Make not detected)
$(error ${MIN_MAKE_VER_MSG})
endif
$ /usr/bin/make -f testmake
"testmake", line 5: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 6: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 7: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 8: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 11: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 12: make: 1254-055 Dependency line needs colon or double colon operator.
"testmake", line 13: make: 1254-055 Dependency line needs colon or double colon operator.
make: 1254-058 Fatal errors encountered -- cannot continue.
我在Sun的make工具的古老版本和现代版本(Solaris 8和10)上遇到了类似的问题。虽然这个问题不是很关键,但如果能解决就更好了。