Makefile 条件错误

标签 makefile conditional-statements gnu-make

我正在尝试执行 make 语句来检查架构。我非常接近让它发挥作用:

test:
        ifeq ("$(shell arch)", "armv7l")
                echo "This is an arm system"
        else
                echo "This is not an arm system."
        endif

我有一个问题:虽然这似乎解决了 ifeq ("i386", "armv7l") 这应该是错误的,但我收到以下错误:

$ make
ifeq ("i386", "armv7l")
/bin/sh: -c: line 0: syntax error near unexpected token `"i386",'
/bin/sh: -c: line 0: `ifeq ("i386", "armv7l")'
make: *** [test] Error 2

因此,它解析为两个字符串进行比较,但存在语法错误。这里出了什么问题?

最佳答案

您不能在配方中使用像 ifeq 这样的 make 语句。配方(以 TAB 开头的行)将传递到 shell。 shell 不理解 ifeq;这是一个 make 构造。

您必须在配方中使用 shell if 语句。而且,您不必在配方中使用 $(shell ...),因为您已经在 shell 中了。

test:
        if [ `arch` = armv7l ]; then \
            echo "This is an arm system"; \
        else \
            echo "This is not an arm system."; \
        fi

这可能不是处理此问题的最佳方法,但由于您没有提供任何有关您真正想要做什么的信息,所以我们只能说。

关于Makefile 条件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17620887/

相关文章:

jquery - 包含元素的每一行,然后删除该行中的类

makefile - 获取目录makefile驻留在

linux - 带 make 的管道不起作用

regex - makefile 目标上的多个词干

jquery隐藏所有图像但不隐藏第一个

windows - 在 Windows 上为 GNU Make 定义和使用构建时间戳

c - GNU Make 无法从循环中进入子目录

c - 正确编译后如何让我的 Makefile 发出声音?

get - 如果资源是在初始请求中获取的,是什么让条件 GET 为 "conditional"?

Python 在字符串中执行操作