我有一個項目,其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