我有一个项目,其makefile使用GNU Make独有的功能。不幸的是,在运行make
时,我们必须支持GNU make所依赖的平台。当某人运行`make`时检测(非)GNU Make
我的一个同事被这个咬了,当一个非GNU make的实现静静地无法正确地构建我们的代码(它将自动变量扩展为空字符串)。我想通过生成明确的错误消息来防止再次发生。
我可以在Makefile
中写什么来区分GNU make和non-GNU make,打印出明确的错误并退出?
我已经想出了一个解决方法,将我的真实生成文件重命名为GNUmakefile
,并在Makefile
中放置一个小存根,但我宁愿更直接一些。
的Beta版和丹塑造的答案看起来真的不错,很简单,但在AIX 6.1,厂名实现不能处理任何人:
$ 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的产品版本(Solaris 8 & 10)。那个不那么重要,但会很好管理。
您运行的是哪个版本的GNU make? – bta 2010-08-04 18:00:28
你是对的。我所采用的方法过于依赖GNUisms,因此可能无法在非GNU make的实现*上运行。我现在怀疑是否有一种使用Makefile(即不使用shell脚本或其他外部资源)来实现您的目标的便携式方法。我已经取消了我的答案。 – 2010-08-04 18:46:36