summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2014-09-14 01:03:19 -0400
committerPaul Smith <psmith@gnu.org>2014-09-14 01:03:19 -0400
commit7f9ce6e97bd1bb4289477ac76532e156947e7865 (patch)
treeb3e06143fcb0801ff26f203351b5037b5ecbd92f
parent621e9edfe9ac4ad20ce297787fa308b032b3fa8e (diff)
downloadgunmake-7f9ce6e97bd1bb4289477ac76532e156947e7865.tar.gz
* main.c (main): Set MAKE_TTYOUT and MAKE_TTYERR.
* configure.ac: Test for isatty() and ttyname() * makeint.h: provide a substitute for ttyname() if it's not available. * config.ami.template, config.h-vms.template, config.h.W32.template: define/undefine HAVE_ISATTY/HAVE_TTYNAME macros. * NEWS, doc/make.texi: Document these new variables.
-rw-r--r--NEWS3
-rw-r--r--config.ami.template6
-rw-r--r--config.h-vms.template6
-rw-r--r--config.h.W32.template6
-rw-r--r--configure.ac2
-rw-r--r--doc/make.texi22
-rw-r--r--main.c12
-rw-r--r--makeint.h6
8 files changed, 61 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index ae725fc..c394850 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ A complete list of bugs fixed in this version is available here:
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.
diff --git a/config.ami.template b/config.ami.template
index d9163c0..419824f 100644
--- a/config.ami.template
+++ b/config.ami.template
@@ -318,6 +318,12 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
/* 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 */
diff --git a/config.h-vms.template b/config.h-vms.template
index 71fe269..8c0a078 100644
--- a/config.h-vms.template
+++ b/config.h-vms.template
@@ -362,6 +362,12 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
/* 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
diff --git a/config.h.W32.template b/config.h.W32.template
index f7aed90..849a855 100644
--- a/config.h.W32.template
+++ b/config.h.W32.template
@@ -292,6 +292,12 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
/* 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 */
diff --git a/configure.ac b/configure.ac
index 59333d1..97fd090 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,7 +140,7 @@ AC_CHECK_FUNCS([strdup strndup mkstemp mktemp fdopen fileno \
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
diff --git a/doc/make.texi b/doc/make.texi
index 2aacc70..3a873d7 100644
--- a/doc/make.texi
+++ b/doc/make.texi
@@ -6321,6 +6321,28 @@ will contain the number of times this instance has restarted. Note
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
diff --git a/main.c b/main.c
index 6aecd80..4a79b60 100644
--- a/main.c
+++ b/main.c
@@ -1374,7 +1374,6 @@ main (int argc, char **argv, char **envp)
#endif
/* Decode the switches. */
-
decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
/* Clear GNUMAKEFLAGS to avoid duplication. */
@@ -1398,6 +1397,17 @@ main (int argc, char **argv, char **envp)
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);
diff --git a/makeint.h b/makeint.h
index ab41665..da267cb 100644
--- a/makeint.h
+++ b/makeint.h
@@ -424,6 +424,12 @@ extern struct rlimit stack_limit;
/* 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
+
const char *concat (unsigned int, ...);
void message (int prefix, size_t length, const char *fmt, ...)