This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Automatic dependency complexity


>>>>> ">" == srivasta  <srivasta@datasync.com> writes:

>> 	Have the -MD and -MMD flags output lines like:
>> foo.o foo.d: a.h

>> 	This really is the right thing to do.

I disagree.

I know that the GNU make documentation suggests having a separate rule
to create the `.d' files.  However, I think this isn't the best way to
go.  Instead, I believe that dependencies should be created as a side
effect of compilation.

This is what automake implements.  It seems to work quite well in
practice.

Doing things this way halves the number of compiler invocations needed
for a build as compared to the way GNU make suggests.


As it turns out, gcc's dependency tracking code isn't really as easy
to use as I'd like it to be (for automake).  Currently automake's
rules have to do some rather nasty post-processing on the generated
dependencies.

First, automake wants to put the `.d' files into a subdirectory.  That
rules out using `-MD'.  Also, in some cases, automake wants to change
the name of the target (e.g., to "foo.o foo.lo: ...").  That suggests
using DEPENDENCIES_OUTPUT -- but that appends to the file that is
created (also, DEPENDENCIES_OUTPUT apparently acts like `-MM' and not
`-M', despite the docs).  So instead automake passes `-Wp,-Md,...' to
gcc -- the first ugliness.

Second, automatic dependency tracking following this model is
susceptible to the "deleted header file" problem.  If I delete a `.h'
file that is mentioned in one of the dependency lists, `make' will
have no way to recreate it, and will die before the dependencies can
be recomputed.

Automake fixes this bug by adding fake targets for each header.  So in
the end automake ends up rewriting this:

	foo.o: foo.c foo.h

into this:

	foo.o foo.lo: foo.c foo.h
	foo.h:


I'd like to propose changing gcc's interface to dependency tracking so
that automake can use it more naturally.  At the same time, changing
the GNU make docs to recommend this (IMNSHO) better way of computing
dependencies would be a good idea.  Here are the new options I'm
thinking of:

  -MT NAME     Set name of target in generated file
               Default is computed as it is now

  -MF NAME     Set name of `.d' file.  (Default is as now.)

  -MH          Add a fake dependency for each header file

Implementation-wise, I think the code that actually generates the `.d'
file should be extracted from cpp and put into its own file.  That
would let the java front end use the same code (right now some of it
is duplicated).


What do people think of this?  It's on my list of stuff I want to
implement eventually, but of course it's hard to say when I'll get to
it.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]