Makefile包含来自不同目录的makefile [英] Makefile include makefile from different directory

查看:98
本文介绍了Makefile包含来自不同目录的makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件,directoryA/MakefiledirectoryB/Makefile.

directoryA/Makefile取决于较大而复杂的directoryB/Makefile中的目标.

directoryA/Makefile depends on targets in a rather large and complex directoryB/Makefile.

我可以进行递归制作

$(MAKE) -C directoryB

但是出于几个原因,这是不可取的.两个主要的原因:我不得不多次执行makefile,并且make无法正确知道何时需要重建目标.

But that is undesirable for several reasons. Two big reasons: I make have to execute the makefile several times, and make can't correctly know when rebuilding a target is necessary.

我想使用include指令.问题是双重的:

I would like to use the include directive. The problem is twofold:

  1. directoryB/Makefile中的目标都是相对于该Makefile定义的.

  1. The targets in directoryB/Makefile are all defined relative to that Makefile.

许多命令取决于工作目录为directoryB.

Many commands depend on the working directory being directoryB.

递归make解决了这两个问题,但是有很大的缺点(如前所述).使用include时是否有办法解决这两个问题?

Recursive make solves both of these problems, but with big disadvantages (mentioned earlier). Is there a way to solve both problems when using include?

推荐答案

很难不见directoryA/Makefile很难说,但是另一种选择是先include directoryB/Makefile然后

It's hard to say without seeing directoryA/Makefile, but another alternative is to have it include directoryB/Makefile, then

cd directoryB
make -f ../directoryA/Makefile

这篇关于Makefile包含来自不同目录的makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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