http://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=105&set=custom
+* New variables: $(MAKE_TTYOUT) and $(MAKE_TTYERR) are set if stdout or
+ stderr, respectively, are believed to be writing to a terminal.
+
* Allow a no-text-argument form of the $(file ...) function. Without a text
argument nothing is written to the file: it is simply opened in the
requested mode, then closed again.
/* Define if you have the kstat library (-lkstat). */
/* #undef HAVE_LIBKSTAT */
+/* Define to 1 if you have the `isatty' function. */
+/* #undef HAVE_ISATTY */
+
+/* Define to 1 if you have the `ttyname' function. */
+/* #undef HAVE_TTYNAME */
+
/* Define if you have the sun library (-lsun). */
/* #undef HAVE_LIBSUN */
/* Define to 1 if you have the sun library (-lsun). */
/* #undef HAVE_LIBSUN */
+/* Define to 1 if you have the `isatty' function. */
+/* #undef HAVE_ISATTY */
+
+/* Define to 1 if you have the `ttyname' function. */
+/* #undef HAVE_TTYNAME */
+
/* Use high resolution file timestamps if nonzero. */
#define FILE_TIMESTAMP_HI_RES 0
/* Define to 1 if you have the 'strsignal' function. */
/* #undef HAVE_STRSIGNAL */
+/* Define to 1 if you have the `isatty' function. */
+#define HAVE_ISATTY 1
+
+/* Define to 1 if you have the `ttyname' function. */
+/* #undef HAVE_TTYNAME */
+
/* Define to 1 if 'n_un.n_name' is a member of 'struct nlist'. */
/* #undef HAVE_STRUCT_NLIST_N_UN_N_NAME */
dup dup2 getcwd realpath sigsetmask sigaction \
getgroups seteuid setegid setlinebuf setreuid setregid \
getrlimit setrlimit setvbuf pipe strerror strsignal \
- lstat readlink atexit])
+ lstat readlink atexit isatty ttyname])
# We need to check declarations, not just existence, because on Tru64 this
# function is not declared without special flags, which themselves cause
this is not the same as recursion (counted by the @code{MAKELEVEL}
variable). You should not set, modify, or export this variable.
+@vindex MAKE_TTYOUT @r{(whether stdout is a terminal)}
+@vindex MAKE_TTYERR @r{(whether stderr is a terminal)}
+@item MAKE_TTYOUT
+@itemx MAKE_TTYERR
+When @code{make} starts it will check whether stdout and stderr will
+show their output on a terminal. If so, it will set
+@code{MAKE_TTYOUT} and @code{MAKE_TTYERR}, respectively, to the name
+of the terminal device (or @code{true} if this cannot be determined).
+If set these variables will be marked for export. These variables
+will not be changed by @code{make} and they will not be modified if
+already set.
+
+These values can be used (particularly in combination with output
+synchronization (@pxref{Parallel Output, ,Output During Parallel
+Execution}) to determine whether @code{make} itself is writing to a
+terminal; they can be tested to decide whether to force recipe
+commands to generate colorized output for example.
+
+If you invoke a sub-@code{make} and redirect its stdout or stderr it
+is your responsibility to reset or unexport these variables as well,
+if your makefiles rely on them.
+
@vindex .RECIPEPREFIX @r{(change the recipe prefix character)}
@item .RECIPEPREFIX
The first character of the value of this variable is used as the
#endif
/* Decode the switches. */
-
decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
/* Clear GNUMAKEFLAGS to avoid duplication. */
decode_switches (argc, (const char **)argv, 0);
+ /* Set a variable specifying whether stdout/stdin is hooked to a TTY. */
+#ifdef HAVE_ISATTY
+ if (isatty (fileno (stdout)))
+ define_variable_cname ("MAKE_TTYOUT", TTYNAME (fileno (stdout)),
+ o_default, 0)->export = v_export;
+
+ if (isatty (fileno (stderr)))
+ define_variable_cname ("MAKE_TTYERR", TTYNAME (fileno (stderr)),
+ o_default, 0)->export = v_export;
+#endif
+
/* Reset in case the switches changed our minds. */
syncing = (output_sync == OUTPUT_SYNC_LINE
|| output_sync == OUTPUT_SYNC_TARGET);
/* The number of bytes needed to represent the largest integer as a string. */
#define INTSTR_LENGTH CSTRLEN ("18446744073709551616")
+#ifdef HAVE_TTYNAME
+# define TTYNAME(_f) ttyname (_f)
+#else
+# define TTYNAME(_f) "true"
+#endif
+
\f
const char *concat (unsigned int, ...);
void message (int prefix, size_t length, const char *fmt, ...)