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

Usm*_*ail 15 makefile

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

小智 29

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

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

  • 如何在其中一个目标内执行此代码? (2认同)

Noé*_*her 15

什么对我有用

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