https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105605

            Bug ID: 105605
           Summary: Manual/doc: Default dependency target (-MT) omits
                    dependence on -o (output file)
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scott.g.mcpeak at gmail dot com
  Target Milestone: ---

In the current documentation for preprocessor options:

  https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

under the description of the -MT switch, it says:

  Change the target of the rule emitted by dependency generation.  By
  default CPP takes the name of the main input file, deletes any
  directory components and any file suffix such as `.c', and appends the
  platform's usual object suffix.  The result is the target.

The second sentence is true of -M/-MM, but not of -MD/-MMD:

  $ mkdir tmp; cd tmp
  $ echo 'int x;' > foo.c
  $ gcc -MMD -c foo.c -o bar.o    # Note "-o bar.o".
  $ ls
  bar.d  bar.o  foo.c
  $ cat bar.d
  bar.o: foo.c                    # Note target name: "bar.o".

If the manual were correct, the target would be called "foo.o" because
no -MT is specified and the source file name is "foo.c".  The GCC
behavior here is perfectly sensible of course, but the manual does not
describe it correctly.

In general, based on experimentation with GCC-12.1.0, a correct
description of the procedure for determining the target name or names is
to use the first of:

1. The sequence of names given to -MT, then those given to -MQ, each
   respective sequence in command line order, if there are any -MQ/-MT
   switches; or
2. For -MD and -MMD, the argument to -o, if present; or
3. The source file name, without any directory, one suffix removed (if
   it had any), and the platform object file suffix added.

If no source files are present, no dependency information is created
(even with -MF), so we can't fall through case 3.

When multiple source files are present, these rules apply to each
dependency output file separately.  In particular, case 3 yields a
potentially different target name for each dependency output file.

Interestingly, for case 1, the order of -MT versus -MQ is reversed in
GCC-9.3.0, which puts the -MQs first.

In summary: case 2 should be documented.

Reply via email to