This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

Re: [bug] -MT option and generating dependencies in one compiler pass.


Neil Booth wrote:


> Manu wrote:-
>
> > A .cpp rule using 1 compiler pass:
> > $(OBJDIR)/%.o : %.cpp
> > #      $(MAKEDEPEND) $< -MT$@ > $(DEPDIR)/$*.Po
> > #      $(COMPILE) -c $< -o $@
> >         $(COMPILE) -MT$@ -MMD -MF$(DEPDIR)/$*.Po -c $< -o $@
> >
> >
> > It seems to work at first glance:
> > Invoking compiler...
> > g++ -MM   file1.c -MT../obj/file1.o > _deps/file1.Po
> > g++   -W -Wall   -O2 -c file1.c -o ../obj/file1.o
> > g++   -W -Wall   -O2 -MT../obj/file2.o -MMD -MF_deps/file2.Po -c file2.cpp -o
../obj/file2.o
> > g++  -O2 -s     ../obj/file1.o ../obj/file2.o -o .././new.exe
> > Performed successfully. (434 ms)
> >
> > But in fact "src/_deps/file2.Po" is corrupted:
> > ../obj/file2.o ../obj/file2.o: file2.cpp file1.h
> > ^^^^^^^^^^^^^^^^^^^
>
> -MMD implies an -MQ target.  Since you can specify multiple targets
> for the dependency, your -MT is in addition to the implicit target,
> and does not replace it.

Ok, I see.

Though, I have the same result with -MQ:
$(OBJDIR)/%.o : %.c
        $(COMPILE) -MQ$@ -MMD -MF$(DEPDIR)/$*.Po -c $< -o $@

Result:
../obj/file1.o ../obj/file1.o: file1.c file1.h

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

So, if I understand well, I must not use -MT / -MQ ?
This confuses me, because the manual says "With `-MT' you can specify a
target yourself, overriding the default one."

Can you confirm that the following is correct:
$(OBJDIR)/%.o : %.cpp
        $(COMPILE) -MMD -MF$(DEPDIR)/$*.Po -c $< -o $@

Manu.



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