如何编写可以分辨英特尔OS X和Linux之间差异的Makefile?

Ale*_*lds 6 linux macos makefile gnu-make

如何在GNU makeMakefile中编写一个条件,它可以识别架构(在这种情况下是Intel OS X vs Linux),这样我就可以适当地设置标志,而不需要最终用户在运行时指定Makefile make -f

编辑

我应该指定我从ifeq包含shell命令的语句中获取makefile错误,如果此条件位于目标之外:

'commands commence before first target. Stop.'

pax*_*blo 10

您应该能够检查其中一个uname变体的输出,然后makefile根据具体情况选择不同的操作.

运行man uname详细信息.

关于如何从GNU make中使用它,您可以将信息从shell函数中获取到变量中,然后ifeq在该变量上使用:

platform=$(shell uname -o)

ifeq ($(platform),Cygwin)

defrule:
    echo I am running in Cygwin.

else

defrule:
    echo I am running elsewhere.

endif
Run Code Online (Sandbox Code Playgroud)