This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [bug] -MT option and generating dependencies in one compiler pass.
Neil Booth wrote:
> Manu wrote:-
[...]
> > OTOH, if I remove -MT or -MQ, it works as expected:
> > $(OBJDIR)/%.o : %.cpp
> > $(COMPILE) -MMD -MF$(DEPDIR)/$*.Po -c $< -o $@
> >
> > Result:
> > ../obj/file2.o: file2.cpp file1.h
>
> Yes, that's what I meant above.
>
> > So, if I understand well, I must not use -MT / -MQ ?
>
> There's nothing to stop you, just that -MD and -MMD add an invisible
> extra target.
Ok, that's very simple finally. I understood.
> > This confuses me, because the manual says "With `-MT' you can specify a
> > target yourself, overriding the default one."
>
> Unfortunately, for historical reasons, the behaviour of the -M options
> is complex and convoluted, but changing it would break backwards
> compatibility.
>
> The manual entry is referring to the non-MMD and -MD options (i.e. -M
> and -MM). -MMD and -MD have the default appended by the driver, again
> for historical reasons, so CPP has no way of knowing what was your
> switch and what was added by the driver.
>
> The docs on the -M options need rewriting. Unforunately, the rewrite
> would be full of "but if you do A, then B, except if C then D"...
:) Yes, I can imagine.
> One day, when I've finished CPP language support, I'll rewrite the
> -M documentation. Or someone else could beat me to it.
Maybe adding an example to the -MD section... ?
"-MD -MP -MF $(depspfx)foo.Po -c foo.c -o $(objpfx)foo.o
might generate dependencies into foo.Po, located in $(depspfx) and
compile foo.c into foo.o, located in $(objpfx). -MP adds phony targets
to dependencies."
Just an idea.
Anyway, a web search on that topic should result these postings.
Many thanks for this very good info, I usually like to understand how
things work and why they don't, so I'm very satisfied.
Plus, I can now generate very simple makefiles, with the possibility
to specify an output directory for objects and dependency files.
Great !
Manu.