【问题标题】:How do I code a Makefile that can tell the difference between Intel OS X and Linux?如何编写可以区分 Intel OS X 和 Linux 的 Makefile?
【发布时间】:2011-09-26 11:12:44
【问题描述】:

如何将条件写入 GNU make Makefile,它可以识别架构(在本例中为 Intel OS X 与 Linux),以便我可以适当地设置标志,而无需最终用户在何时指定 Makefile正在运行make -f

编辑

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

'commands commence before first target. Stop.'

【问题讨论】:

    标签: linux macos makefile gnu-make


    【解决方案1】:

    您应该能够检查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
    

    【讨论】:

    • uname -o 在 OS X 上实际上无效。uname -s 可能就足够了。
    【解决方案2】:

    uname 是你的朋友。

    $ uname -o
    GNU/Linux
    

    【讨论】:

      猜你喜欢
      • 2011-04-29
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多