Makefile dependency to reuse existing artifacts to remake common target

混江龙づ霸主 提交于 2019-12-24 06:12:55

问题


This may be simple but I've not been able to find the answer. I'm developing a gmake system for an embedded platform that has two processing elements, each with their own firmwares, call them CoreA.bin and CoreB, each with their own tree of dependencies. CoreB's make system is from a third party and has to be treated as a black box PHONY target. The bootloader updates them both from a single binary file, call it BinFile.bin which contains CoreA.bin and CoreB binaries rolled together.

Thus the make dependencies look like this:

.PHONY CoreB
CoreA.bin: Some Targets
CoreB    : Yet More
BinFile.bin: CoreA.bin CoreB
all: BinFile.bin

Nice and simple. However the builds take a long time and the guys working on CoreA build 'all' once to get a CoreB binary and then the BinFile, then only need to rebuild CoreA. The make dependencies take quite a while to resolve so they don't want to remake CoreB, but they do need BinFile to be remade.

This would look something like this:

BinFileSubsequent : CoreA
BinFileSubsequent :
     # Remake CoreA
     # Remake the BinFile rollup without duplicating the makefile code

The problem is shaking the CoreB dependency but still remaking the BinFile with existing artifacts. Any ideas?


回答1:


Real targets should not depend on .PHONY targets. That's causing the problem you are having.

From 4.6 Phony Targets:

A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal (see Arguments to Specify the Goals).

Does the CoreB build system have a way to tell you if it has work to do? If it does then using a stamp file instead of the phony target is likely the simplest solution.

If not, and a manual "solution" is acceptable then something like this might work.

.PHONY CoreB
CoreA.bin: Some Targets
CoreB    : Yet More
ifeq (,$(PARTIAL_BUILD))
BinFile.bin: CoreB
endif
BinFile.bin: CoreA.bin
all: BinFile.bin

And then running make will do the full build and running make PARTIAL_BUILD=1 will run without listing CoreB as a prerequisite of BinFile.bin.

This assumes, of course, that the BinFile.bin rule knows how to find the built output of CoreB without using the CoreB prerequisite entry.



来源:https://stackoverflow.com/questions/27425097/makefile-dependency-to-reuse-existing-artifacts-to-remake-common-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!