This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Recognize '-' as special -MF argument (write to stdout)
- From: Boris Kolpackov <boris at codesynthesis dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 15 May 2017 09:54:32 +0200
- Subject: [PATCH] Recognize '-' as special -MF argument (write to stdout)
- Authentication-results: sourceware.org; auth=none
Hi,
Sometimes it is useful to generate pre-processed output to a file and
the dependency information to stdout for further analysis/processing.
For example:
g++ -E -MD -fdirectives-only -o test.ii test.cxx
This will generate the dependency information to test.d (as per the
documentation). While changing this behavior is probably unwise, one
traditional (e.g., supported by -o) way to handle this is to recognize
the special '-' file name as an instruction to write to stdout:
g++ -E -MD -fdirectives-only -o test.ii -MF - test.cxx
Currently this will create a file named '-'. The included patch changes
this behavior to write to stdout.
Note also that Clang has supported this from at least version 3.5.
The patch should apply cleanly to trunk. I would also like to see it
backported to previous versions, if possible. If this requires any
additional work, I am willing to do it.
Thanks,
Boris
Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog (revision 247825)
+++ gcc/ChangeLog (working copy)
@@ -1,3 +1,6 @@
+
+ * doc/cppopts.texi: Document '-' special value to -MF.
+
2017-05-09 Marek Polacek <polacek@redhat.com>
* doc/invoke.texi: Fix typo.
Index: gcc/c-family/ChangeLog
===================================================================
--- gcc/c-family/ChangeLog (revision 247825)
+++ gcc/c-family/ChangeLog (working copy)
@@ -1,3 +1,6 @@
+
+ * c-opts.c (c_common_finish): Handle '-' special value to -MF.
+
2017-05-09 Marek Polacek <polacek@redhat.com>
PR c/80525
Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c (revision 247825)
+++ gcc/c-family/c-opts.c (working copy)
@@ -1164,6 +1164,8 @@
output stream. */
if (!deps_file)
deps_stream = out_stream;
+ else if (deps_file[0] == '-' && deps_file[1] == '\0')
+ deps_stream = stdout;
else
{
deps_stream = fopen (deps_file, deps_append ? "a": "w");
@@ -1177,7 +1179,7 @@
with cpp_destroy (). */
cpp_finish (parse_in, deps_stream);
- if (deps_stream && deps_stream != out_stream
+ if (deps_stream && deps_stream != out_stream && deps_stream != stdout
&& (ferror (deps_stream) || fclose (deps_stream)))
fatal_error (input_location, "closing dependency file %s: %m", deps_file);
Index: gcc/doc/cppopts.texi
===================================================================
--- gcc/doc/cppopts.texi (revision 247825)
+++ gcc/doc/cppopts.texi (working copy)
@@ -125,6 +125,8 @@
When used with the driver options @option{-MD} or @option{-MMD},
@option{-MF} overrides the default dependency output file.
+If @var{file} is @file{-}, then the dependencies are written to @file{stdout}.
+
@item -MG
@opindex MG
In conjunction with an option such as @option{-M} requesting