I have two projects which I build with GNU make. Project B depends upon one of the outputs of project A. Let's call it OUTPUT. So the Makefile for project B contains something like this:
target: ../ProjectA/OUTPUT
do stuff
To ensure that OUTPUT is up to date, I would like the Makefile for B to launch the make for A and then only "do stuff" if OUTPUT was rebuilt (or was already newer than target).
I first tried doing it this way:
../ProjectA/OUTPUT:
(cd ../ProjectA; $(MAKE) OUTPUT)
but because there are no dependencies given for OUTPUT, make will simply assume that it is up to date if it exists and will not run the sub-make.
Declaring OUTPUT to be phony ensures that the sub-make will run:
.PHONY: ../ProjectA/OUTPUT
../ProjectA/OUTPUT:
(cd ../ProjectA; $(MAKE) OUTPUT)
but now make will ignore the actual date on OUTPUT and always consider it to be newer than target, meaning "do stuff" will always execute.
The only thing I've found to work is duplicating OUTPUT's entire dependency tree within B's Makefile. That's too horrible to contemplate. Only slightly less horrible is to put OUTPUT's dependency tree in a separate file that the Makefiles for both projects include.
Is there a nicer way to get make to do what I want?