刚一说明,我糊涂了 - 让这个做文件testmake
:
$(eval $(info A: CFLAGS here is $(CFLAGS)))
override CFLAGS += -B
$(eval $(info B: CFLAGS here is $(CFLAGS)))
CFLAGS += -C
$(eval $(info C: CFLAGS here is $(CFLAGS)))
override CFLAGS += -D
$(eval $(info D: CFLAGS here is $(CFLAGS)))
CFLAGS += -E
$(eval $(info E: CFLAGS here is $(CFLAGS)))
然后:
$ make -f testmake
A: CFLAGS here is
B: CFLAGS here is -B
C: CFLAGS here is -B
D: CFLAGS here is -B -D
E: CFLAGS here is -B -D
make: *** No targets. Stop.
$ make -f testmake CFLAGS+=-g
A: CFLAGS here is -g
B: CFLAGS here is -g -B
C: CFLAGS here is -g -B
D: CFLAGS here is -g -B -D
E: CFLAGS here is -g -B -D
make: *** No targets. Stop.
随着override
指令从testmake
文件中删除:
$ make -f testmake
A: CFLAGS here is
B: CFLAGS here is -B
C: CFLAGS here is -B -C
D: CFLAGS here is -B -C -D
E: CFLAGS here is -B -C -D -E
make: *** No targets. Stop.
$ make -f testmake CFLAGS+=-g
A: CFLAGS here is -g
B: CFLAGS here is -g
C: CFLAGS here is -g
D: CFLAGS here is -g
E: CFLAGS here is -g
make: *** No targets. Stop.
所以,
- 如果一个变量用
override
一次,它只能与override
(正常分配将被忽略)另一个语句所附;
- 根本没有
override
;试图从命令行追加(如+=
)覆盖该变量的每个实例。
感谢您的参考链接。这看起来像是解决问题的更好方案之一。 –