2012-02-14 75 views
13

我有一個在OSX/Unix中以及Debian/Linux中的另一種方式的命令。我想爲我的應用程序創建一個make文件,但需要檢測操作系統並相應地發出命令。我會如何去做這件事?如何檢測make文件中的操作系統?

+0

可能重複http://stackoverflow.com/questions/714100/os-檢測生成文件) – Anko 2013-12-19 01:00:05

回答

25

你可以使用uname來做到這一點。在你的Makefile,你可以寫這樣的:

OS := $(shell uname) 
ifeq $(OS) Darwin 
# Run MacOS commands 
else 
# check for Linux and run other commands 
endif 
+2

該代碼如何在其中一個目標內執行? – Mikhail 2017-03-21 19:02:52

14

什麼工作對我來說

OS := $(shell uname) 
ifeq ($(OS),Darwin) 
    # Run MacOS commands 
else 
    # check for Linux and run other commands 
endif 
[OS檢測生成文件(的