如何在make文件中检测操作系统?

时间:2012-02-14 15:42:39

标签: makefile

我有一个在OSX / Unix中运行的命令,另一个在Debian / Linux中运行。我想为我的应用程序创建一个make文件,但需要检测操作系统并相应地发出命令。我该怎么做呢?

3 个答案:

答案 0 :(得分:28)

您可以使用 uname 执行此操作。在Makefile中,您可以编写如下内容:

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

答案 1 :(得分:15)

什么对我有用

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

答案 2 :(得分:1)

使用autotools。这是构建可移植源代码包的标准方法。