Makefile包含来自不同目录的makefile [英] Makefile include makefile from different directory
问题描述
我有两个文件,directoryA/Makefile
和directoryB/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:
-
directoryB/Makefile
中的目标都是相对于该Makefile定义的.
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屋!