从另一个Makefile获取依赖项 [英] Get dependencies from another Makefile

查看:67
本文介绍了从另一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆