Subject: Recursive make and variations on the theme

From: Jonathan Nieder <[email-masked]>
Date: Wed, 23 Feb 2011 03:56:50 -0600

Jeff King wrote:

> The problem is that no single make was
> allowed to see the whole dependency tree.
>
> I know GNU make does have some magic for communicating between recursive
> makes. Does it handle this situation?
>
> You can fix this with a rule like "only invoke recursive makes on
> directories _below_ you, never above or to the side". But then you can't
> run "make" from inside cmds/.

In that story, commands/Makefile would make commands/built-in.a and
various commands/foo.o.  The toplevel makefile would pass "make -C
commands" a long list of targets to build, presumably deduced from
$(MAKECMDGOALS).  Not pleasant, I agree.

>>      - keep careful track of what directory "make" was run from; [*]
>> [...]
>>     [*] is a little hazy and sounds hackish.
>
> Yeah, you have to be careful with paths.

It could be pretty simple by maintaining a $(prefix_) variable
representing the path from the cwd to the directory containing the
makefile.  Might try it out.

> I think a more sane way would
> be a single top-level Makefile that [...] contains everything

That sounds best to me in the short term, too.

> A dummy Makefile in each subdir that cd's to the toplevel and runs a
> specific target. So from the top-level, "make" would build everything,
> "make lib" would build stuff in the lib directory, and the Makefile in
> lib/ would just do "cd .. && make lib".

Yes, reasonable.

Ciao,
Jonathan