[distcc] improved gcc -MD handling

Martin Pool mbp at hpausa5.aus.hp.com
Thu Nov 21 20:14:00 GMT 2002


I put some changes into distcc CVS last night that improve gcc -MD
handling.  These should make the most common cases work properly.

distcc now runs the preprocessor with -E and no -o option, and
captures the preprocessor's stdout.  This should allow distcc to work
with compilers which don't accept -E and -o together -- I think some
Sun or HP compilers are like this.

gcc dependency computation takes place as a side effect of
preprocessing, so by passing -M options through to the preprocessor
distcc ought to be able to evaluate them on the client.

Getting this to work exactly the same as gcc is difficult because gcc
has changed the meaning of this option over time in a very perverse
way.  In addition, sometimes the manual seems to not be in sync with
the program, and different programs described as "3.2" behave
differently.  :-(

  gcc-2.95     -MD always writes into working directory
	       There is no -MF option.
	       With -E and -o, -o sets the preprocessor output.

  gcc-3.2      -MF option to set dependency output file
	       With -E and -o, -o sets the dependency output.
	       Without -E but with -o, -o sets the object file, and
	       dependencies are written alongside the object file.
	       Without -E or -o, dependencies are written alongside
	       the source file.

  others       Who knows?!?  

For the common and simple case of source, objects and dependencies in
the same directory, they all behave the same way.  For more complex
situations, you can't know what will happen without (in practice)
trying it to see, since it varies between versions.  If you use these
features and upgrade gcc from 2.95 to 3.2 your Makefile might
break. :-(

distcc now turns an invocation like this

  distcc gcc -c ~/hello.c -MD

into a preprocessor command like this:

  gcc -E ~/hello.c -MD

which will be somewhat reasonable for both versions: 2.95 will put a
.d file in the working directory, and 3.2 will put it in ~/hello.d.  

If you used 3.2 and relied on the dependencies being put alongside the
-o file then distcc will probably not behave the same way.  I can't
see any feasible way to implement that at the moment.  We can't use
-MF, since that's not supported in some copies of gcc.  We can't
specify -o, because 3.2 stupidly breaks -E -o.  

If anyone knows a better way I'd like to hear it.

However, if your Makefile counts on using gcc-3.2, then it would be
reasonable to add a -MF option to explicitly set the dependency file.
distcc will pass that through, and it should work fine.

-- 
Martin



More information about the distcc mailing list