]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cppinit.c (init_dependency_output): Take deps output file from -o if none given with...
authorNeil Booth <neil@daikokuya.demon.co.uk>
Mon, 11 Mar 2002 21:38:27 +0000 (21:38 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Mon, 11 Mar 2002 21:38:27 +0000 (21:38 +0000)
preprocessor/3951
* cppinit.c (init_dependency_output): Take deps output file
from -o if none given with -MF.  Suppress normal output.
* gcc.c (cpp_unique_options): Have -M and -MM imply -E.
* doc/cpp.texi, doc/invoke.texi: Update.

From-SVN: r50602

gcc/ChangeLog
gcc/cppinit.c
gcc/doc/cpp.texi
gcc/doc/invoke.texi
gcc/gcc.c

index 01f34607f044ea691e51e269b4be52aab3559fba..9b0831166d1ce0ba9c3fe13eadb9b48f592a98c3 100644 (file)
@@ -1,3 +1,11 @@
+2002-03-11  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       preprocessor/3951
+       * cppinit.c (init_dependency_output): Take deps output file
+       from -o if none given with -MF.  Suppress normal output.
+       * gcc.c (cpp_unique_options): Have -M and -MM imply -E. 
+       * doc/cpp.texi, doc/invoke.texi: Update.
+
 2002-03-01  Zack Weinberg  <zack@codesourcery.com>
 
        * doc/cpp.texi: Clarify documentation of relationship between
index b8f4808a3010f4291beba17dd9faa856968cf479..15962fb304eba9712b4e8adb229b08366214443c 100644 (file)
@@ -981,7 +981,7 @@ output_deps (pfile)
   FILE *deps_stream = 0;
   const char *deps_mode = CPP_OPTION (pfile, print_deps_append) ? "a" : "w";
 
-  if (CPP_OPTION (pfile, deps_file) == 0)
+  if (CPP_OPTION (pfile, deps_file)[0] == '\0')
     deps_stream = stdout;
   else
     {
@@ -999,7 +999,7 @@ output_deps (pfile)
     deps_phony_targets (pfile->deps, deps_stream);
 
   /* Don't close stdout.  */
-  if (CPP_OPTION (pfile, deps_file))
+  if (deps_stream != stdout)
     {
       if (ferror (deps_stream) || fclose (deps_stream) != 0)
        cpp_fatal (pfile, "I/O error on output");
@@ -1736,7 +1736,8 @@ cpp_post_options (pfile)
     cpp_fatal (pfile, "you must additionally specify either -M or -MM");
 }
 
-/* Set up dependency-file output.  */
+/* Set up dependency-file output.  On exit, if print_deps is non-zero
+   then deps_file is not NULL; stdout is the empty string.  */
 static void
 init_dependency_output (pfile)
      cpp_reader *pfile;
@@ -1775,21 +1776,20 @@ init_dependency_output (pfile)
       else
        output_file = spec;
 
-      /* Command line overrides environment variables.  */
+      /* Command line -MF overrides environment variables and default.  */
       if (CPP_OPTION (pfile, deps_file) == 0)
        CPP_OPTION (pfile, deps_file) = output_file;
-      CPP_OPTION (pfile, print_deps_append) = 1;
-    }
 
-  /* If dependencies go to standard output, or -MG is used, we should
-     suppress output, including -dM, -dI etc.  */
-  if (CPP_OPTION (pfile, deps_file) == 0
-      || CPP_OPTION (pfile, print_deps_missing_files))
-    {
-      CPP_OPTION (pfile, no_output) = 1;
-      CPP_OPTION (pfile, dump_macros) = 0;
-      CPP_OPTION (pfile, dump_includes) = 0;
+      CPP_OPTION (pfile, print_deps_append) = 1;
     }
+  else if (CPP_OPTION (pfile, deps_file) == 0)
+    /* If -M or -MM was seen, default output to wherever was specified
+       with -o.  out_fname is non-NULL here.  */
+    CPP_OPTION (pfile, deps_file) = CPP_OPTION (pfile, out_fname);
+
+  /* When doing dependencies, suppress normal preprocessed output.
+     Still do -dM, -dI etc. as e.g. glibc depends on this.  */
+  CPP_OPTION (pfile, no_output) = 1;
 }
 
 static void
index a6b39531d951f19238bf61b40237cbf6871185c3..174b7465964663c13350f4d70c40b48f241d65eb 100644 (file)
@@ -3977,6 +3977,8 @@ suffix replaced with object file suffix.  If there are many included
 files then the rule is split into several lines using @samp{\}-newline.
 The rule has no commands.
 
+Passing @option{-M} to the driver implies @option{-E}.
+
 @item -MM
 Like @option{-M}, but mention only the files included with @code{@w{#include
 "@var{file}"}} or with @option{-include} or @option{-imacros} command line
@@ -3984,10 +3986,14 @@ options.  System header files included with @code{@w{#include <@var{file}>}}
 are omitted.
 
 @item -MF @var{file}
-When used with @option{-M} or @option{-MM}, specifies a file to write the
-dependencies to.  This allows the preprocessor to write the preprocessed
-file to stdout normally.  If no @option{-MF} switch is given, CPP sends
-the rules to stdout and suppresses normal preprocessed output.
+@anchor{-MF}
+When used with @option{-M} or @option{-MM}, specifies a
+file to write the dependencies to.  If no @option{-MF} switch is given
+the preprocessor sends the rules to the same place it would have sent
+preprocessed output.
+
+When used with the driver options @option{-MD} or @option{-MMD},
+@option{-MF} overrides the default dependency output file.
 
 @item -MG
 When used with @option{-M} or @option{-MM}, @option{-MG} says to treat missing
@@ -4040,14 +4046,24 @@ $$(objpfx)foo.o: foo.c
 The default target is automatically quoted, as if it were given with
 @option{-MQ}.
 
-@item -MD @var{file}
-@itemx -MMD @var{file}
-@option{-MD @var{file}} is equivalent to @option{-M -MF @var{file}}, and
-@option{-MMD @var{file}} is equivalent to @option{-MM -MF @var{file}}.
+@item -MD
+@option{-MD} is equivalent to @option{-M -MF @var{file}}, except that
+@option{-E} is not implied.  The driver determines @var{file} based on
+whether an @option{-o} option is given.  If it is, the driver uses its
+argument but with a suffix of @file{.d}, otherwise it take the
+basename of the input file and applies a @file{.d} suffix.
+
+If @option{-MD} is used in conjunction with @option{-E}, any
+@option{-o} switch is understood to specify the dependency output file
+(but @pxref{-MF}), but if used without @option{-E}, each @option{-o}
+is understood to specify a target object file.
+
+Since @option{-E} is not implied, @option{-MD} can be used to generate
+a dependency output file as a side-effect of the compilation process.
 
-Due to limitations in the compiler driver, you must use these switches
-when you want to generate a dependency file as a side-effect of normal
-compilation.
+@item -MMD
+Like @option{-MD} except mention only user header files, not system
+-header files.
 
 @item -x c
 @itemx -x c++
index 437acacfd92dcf129aa2a630ae19484dcb77f56a..8da3e7ea00b6d3789bcd26e07238ad4e2e61d499 100644 (file)
@@ -3865,15 +3865,19 @@ Used with the @option{-E} option.
 @item -M
 @opindex M
 Instead of outputting the result of preprocessing, output a rule
-suitable for @code{make} describing the dependencies of the main source
-file.  The preprocessor outputs one @code{make} rule containing the
-object file name for that source file, a colon, and the names of all the
-included files.  Unless overridden explicitly, the object file name
-consists of the basename of the source file with any suffix replaced with
-object file suffix.  If there are many included files then the
-rule is split into several lines using @samp{\}-newline.
+suitable for @command{make} describing the dependencies of the main
+source file.  The preprocessor outputs one @command{make} rule containing
+the object file name for that source file, a colon, and the names of all
+the included files, including those coming from @option{-include} or
+@option{-imacros} command line options.
 
-@option{-M} implies @option{-E}.
+Unless specified explicitly (with @option{-MT} or @option{-MQ}), the
+object file name consists of the basename of the source file with any
+suffix replaced with object file suffix.  If there are many included
+files then the rule is split into several lines using @samp{\}-newline.
+The rule has no commands.
+
+Passing @option{-M} to the driver implies @option{-E}.
 
 @item -MM
 @opindex MM
@@ -3883,13 +3887,19 @@ Like @option{-M}, but mention only the files included with @samp{#include
 
 @item -MD
 @opindex MD
-Like @option{-M} but the dependency information is written to a file
-rather than stdout.  @code{gcc} will use the same file name and
-directory as the object file, but with the suffix @file{.d} instead.
+@option{-MD} is equivalent to @option{-M -MF @var{file}}, except that
+@option{-E} is not implied.  The driver determines @var{file} based on
+whether an @option{-o} option is given.  If it is, the driver uses its
+argument but with a suffix of @file{.d}, otherwise it take the
+basename of the input file and applies a @file{.d} suffix.
+
+If @option{-MD} is used in conjunction with @option{-E}, any
+@option{-o} switch is understood to specify the dependency output file
+(but @pxref{-MF}), but if used without @option{-E}, each @option{-o}
+is understood to specify a target object file.
 
-This is in addition to compiling the main file as specified---@option{-MD}
-does not inhibit ordinary compilation the way @option{-M} does,
-unless you also specify @option{-MG}.
+Since @option{-E} is not implied, @option{-MD} can be used to generate
+a dependency output file as a side-effect of the compilation process.
 
 With Mach, you can use the utility @code{md} to merge multiple
 dependency files into a single dependency file suitable for using with
@@ -3902,10 +3912,14 @@ Like @option{-MD} except mention only user header files, not system
 
 @item -MF @var{file}
 @opindex MF
-When used with @option{-M} or @option{-MM}, specifies a file to write the
-dependencies to.  This allows the preprocessor to write the preprocessed
-file to stdout normally.  If no @option{-MF} switch is given, CPP sends
-the rules to stdout and suppresses normal preprocessed output.
+@anchor{-MF}
+When used with @option{-M} or @option{-MM}, specifies a
+file to write the dependencies to.  If no @option{-MF} switch is given
+the preprocessor sends the rules to the same place it would have sent
+preprocessed output.
+
+When used with the driver options @option{-MD} or @option{-MMD},
+@option{-MF} overrides the default dependency output file.
 
 Another way to specify output of a @code{make} rule is by setting
 the environment variable @env{DEPENDENCIES_OUTPUT} (@pxref{Environment
index 5c73af4b2c5c4c8c5c1c6d10509fa2bd2d4bc027..5fc54bf23a04e267b04d7437bc10913f67d4a6c6 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -598,7 +598,8 @@ static const char *cpp_options =
  %{C} %{v} %{I*} %{P} %{$} %I\
  %{MD:-M -MF %W{!o: %b.d}%W{o*:%.d%*}}\
  %{MMD:-MM -MF %W{!o: %b.d}%W{o*:%.d%*}}\
- %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
+ %{M} %{MM} %W{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
+ %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ %*}}}}}\
  %{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
  %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
  %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
@@ -610,7 +611,7 @@ static const char *cpp_options =
  %{fleading-underscore} %{fno-leading-underscore}\
  %{fno-operator-names} %{ftabstop=*} %{remap}\
  %{g3:-dD} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*&U*&A*} %{i*} %Z %i\
- %{E:%{!M*:%W{o*}}}";
+ %{E|M|MM:%W{o*}}";
 
 /* NB: This is shared amongst all front-ends.  */
 static const char *cc1_options =