Hi!

This patch makes the -fdiagnostics-color= default configurable, and
changes the default (if no configure option is specified for it)
to --with-diagnostics-color=auto.  The previous behavior can be
restored with --with-diagnostics-color=auto-if-env , the 4.8
behavior (never coloring anything) with --with-diagnostics-color=never .
Bootstrapped/regtested on x86_64-linux and i686-linux and tested with
all 5 different configure options (the four explicit one and without).
Ok for trunk?

2014-11-12  Jakub Jelinek  <ja...@redhat.com>

        * configure.ac (--with-diagnostics-color): New configure
        option, default to --with-diagnostics-color=auto.
        * toplev.c (process_options): Use DIAGNOSTICS_COLOR_DEFAULT
        to determine -fdiagnostics-color= option default.
        * doc/invoke.texi (-fdiagnostics-color=): Document new
        default.
        * configure: Regenerated.
        * config.in: Regenerated.

--- gcc/configure.ac.jj 2014-11-12 08:06:56.000000000 +0100
+++ gcc/configure.ac    2014-11-12 20:28:32.379823251 +0100
@@ -5608,6 +5608,34 @@ if test x"${LINKER_HASH_STYLE}" != x; th
                                          [The linker hash style])
 fi
 
+# Specify what should be the default of -fdiagnostics-color option.
+AC_ARG_WITH([diagnostics-color],
+[AC_HELP_STRING([--with-diagnostics-color={never,auto,auto-if-env,always}],
+                [specify the default of -fdiagnostics-color option
+                 auto-if-env stands for -fdiagnostics-color=auto if
+                 GCC_COLOR environment variable is present and
+                 -fdiagnostics-color=never otherwise])],
+[case x"$withval" in
+   xnever)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_NO
+     ;;
+   xauto)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_AUTO
+     ;;
+   xauto-if-env)
+     DIAGNOSTICS_COLOR_DEFAULT=-1
+     ;;
+   xalways)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_YES
+     ;;
+   *)
+     AC_MSG_ERROR([$withval is an invalid option to --with-diagnostics-color])
+     ;;
+ esac],
+[DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_AUTO])
+AC_DEFINE_UNQUOTED(DIAGNOSTICS_COLOR_DEFAULT, $DIAGNOSTICS_COLOR_DEFAULT,
+                  [The default for -fdiagnostics-color option])
+
 # Generate gcc-driver-name.h containing GCC_DRIVER_NAME for the benefit
 # of jit/jit-playback.c.
 cat > gcc-driver-name.h <<EOF
--- gcc/toplev.c.jj     2014-11-12 08:06:55.000000000 +0100
+++ gcc/toplev.c        2014-11-12 20:25:00.345096573 +0100
@@ -1264,12 +1264,28 @@ process_options (void)
 
   maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
 
-  /* Default to -fdiagnostics-color=auto if GCC_COLORS is in the environment,
-     otherwise default to -fdiagnostics-color=never.  */
-  if (!global_options_set.x_flag_diagnostics_show_color
-      && getenv ("GCC_COLORS"))
-    pp_show_color (global_dc->printer)
-      = colorize_init (DIAGNOSTICS_COLOR_AUTO);
+  /* If DIAGNOSTICS_COLOR_DEFAULT is -1, default to -fdiagnostics-color=auto
+     if GCC_COLORS is in the environment, otherwise default to
+     -fdiagnostics-color=never, for other values default to that
+     -fdiagnostics-color={never,auto,always}.  */
+  if (!global_options_set.x_flag_diagnostics_show_color)
+    switch ((int) DIAGNOSTICS_COLOR_DEFAULT)
+      {
+      case -1:
+       if (!getenv ("GCC_COLORS"))
+         break;
+       /* FALLTHRU */
+      case DIAGNOSTICS_COLOR_AUTO:
+       pp_show_color (global_dc->printer)
+         = colorize_init (DIAGNOSTICS_COLOR_AUTO);
+       break;
+      case DIAGNOSTICS_COLOR_YES:
+       pp_show_color (global_dc->printer)
+         = colorize_init (DIAGNOSTICS_COLOR_YES);
+       break;
+      default:
+       break;
+      }
 
   /* Allow the front end to perform consistency checks and do further
      initialization based on the command line options.  This hook also
--- gcc/doc/invoke.texi.jj      2014-11-12 08:06:54.000000000 +0100
+++ gcc/doc/invoke.texi 2014-11-12 20:20:58.802642925 +0100
@@ -3103,8 +3103,10 @@ a message which is too long to fit on a
 @cindex highlight, color, colour
 @vindex GCC_COLORS @r{environment variable}
 Use color in diagnostics.  @var{WHEN} is @samp{never}, @samp{always},
-or @samp{auto}.  The default is @samp{never} if @env{GCC_COLORS} environment
-variable isn't present in the environment, and @samp{auto} otherwise.
+or @samp{auto}.  The default depends on how the compiler has been configured,
+it can be any of the above @var{WHEN} options or also @samp{never}
+if @env{GCC_COLORS} environment variable isn't present in the environment,
+and @samp{auto} otherwise.
 @samp{auto} means to use color only when the standard error is a terminal.
 The forms @option{-fdiagnostics-color} and @option{-fno-diagnostics-color} are
 aliases for @option{-fdiagnostics-color=always} and
--- gcc/configure.jj    2014-11-12 08:06:54.000000000 +0100
+++ gcc/configure       2014-11-12 20:28:49.364032302 +0100
@@ -935,6 +935,7 @@ enable_plugin
 enable_host_shared
 enable_libquadmath_support
 with_linker_hash_style
+with_diagnostics_color
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1709,6 +1710,11 @@ Optional Packages:
   --with-system-zlib      use installed libz
   --with-linker-hash-style={sysv,gnu,both}
                           specify the linker hash style
+  --with-diagnostics-color={never,auto,auto-if-env,always}
+                          specify the default of -fdiagnostics-color option
+                          auto-if-env stands for -fdiagnostics-color=auto if
+                          GCC_COLOR environment variable is present and
+                          -fdiagnostics-color=never otherwise
 
 Some influential environment variables:
   CC          C compiler command
@@ -18100,7 +18106,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18103 "configure"
+#line 18109 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18206,7 +18212,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18209 "configure"
+#line 18215 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -28227,6 +28233,37 @@ _ACEOF
 
 fi
 
+# Specify what should be the default of -fdiagnostics-color option.
+
+# Check whether --with-diagnostics-color was given.
+if test "${with_diagnostics_color+set}" = set; then :
+  withval=$with_diagnostics_color; case x"$withval" in
+   xnever)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_NO
+     ;;
+   xauto)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_AUTO
+     ;;
+   xauto-if-env)
+     DIAGNOSTICS_COLOR_DEFAULT=-1
+     ;;
+   xalways)
+     DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_YES
+     ;;
+   *)
+     as_fn_error "$withval is an invalid option to --with-diagnostics-color" 
"$LINENO" 5
+     ;;
+ esac
+else
+  DIAGNOSTICS_COLOR_DEFAULT=DIAGNOSTICS_COLOR_AUTO
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define DIAGNOSTICS_COLOR_DEFAULT $DIAGNOSTICS_COLOR_DEFAULT
+_ACEOF
+
+
 # Generate gcc-driver-name.h containing GCC_DRIVER_NAME for the benefit
 # of jit/jit-playback.c.
 cat > gcc-driver-name.h <<EOF
--- gcc/config.in.jj    2014-11-11 00:06:11.000000000 +0100
+++ gcc/config.in       2014-11-12 20:25:48.000000000 +0100
@@ -51,6 +51,12 @@
 #endif
 
 
+/* The default for -fdiagnostics-color option */
+#ifndef USED_FOR_TARGET
+#undef DIAGNOSTICS_COLOR_DEFAULT
+#endif
+
+
 /* Define if you want assertions enabled. This is a cheap check. */
 #ifndef USED_FOR_TARGET
 #undef ENABLE_ASSERT_CHECKING

        Jakub

Reply via email to