+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
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
{
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");
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;
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
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
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
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++
@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
@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
@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
%{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__}}\
%{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 =