[gnu.gcc.bug] gcc-cpp problem with SunOS4.0 make

ji@CS.COLUMBIA.EDU (John Ioannidis) (02/08/89)

I came accross a problem concerning the interaction of gcc (actually,
the preprocessor) with the SunOS 4.0 new and improved make: it would
correctly figure out hidden dependencies when using sun's cc, but would
ignore them when told to use gcc. 

After countless hours of reading through sources, experimenting with
fake cpp's and cc's and so on, I found out how make(1) would get the
dependencies list (see, it wasn't invoking the cc twice, once with the
-M and once without, and I knew it would have something to do with the
compiler and not with make 'cause otherwise there wouldn't be a
problem when switching compilers). To make a long story short, this is
what I found:

When the special target .KEEP_STATE: is present in the makefile,
make(1) will set the environment variable SUNPRO_DEPENDENCIES to
contain the name of a file where it wants the dependencies to be
written.  /lib/cpp (and other programs, like cc itself) uses this
variable to pass back said dependencies. (the variable also contains a
prefix to use when writing dependencies; try this:
	$ SUNPRO_DEPENDENCIES="foo bar" /lib/cpp foo.c > /dev/null
where foo.c contains some #includes. Then examine the contents of file foo)

Needless to say, this is undocumented, and might change in future
releases. Meanwhile, I had to make gcc cooperate with make(1), so I
patched the new /lib/cpp functionality into cccp.c (the gnu c
preprocessor). gcc also needs to be changed so that it will output the
dependencies on /lib/crt0.o and stuff, but I didn't deem this to be
critical so I didn't do it.

Here are the context diff's for gcc-cpp version 1.27. It should be
fairly easy to incorporate them in later releases -- I'll do that for
1.33 sometime next month! 

I'm posting this in sun-spots (since it obviously concerns SunOS
users) and to bug-gcc just in case the powers-that-be decide to
include it in future releases!


To enable the pathces, you have to define SUNPRO_DEP_HACK in your
config-sun4.h file.

------>8---->8---->8---->8---->8----cut-here---->8---->8---->8---->8---->8----
*** cccp.c.orig	Tue Feb  7 17:28:09 1989
--- cccp.c	Tue Feb  7 17:19:58 1989
***************
*** 562,567 ****
--- 562,578 ----
  /* Number of bytes since the last newline.  */
  int deps_column;
  
+ /* sunpro-dependencies stuff */
+ 
+ #ifdef SUNPRO_DEP_HACK
+ 
+ int sunpro_deps = 0;			/* flag */
+ FILE *sunpro_file;			/* I trust stdio buffering more */
+ char *sunpro_env;			/* the environ var */
+ char *sunpro_space;			/* the space char, also b4 suffix */
+ 
+ #endif
+ 
  /* Nonzero means -I- has been seen,
     so don't look for #include "foo" the source-file directory.  */
  int ignore_srcdir;
***************
*** 798,803 ****
--- 809,835 ----
      }
    }
  
+ #ifdef SUNPRO_DEP_HACK
+ 
+   /* initialize the sunpro file, ignoring errors */
+ 
+   if (sunpro_env = (char *)getenv("SUNPRO_DEPENDENCIES")) 
+     if (sunpro_space = (char *)index(sunpro_env, ' '))
+     {
+ 	    *sunpro_space = '\0';
+ 	    sunpro_file = fopen(sunpro_env, "a");
+ 	    
+ 	    if (sunpro_file)
+ 	    {
+ 		    sunpro_deps = 1;
+ 	    
+ 		    *sunpro_space++ = ' '; /* restore it, you never know */
+ 		    fprintf(sunpro_file, "%s:", sunpro_space);
+ 	    }
+     }
+   
+ #endif
+ 
    /* Now that dollars_in_ident is known, initialize is_idchar.  */
    initialize_char_syntax ();
  
***************
*** 987,992 ****
--- 1019,1036 ----
    else if (write (fileno (stdout), outbuf.buf, outbuf.bufp - outbuf.buf) < 0)
      fatal ("I/O error on output");
  
+ #ifdef SUNPRO_DEP_HACK
+ 
+   /* stick a final newline in the file and close it */
+ 
+   if (sunpro_deps)
+   {
+ 	  putc('\n', sunpro_file);
+ 	  fclose(sunpro_file);
+   }
+   
+ #endif
+ 
    if (ferror (stdout))
      fatal ("I/O error on output");
  
***************
*** 2446,2451 ****
--- 2490,2507 ----
        deps_output (fname, strlen (fname));
        deps_output (" ", 0);
      }
+ 
+ #ifdef SUNPRO_DEP_HACK
+ 
+   /* For SUNPRO_DEPENDENCIES, append the name of the included file. */
+ 
+   if (sunpro_deps)
+     {
+       fputs(fname, sunpro_file);	/* I guess this is faster */
+       putc(' ', sunpro_file);		/* than fprintf! */
+     }
+ 
+ #endif  
  
    if (f < 0) {
      strncpy (fname, fbeg, flen);
------>8---->8---->8---->8---->8----cut-here---->8---->8---->8---->8---->8----


#include <appropriate disclaimers>

In-Real-Life: John Ioannidis
E-Mail-To: <ji@cs.columbia.edu> (preferred), or <ji@walkuere.altair.fr>
P-Mail-To: GIP-Altair, Dom de Voluceau BP105, Rocquencourt 78153 Le Chesnay, FR
V-Mail-To: +33 1 39635227, +33 1 39635417

		... It's all greek to me

rms@WHEATIES.AI.MIT.EDU (Richard Stallman) (02/08/89)

I believe GCC 1.33 contains that feature already.