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]
Other format: [Raw text]

[PATCH] add GCC_OPTIONS


This patch takes an idea from GNU Grep and adds support for the
"GCC_OPTIONS" environmental variable.  This is *very* useful when one is
building a read-only source base and one needs to tweak the options used
by GCC.  Examples are adding -g, -save-temps, -v, or -m32.

Unfortunately the more direct "env CC='gcc -g' make" often doesn't work
as developers frightening often hard code "CC=gcc" in Makefiles, or worse
just use "gcc" directly in the target's build rules.

OK to commit to main-line?



2003-06-25  David O'Brien  <obrien@FreeBSD.org>

	* gcc.c (GCC_OPTIONS): New environmental variable.

Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.382
diff -u -r1.382 gcc.c
--- gcc.c	23 Jun 2003 15:27:36 -0000	1.382
+++ gcc.c	25 Jun 2003 19:30:06 -0000
@@ -3366,6 +3366,44 @@
 	}
     }
 
+  /* Options specified as if they appeared on the command line.  */
+  temp = getenv ("GCC_OPTIONS");
+  if ((temp) && (strlen (temp) > 0))
+    {
+      int len;
+      int optc = 1;
+      int new_argc;
+      const char **new_argv;
+      char *envopts;
+
+      while (isspace (*temp))
+	temp++;
+      len = strlen (temp);
+      envopts = (char *) xmalloc (len + 1);
+      strcpy (envopts, temp);
+
+      for (i = 0; i < (len - 1); i++)
+	if ((isspace (envopts[i])) && ! (isspace (envopts[i+1])))
+	  optc++;
+
+      new_argv = (const char **) alloca ((optc + argc) * sizeof(char *));
+
+      for (i = 0, new_argc = 1; new_argc <= optc; new_argc++)
+	{
+	  while (isspace (envopts[i]))
+	    i++;
+	  new_argv[new_argc] = envopts + i;
+	  while (!isspace (envopts[i]) && (envopts[i] != '\0'))
+	    i++;
+	  envopts[i++] = '\0';
+	}
+      for (i = 1; i < argc; i++)
+	new_argv[new_argc++] = argv[i];
+
+      argv = new_argv;
+      argc = new_argc;
+    }
+
   /* Convert new-style -- options to old-style.  */
   translate_options (&argc, &argv);
 


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