makefile - 使用 ifeq 在 Makefile 中定义条件变量

标签 makefile conditional-statements

我正在尝试根据条件在 Makefile 中定义变量。由于 ifeq 只能在规则中运行,因此我为每个规则添加了一条附加规则 (def_rule)。

示例:

def_rule:
ifeq ($(TARGET), android)
    CC=arm-linux-androideabi-gcc
else
    echo "native build" 
endf

all:    def_rule tp xi_eid_chipset.o

不幸的是,调用 make all 会返回以下内容:

ifeq (linux, android)
/bin/sh: Syntax error: word unexpected (expecting ")")
make: *** [def_rule] Error 2

我不明白为什么。我刚刚遵循了 GNU Make 文档中的示例。

你知道如何在 Makefile 中进行条件定义吗?

最佳答案

条件可以超出规则:

ifeq ($(TARGET), android)
 $(info Android)
 CC=arm-linux-androideabi-gcc
else
 $(info native build)
 CC=something else
endif

(请注意,我添加了一些前导空格,只是为了使其更易于阅读 - 它们既没有必要也没有害处。)

关于makefile - 使用 ifeq 在 Makefile 中定义条件变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6523939/

相关文章:

javascript - 如何创建动态 if 条件

string - 为什么从标准输入读取用户输入时我的字符串不匹配?

r - 如何在我的代码中停止 if 循环的计数过程?

javascript - 祖先的事件处理程序可以停止其子元素的事件之一的传播吗?

c - 如何链接来自不同目录的对象(运行 ld)

c++ - pthreads 的 Makefile

BBB 上的 Ruby 2.00 编译错误

c++ - 如何知道一个c++源文件是否有main函数?

makefile - Make 添加意外的 mv 命令

object - 分机JS 4 : Custom object property value based on condition