martine/ninja — Issue #241: Broken dependency files generated by older GCC/multi-target dep files
Author: usovalx
Created: 2012-03-08 01:58:52+00:00
State: open

Hi,

I have just been hit by issue #147 -- where older versions of gcc
would generate incorrect depfiles under some circumstances.

Simple example:
> touch foo.cc
> g++ -MMD -MF t.cc.o.d -MQ t.cc.o.d -o t.cc.o -c t.cc && cat t.cc.o.d
t.cc.o t.cc.o: t.cc
> g++ -MMD -MF t.cc.o.d -MQ t.cc.o.d -o t.cc.o -E t.cc && cat t.cc.o.d
t.cc.o: t.cc
> g++ -MMD -MF t.cc.o.d -o t.cc.o -c t.cc && cat t.cc.o.d
t.cc.o: t.cc
> g++ -MMD -MF t.cc.o.d -o t.cc.o -E t.cc && cat t.cc.o.d
t.o: t.cc

The main problem is that I use distcc as the compiler (configured so
that it uses a few local CPU's and a bunch of remotes) and it will
effectively run "gcc -c" for local compilations and "gcc -E" for
remotes.

Quick-and-dirty workaround would be to write distcc wrapper to rewrite
depfile (btw, are there any specific requirement for depfile timestamp
w.r.t. corresponding object file?).

More long-term (and potentially much more useful) solution would be to
extend ninja's depfile parser to accept multiple targets:
target1 target2 ... targetN: dep1 dep2 .. depN

I'm ready to implement it in the coming few days if there would be no
objections to it.