This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [CPP patch]: -M default name
Neil Booth wrote:-
> * cppinit.c (cpp_start_read): Don't fix out_fname here, ...
> (cpp_post_options): ... but here.
> (init_dependency_output): Send any output to stdout if
> we're generating dependencies.
> * cpplib.h: Update comment.
> * cppmain.c (printer_init): Remove redundant check.
>
> * gcc.c (cpp_options): Don't delete output file on error
> with -M and -MM.
Here's the patch with the C++ stuff in my tree deleted. Sorry for the
confusion.
Neil.
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.204
diff -u -p -r1.204 gcc.c
--- gcc.c 2001/02/07 18:58:05 1.204
+++ gcc.c 2001/02/08 19:26:46
@@ -606,7 +606,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:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}";
+ %{E:%W{o*}}";
/* NB: This is shared amongst all front-ends. */
static const char *cc1_options =
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.147
diff -u -p -r1.147 cppinit.c
--- cppinit.c 2001/02/07 18:32:41 1.147
+++ cppinit.c 2001/02/08 19:27:05
@@ -915,8 +917,6 @@ cpp_start_read (pfile, fname)
if (CPP_OPTION (pfile, in_fname) == NULL)
CPP_OPTION (pfile, in_fname) = "";
}
- if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
if (CPP_OPTION (pfile, print_deps))
/* Set the default target (if there is none already). */
@@ -1697,6 +1697,10 @@ cpp_post_options (pfile)
if (CPP_OPTION (pfile, user_label_prefix) == NULL)
CPP_OPTION (pfile, user_label_prefix) = USER_LABEL_PREFIX;
+ /* Guarantee out_fname is non-null, before init_dependency_output. */
+ if (CPP_OPTION (pfile, out_fname) == NULL)
+ CPP_OPTION (pfile, out_fname) = "";
+
/* We need to do this after option processing and before
cpp_start_read, as cppmain.c relies on the options->no_output to
set its callbacks correctly before calling cpp_start_read. */
@@ -1755,6 +1759,10 @@ init_dependency_output (pfile)
CPP_OPTION (pfile, deps_file) = output_file;
CPP_OPTION (pfile, print_deps_append) = 1;
}
+
+ /* We might be invoked as "gcc -M foo.c -o foo.o". With "foo.o" in
+ out_fname, cppmain.c will truncate it unless we catch it here. */
+ CPP_OPTION (pfile, out_fname) = "";
/* If dependencies go to standard output, or -MG is used, we should
suppress output. The user may be requesting other stuff to
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.163
diff -u -p -r1.163 cpplib.h
--- cpplib.h 2001/02/04 08:29:46 1.163
+++ cpplib.h 2001/02/08 19:27:14
@@ -514,7 +514,8 @@ extern void cpp_set_callbacks PARAMS ((c
understand the next switch. When there are no switches left, you
must call cpp_post_options before calling cpp_start_read. Only
after cpp_post_options are the contents of the cpp_options
- structure reliable. */
+ structure reliable. cpp_post_options guarantees that out_fname is
+ non-null on returning; an empty string means stdout. */
extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
extern void cpp_post_options PARAMS ((cpp_reader *));
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.61
diff -u -p -r1.61 cppmain.c
--- cppmain.c 2001/02/01 19:13:53 1.61
+++ cppmain.c 2001/02/08 19:27:14
@@ -271,9 +271,6 @@ printer_init (pfile)
print.lineno = 0;
print.printed = 0;
- if (options->out_fname == NULL)
- options->out_fname = "";
-
if (options->out_fname[0] == '\0')
print.outf = stdout;
else