在gnu make中,有没有办法获取启动整个链的原始目标并将执行引导到当前配方?
.PHONY : all clean common
all: common
clean: common
common:
@echo $@
@echo $(MAKECMDGOALS)
@for a in $$(ls); do \
if [ -d $$a ]; then \
echo -C $$a $(MAKECMDGOALS); \
#$(MAKE) -C $$a $(MAKECMDGOALS); \
fi; \
done;
@echo "Done!"
如上面的示例所示,当我运行“make all”或“make clean”时,我可以使用 $(MAKECMDGOALS) 来告诉从命令行传递给 make 的目标。然而,如果有人将其称为“make clean all”,那么“common”将被调用一次,我们会得到“make:Nothing to be do for 'clean'”。
那么,有没有一种方法可以在每次将其作为目标的先决条件引用时调用“common”,并计算出原始目标名称,以便将其传递到下一个 make 中?尽管“common”是一个假目标,但它只被调用一次,我不确定为什么。
我有以下替代方案,但我认为第一个是最简洁的
生成文件1
just_a_func = @echo "just_a_func from " $(1)
.PHONY : all clean
all:
@echo $@ " enter"
$(call just_a_func, $@)
clean:
@echo $@ " enter"
$(call just_a_func, $@)
生成文件2
.PHONY : all clean common
all:
@echo $@ " enter"
$(MAKE) -f makefile common
clean:
@echo $@ " enter"
$(MAKE) -f makefile common
common:
@echo $@ " enter"
让我印象深刻的是,这里有两个问题,一个是标题中的问题,另一个是在阐述问题时插入的。
在回答标题中的问题:抓住导致变革的目标时,请使用remake http://bashdb.sourceforge.net/remake/.
例如,使用您提供的 Makefile:
$ remake -X -f Makefile
GNU Make 4.1+dbg0.91
...
Reading makefiles...
Updating makefiles....
Updating goal targets....
File 'PHONY' does not exist.
File 'all' does not exist.
-> (/tmp/Makefile:5)
common:
remake<0> T
=>#0 common at /tmp/Makefile:5
#1 all at /tmp/Makefile:2
#2 PHONY at /tmp/Makefile:1
remake<1> quit
$ remake -X -f Makefile clean
GNU Make 4.1+dbg0.91
...
Reading makefiles...
Updating makefiles....
Updating goal targets....
File 'clean' does not exist.
-> (/tmp/Makefile:5)
common:
remake<0> T
=>#0 common at /tmp/Makefile:5
#1 clean at /tmp/Makefile:3
remake<1>
上面我们恰好从我们想要检查的目标开始。如果不是这种情况,您可以使用“断点”命令设置断点,然后“继续”运行,直到达到该目标。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)