我正在尝试根据条件在 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/