【发布时间】:2019-08-07 21:47:30
【问题描述】:
我想根据 makefile 中的另一个变量值来不同地定义一个变量。我认为使用条件可以解决问题,就像在 makefile 中这样:
ifeq ($(BOOT_FLAG),installed)
BOOT_TEST=$(BOOT_FLAG)
else
BOOT_TEST=no
endif
BOOT_DEFINE=$(BOOT_FLAG)
BOOT_FLAG=installed
.PHONY: all
all:
@echo $(BOOT_TEST)
@echo $(BOOT_DEFINE)
我预计输出是:
installed
installed
但我得到了这个:
no
installed
显然 ifeq 没有将 BOOT_FLAG 扩展为 installed
但是 BOOT_DEFINE 变量的设置可以正确扩展它。
我在手册中读到:
“make 在读取 makefile 时评估条件。因此,您不能在条件测试中使用自动变量,因为它们在命令运行之前没有定义”
但 BOOT_FLAG 不是自动变量。此外,如果我将 BOOT_FLAG 的定义移到 ifeq 之前,那么它可以按我的意愿工作。但是,我想保持定义的当前顺序(而且我不明白为什么 make 在使用条件时会对定义的顺序无关性产生异常)
【问题讨论】:
标签: makefile conditional-statements