On 4/19/07, Rick Flower <[EMAIL PROTECTED]> 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 _______________________________________________ Help-make mailing list Help-make@gnu.org http://lists.gnu.org/mailman/listinfo/help-make