Makefile 在if语句中设置变量不起作用
在这个非常简单的makefile中,我尝试在条件内设置一个变量,但在条件外没有注意到更改Makefile 在if语句中设置变量不起作用,makefile,gnu-make,Makefile,Gnu Make,在这个非常简单的makefile中,我尝试在条件内设置一个变量,但在条件外没有注意到更改 all: STUFF="nothing" ifeq (true, true) echo "setting" STUFF="hi" endif echo $(STUFF) 当我运行这个命令时,我希望最后一个命令打印“hi”,但它没有 chris@cranberry ~/git % make STUFF="nothing" echo "setti
all:
STUFF="nothing"
ifeq (true, true)
echo "setting"
STUFF="hi"
endif
echo $(STUFF)
当我运行这个命令时,我希望最后一个命令打印“hi”,但它没有
chris@cranberry ~/git % make
STUFF="nothing"
echo "setting"
setting
STUFF="hi"
echo
我做错了什么
更新:
run: build/aura.bin
ifdef DEBUGGING
$(eval DFLAGS=-s -S)
endif
qemu-system-i386 -serial stdio $(DFLAGS) -kernel build/aura.bin
我通过使用
$(eval)
设置值来修复它
all:
STUFF="nothing"
ifeq (true, true)
echo "setting"
$(eval STUFF="hi")
endif
echo $(STUFF)
您可以在不使用
eval的情况下执行此操作
ifdef DEBUGGING
run: private DFLAGS += -s -S
endif
run: build/aura.bin
qemu-system-i386 -serial stdio $(DFLAGS) -kernel $<
ifdef调试
运行:私有DFLAGS+=-s-s
恩迪夫
运行:build/aura.bin
qemu-system-i386-串行stdio$(DFLAGS)-内核$<
另一种选择是
run: private DFLAGS += $(if $(DEBUGGING),-s -S)
run: build/aura.bin
qemu-system-i386 -serial stdio $(DFLAGS) -kernel $<
run:private-DFLAGS+=$(如果$(调试),-s-s)
运行:build/aura.bin
qemu-system-i386-串行stdio$(DFLAGS)-内核$<
删除private
以使DFLAGS
的值在run
的先决条件中可用。正如您所发现的,您不能在Recipes中直接设置make变量eval
有效,但可能还有另一种方法,不幸的是,你的例子太过做作,无法给出一个像样的解决方案,你能发布一下你是如何真正使用它的吗?@user657267查看我的更新问题。$@chris13524是什么?这是一个特别的$经验法则:eval
永远都不是正确的答案,除非没有其他可能的答案。