help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fun with auto generated dependencies & clean...


From: Mike Shal
Subject: Re: Fun with auto generated dependencies & clean...
Date: Thu, 19 Apr 2007 17:39:53 -0400

On 4/19/07, Rick Flower <address@hidden> wrote:
Hi all again.. This is not so much a problem as an annoyance to me that
others are happily able to live with -- I'd like to solve it if
possible.. What I've got is a source tree with C++ files (.cc) in it and
as part of the Makefiles I've got, there are also auto-dependencies
created when "make all" is invoked.  This works great except for one
case which we frequently do around here -- "make clean all".  In that
case, the dependencies are created only to be removed by the "clean"..
If you separate the clean/all steps into separate steps it works great.
  Anyway, below are some Makefile snippets that may or may not shed some
light on the issue.. If you've got any ideas on solving this annoyance,
I'd love to hear about it.   Thanks!

The problem is you're building the dependencies before each build,
rather than during the build. This is because you've made a rule for
the dependency files (%.d: %.cc) and you're including them. It is only
necessary to have the dependency files available for the *next* build.
See: http://make.paulandlesley.org/autodep.html

%.d: %.cc
        @echo "Building depends..."
        $(target_gpp) -MM $(GPPFLAGS) $< \
        | sed "/.*\.o:/ s%^[ ]*%\$$(OBJDIR)/%" > $@

I would get rid of this rule, or perhaps move the commands into the
%.o: %.cc rule so the .d and .o files are built at the same time.

$(OBJDIR)/%.o : %.cc %.d
        @echo "Prerequisites are: $^"
        $(target_gpp) $(GPPFLAGS) -c $< -o $@

Here I would remove %.d from the rule, since the .o file doesn't need
the .d file to be built (again, you just want the .d to hang around
for the next time you build). If you moved your commands from the .d
rule here, you would always create the .d file when you create the .o
file. Or, assuming you're using a recent version of gcc, look into the
-MMD flag. This flag will create the .o and .d simultaneously (thus
saving you an extraneous preprocessing step). Also look at the other
-M flags (like -MT, -MF, etc) to get the .d file in the location you
want it, and have it specify the correct rule. IIRC these flags
changed behavior a few times during the 3.X releases, but I think
they're stable now.

Not sure if that necessarily helps with the issue of specifying both
clean and all at the same time (it seems like you would still have
issues with -j), but it would be more efficient :)

-Mike




reply via email to

[Prev in Thread] Current Thread [Next in Thread]