summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/cppinit.c30
-rw-r--r--gcc/doc/cpp.texi38
-rw-r--r--gcc/doc/invoke.texi50
-rw-r--r--gcc/gcc.c5
5 files changed, 85 insertions, 45 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e5bc35e6e3f..22577cd8da3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2002-02-20 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * 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-02-19 Zack Weinberg <zack@codesourcery.com>
* toplev.c (output_quoted_string): Write unprintable
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index b5ad93719e4..efaf3166afb 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -1084,7 +1084,7 @@ output_deps (pfile)
const char *const 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
{
@@ -1835,7 +1835,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;
@@ -1874,21 +1875,22 @@ init_dependency_output (pfile)
else
output_file = spec;
- /* Command line overrides environment variables. */
- if (CPP_OPTION (pfile, deps_file) == 0)
- CPP_OPTION (pfile, deps_file) = output_file;
CPP_OPTION (pfile, print_deps_append) = 1;
}
+ else
+ /* If -M or -MM was seen, default output to wherever was specified
+ with -o. out_fname is non-NULL here. */
+ output_file = CPP_OPTION (pfile, out_fname);
- /* 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;
- }
+ /* Command line -MF overrides environment variables and default. */
+ if (CPP_OPTION (pfile, deps_file) == 0)
+ CPP_OPTION (pfile, deps_file) = output_file;
+
+ /* When doing dependencies, we should suppress all output, including
+ -dM, -dI etc. */
+ CPP_OPTION (pfile, no_output) = 1;
+ CPP_OPTION (pfile, dump_macros) = 0;
+ CPP_OPTION (pfile, dump_includes) = 0;
}
/* Handle --help output. */
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 3572384613c..f22e855d993 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -3956,6 +3956,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
@@ -3963,10 +3965,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
@@ -4019,14 +4025,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++
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 10d9521ec96..a0e44d584a5 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4029,15 +4029,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
@@ -4047,13 +4051,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
@@ -4066,10 +4076,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
diff --git a/gcc/gcc.c b/gcc/gcc.c
index ae4bc6379be..1fcd8f32822 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -665,7 +665,8 @@ static const char *cpp_unique_options =
%{nostdinc*} %{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*} %{!E:%{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}\
%{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
@@ -674,7 +675,7 @@ static const char *cpp_unique_options =
%{ffreestanding:-D__STDC_HOSTED__=0} %{fno-hosted:-D__STDC_HOSTED__=0}\
%{!ffreestanding:%{!fno-hosted:-D__STDC_HOSTED__=1}} %{remap}\
%{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i\
- %{E:%W{o*}}";
+ %{E|M|MM:%W{o*}}";
/* This contains cpp options which are common with cc1_options and are passed
only when preprocessing only to avoid duplication. */