从另一个Makefile获取依赖项 [英] Get dependencies from another Makefile
问题描述
我正在尝试使用多个makefile,如下所示:
I'm trying to use multiple makefiles like this:
在~/generator/Makefile
中:
foo.xml: foo-part1.xml foo-part2.xml foo-part3.xml
./generate $^ > $@
在~/some/other/dir/Makefile
中:
foo.xml:
$(MAKE) -C ~/generator $@
mv ~/generator/$@ $@
问题是:当我进入~/some/other/dir/
并运行make foo.xml
时,没有foo.xml
的依赖项列表,并且即使(例如)~/generator/foo-part1.xml
比~/generator/foo-part1.xml
更新,也不会调用make -C ~/generator foo.xml
目标.
The problem is: when I go to ~/some/other/dir/
and run make foo.xml
, there is no dependency list for foo.xml
, and make -C ~/generator foo.xml
isn't called even if (for instance) ~/generator/foo-part1.xml
is newer than the target.
我想到的唯一解决方案是将具有绝对路径的依赖项列表复制到~/some/other/dir/Makefile
,这很糟糕:
The only solution I thought of is copying the dependency list with absolute paths to ~/some/other/dir/Makefile
, which is quite awful:
foo.xml: ~/generator/foo-part1.xml ~/generator/foo-part2.xml ~/generator/foo-part3.xml
然后,我的问题是:makefile中是否有办法询问另一个em_makefile目标的依赖关系是什么?还是仅将请求foo.xml
转发到该makefile并收集结果?我基本上希望第二个makefile在决定是否应重建目标以及何时重建目标时依赖第一个makefile.
Then, my question is: is there a way in a makefile to ask another makefile what are the dependencies of target? Or to just forward the request foo.xml
to that makefile and collect the result? I basically want the second makefile to rely on the first one when it comes to decide if a target should be rebuilt, and when it comes to build it.
推荐答案
我通过在第二个生成文件中包含两个规则来解决了这个问题:
I solved it by having two rules in the second makefile:
在~/some/other/dir/Makefile
中:
.PHONY: ~/generator/foo.xml
~/generator/foo.xml:
$(MAKE) -C ~/generator $(notdir $@)
foo.xml: ~/generator/foo.xml
cp $< $@
这篇关于从另一个Makefile获取依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!