From a9374841850fb444b6de78ff169b88dc03766d83 Mon Sep 17 00:00:00 2001
From: Mark Mitchell <mark@codesourcery.com>
Date: Wed, 7 Feb 2001 18:58:07 +0000
Subject: [PATCH] defaults.h (CPLUSPLUS_CPP_SPEC): New macro.

	* defaults.h (CPLUSPLUS_CPP_SPEC): New macro.
	* gcc.c (struct compiler): Add cpp_spec field.
	(input_file_compiler): New variable.
	(do_spec_1): Allow a particular compiler to handle `%C'
	specially.
	(main): Store the current compiler in input_file_compiler.
	* tm.texi (CPLUSPLUS_CPP_SPEC): Document.

	* lang-specs.h: Use CPLUSPLUS_CPP_SPEC for the preprocessor
	spec.

From-SVN: r39524
---
 gcc/ChangeLog       | 10 ++++++++++
 gcc/cp/ChangeLog    |  5 +++++
 gcc/cp/lang-specs.h |  3 +++
 gcc/defaults.h      |  8 ++++++++
 gcc/gcc.c           | 35 ++++++++++++++++++++++++-----------
 gcc/tm.texi         |  6 ++++++
 6 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2f385b7ccae..285097e2624 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2001-02-07  Mark Mitchell  <mark@codesourcery.com>
+
+	* defaults.h (CPLUSPLUS_CPP_SPEC): New macro.
+	* gcc.c (struct compiler): Add cpp_spec field.
+	(input_file_compiler): New variable.
+	(do_spec_1): Allow a particular compiler to handle `%C' 
+	specially.
+	(main): Store the current compiler in input_file_compiler.
+	* tm.texi (CPLUSPLUS_CPP_SPEC): Document.
+	
 2001-02-07  Zack Weinberg  <zack@wolery.stanford.edu>
 
 	* cpphash.h (struct spec_nodes): Add n_true and n_false.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 29901cb26fb..6f756a4976c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2001-02-07  Mark Mitchell  <mark@codesourcery.com>
+
+	* lang-specs.h: Use CPLUSPLUS_CPP_SPEC for the preprocessor 
+	spec.
+
 2001-02-06  Nathan Sidwell  <nathan@codesourcery.com>
 
 	* pt.c (lookup_template_class): Make sure it's a primary
diff --git a/gcc/cp/lang-specs.h b/gcc/cp/lang-specs.h
index 210255e3e8b..cfcac347487 100644
--- a/gcc/cp/lang-specs.h
+++ b/gcc/cp/lang-specs.h
@@ -67,6 +67,9 @@ Boston, MA 02111-1307, USA.  */
        %{ansi:-trigraphs -$}\
        %(cc1_options) %2 %{+e*}\
        %{!fsyntax-only:%(invoke_as)}}}}"
+#endif
+#ifdef CPLUSPLUS_CPP_SPEC
+     , CPLUSPLUS_CPP_SPEC
 #endif
      },
   {".ii", "@c++-cpp-output"},
diff --git a/gcc/defaults.h b/gcc/defaults.h
index c1c938b5c0c..20ea99ab62c 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -296,5 +296,13 @@ do {								\
 #define BUILD_VA_LIST_TYPE(X) ((X) = ptr_type_node)
 #endif
 
+/* By default, the preprocessor should be invoked the same way in C++
+   as in C.  */
+#ifndef CPLUSPLUS_CPP_SPEC
+#ifdef CPP_SPEC
+#define CPLUSPLUS_CPP_SPEC CPP_SPEC
+#endif
+#endif
+
 #endif  /* GCC_DEFAULTS_H */
 
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 9a7a9419d69..51213c1c165 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -698,6 +698,10 @@ struct compiler
 				   whose names end in this suffix.  */
 
   const char *spec;		/* To use this compiler, run this spec.  */
+
+  const char *cpp_spec;         /* If non-NULL, substitute this spec
+				   for `%C', rather than the usual
+				   cpp_spec.  */
 };
 
 /* Pointer to a vector of `struct compiler' that gives the spec for
@@ -3870,6 +3874,9 @@ static int suffixed_basename_length;
 static const char *input_basename;
 static const char *input_suffix;
 
+/* The compiler used to process the current input file.  */
+static struct compiler *input_file_compiler;
+
 /* These are variables used within do_spec and do_spec_1.  */
 
 /* Nonzero if an arg has been started and not yet terminated
@@ -4441,9 +4448,15 @@ do_spec_1 (spec, inswitch, soft_matched_part)
 	    break;
 
 	  case 'C':
-	    value = do_spec_1 (cpp_spec, 0, NULL_PTR);
-	    if (value != 0)
-	      return value;
+	    {
+	      const char* spec 
+		= (input_file_compiler->cpp_spec 
+		   ? input_file_compiler->cpp_spec 
+		   : cpp_spec);
+	      value = do_spec_1 (spec, 0, NULL_PTR);
+	      if (value != 0)
+		return value;
+	    }
 	    break;
 
 	  case 'E':
@@ -5795,7 +5808,6 @@ main (argc, argv)
 
   for (i = 0; (int) i < n_infiles; i++)
     {
-      register struct compiler *cp = 0;
       int this_file_error = 0;
 
       /* Tell do_spec what to substitute for %i.  */
@@ -5809,17 +5821,18 @@ main (argc, argv)
 
       /* Figure out which compiler from the file's suffix.  */
 
-      cp = lookup_compiler (infiles[i].name, input_filename_length,
-			    infiles[i].language);
-
-      if (cp)
+      input_file_compiler
+	= lookup_compiler (infiles[i].name, input_filename_length,
+			   infiles[i].language);
+      
+      if (input_file_compiler)
 	{
 	  /* Ok, we found an applicable compiler.  Run its spec.  */
 
-	  if (cp->spec[0] == '#')
+	  if (input_file_compiler->spec[0] == '#')
 	    error ("%s: %s compiler not installed on this system",
-		   input_filename, &cp->spec[1]);
-	  value = do_spec (cp->spec);
+		   input_filename, &input_file_compiler->spec[1]);
+	  value = do_spec (input_file_compiler->spec);
 	  if (value < 0)
 	    this_file_error = 1;
 	}
diff --git a/gcc/tm.texi b/gcc/tm.texi
index b8af796d067..d6557b861f8 100644
--- a/gcc/tm.texi
+++ b/gcc/tm.texi
@@ -109,6 +109,12 @@ give to GCC into options for GCC to pass to the CPP.
 
 Do not define this macro if it does not need to do anything.
 
+@findex CPLUSPLUS_CPP_SPEC
+@item CPLUSPLUS_CPP_SPEC
+This macro is just like @code{CPP_SPEC}, but is used for C++, rather
+than C.  If you do not define this macro, then the value of
+@code{CPP_SPEC} (if any) will be used instead.
+
 @findex NO_BUILTIN_SIZE_TYPE
 @item NO_BUILTIN_SIZE_TYPE
 If this macro is defined, the preprocessor will not define the builtin macro
-- 
2.30.2