This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [CPP patch]: -M default name


OK, I'm starting to understand this better now.  The CPP specs are
somewhat convoluted, what with cppspec.c joining in the fun by stealth
too.

"cpp" inserts "-E" in the command line before driver spec processing;
this is done by cppspec.c.  "gcc" does not do this as it does not use
cppspec.c.

Note the way cpp gives double -o test.o below, as well as the -MQ
test.o.  We don't want any "-o" options to get to cpp0.

bash-2.04$ cpp -M test.c -o test.o -v
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.97/specs
Configured with: ../configure --enable-shared --disable-checking
--enable-threads=posix : (reconfigured)
gcc version 2.97 20010205 (experimental)
 /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.97/cpp0 -lang-c -v -M -MQ
test.o -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__
-D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -Acpu=i386
-Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i586__
-D__tune_pentium__ test.c -o test.o -o test.o

This is all caused by the spec in gcc.c that reads

%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}";

This spec is completely wrong, if I understand what's going on at all.
My original understanding was that the %W merely indicates to the
driver to delete the final -o option.  In fact, it also supplies the
-o options.  Therefore, the above line was causing the -o option to be
output twice - once for the "-E" and once for the "-M".

As I said in the previous mail, the %W is not wanted at all for the
-M/-MM/-MD/-MMD options, since it's not the ".o" file that is our
output; ".d" is.  Instead I think what we need is the patch below.

o We only destroy the .o file in the abscence of -M, -MM, -MMD and -MD.
o We destroy the .d file by insertion of %W in the appropriate places;
  one for each of -MD, -MMD and -MF.  This makes the specs even
  prettier than they already are <g>.

Does the above sound convincing?  It has boiled it down to a pure
specs issue; I don't think we need to change cpp0 at all (though it
still needs a cleanup in the in_fname and out_fname area).

If the patch below bootstraps, and has the required behaviour for a
few simple tests, I'll commit it unless you shout Zack.

Neil.

	* gcc.c (cpp_options): Delete .d files on error.  Don't delete
	.o files when using the -M options.

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 21:24:42
@@ -593,8 +593,9 @@ static const char *cpp_options =
 "%{C:%{!E:%eGNU C does not support -C without using -E}}\
  %{std*} %{nostdinc*}\
  %{C} %{v} %{I*} %{P} %{$} %I\
- %{MD:-M -MF %{!o: %b.d}%{o*:%.d%*}} %{MMD:-MM -MF %{!o: %b.d}%{o*:%.d%*}}\
- %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|MMD:%{o*:-MQ %*}}\
+ %{MD:-M -MF %W{%{!o: %b.d}%{o*:%.d%*}}}\
+ %{MMD:-MM -MF %W{%{!o: %b.d}%{o*:%.d%*}}}\
+ %{M} %{MM} %W{%{MF*}} %{MG} %{MP} %{MQ*} %{MT*} %{M|MD|MM|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__}}\
@@ -606,7 +607,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:%{!M*:%W{o*}}}";
 
 /* NB: This is shared amongst all front-ends.  */
 static const char *cc1_options =

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]