This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
In gcc/doc/cppopts.texi, in the description of -MT it says: Change the target of the rule emitted by dependency generation. By default CPP takes the name of the main input file, including any path, deletes any file suffix such as @samp{.c}, and appends the platform's usual object suffix. The result is the target. An @option{-MT} option will set the target to be exactly the string you specify. If you want multiple targets, you can specify them as a single argument to @option{-MT}, or use multiple @option{-MT} options. My reading of this is that if you specify -MT <target>, then the default target will *NOT* be used. And examining the code, that appears to be the intent -- for each target specified with -MT / -MQ, deps_add_target is called. And after processing such arguments, deps_add_default_target is called (by cpp_read_main_file) which only adds the default target if there are no targets already specified. But, that isn't the full story. In gcc.c, variable cpp_unique_options, we find this line: %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}} which causes the default target to get added unilaterally. I believe that either this line should disappear totally or it should be changed to: %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} i.e., have !MT && !MQ added as a condition. I have lightly tested both solutions; they both appear to work.
*** Bug 12478 has been marked as a duplicate of this bug. ***
To reproduce the problem, consider the following Makefile: CC = gcc CFLAGS = -MD -MT foo.o -MF foo.d MV = mv foo.o: bar.c ${CC} bar.c -o - > xfoo.o ${MV} xfoo.o foo.o Suppose bar.c includes no files, then the resulting foo.d file will contain: foo.o -: bar.c But, it should contain: foo.o: bar.c The - should NOT be present. You could argue about whether - should ever be a target within the .d file, but regardless -- if the user specified one or more targets with -MT / -MQ, then the *DEFAULT* target should *NOT* be used. Eliminating or editing the cpp_unique_options line, as mentioned, fixes the problem. Deleting the line (my preferred fix) bootstraps just fine. There do not appear to be any tests within the testsuite that test the -MT / -MQ / -MD / -MMD / -MF / -M<whatever> options. If someone will give me a pointer on how to have the testsuite compare two files -- the generated .d file against the correct .d file, I will gladly write a test case for this bug.
Hello, I just came to Bugzilla to report this bug, and bumped into this existing bug report. Since this is currently set as UNCONFIRMED, I'd simply like to point out that the bug is very easily reproducible. For example: $ touch foo.h $ echo '#include "foo.h"' > foo.c $ gcc -c -MD foo.c -MT foo.d -o foo.o $ cat foo.d foo.d foo.o: foo.c foo.h Now, since -MT is advertised to "set the target to be exactly the string you specify", and indeed does that in all other cases (i.e., except when it's specified along with both -MD and -o), this is an obviously wrong behaviour.
Confirmed but please send the patch to gcc-patches@gcc.gnu.org.
The proposed patch would be this: ------------------------------------------------------------------------ <date> David Taylor <taylor at candd dot org> PR driver/12448 * gcc.c (cpp_unique_options): Strip Index: gcc.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/gcc.c,v retrieving revision 1.400 diff -c -3 -p -r1.400 gcc.c *** gcc.c 20 Dec 2003 07:40:21 -0000 1.400 --- gcc.c 23 Dec 2003 11:57:41 -0000 *************** static const char *cpp_unique_options = *** 745,751 **** %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ ! %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\ %{trigraphs} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\ %{E|M|MM:%W{o*}}"; --- 745,751 ---- %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ ! %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} \ %{trigraphs} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\ %{E|M|MM:%W{o*}}"; ------------------------------------------------------------------------ I really can't tell if this is correct or not. Evil driver commands!
I just bumped into this bug as well. Still failing in gcc-3.4.3 a year later :-( The simplest test case: mkdir pr12448 && cd pr12448 && touch foo.c && gcc -c -o foo.o -MD -MTfoobar foo.c && cat foo.d Current output: foobar foo.o: foo.c Expected output: foobar: foo.c
*** Bug 25356 has been marked as a duplicate of this bug. ***
The patch in this PR looks correct to me.
I tested this and it works. I'm submitting it.
Subject: Bug number PR driver/12448 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-01/msg01759.html
Subject: Bug 12448 Author: tromey Date: Tue Mar 13 23:50:42 2007 New Revision: 122889 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122889 Log: 2007-03-13 David Taylor <taylor@candd.org> PR driver/12448: * gcc.c (cpp_unique_options): If -MT or -MQ is seen, don't pass default -MQ. Modified: trunk/gcc/ChangeLog trunk/gcc/gcc.c
*** Bug 31851 has been marked as a duplicate of this bug. ***