makefile - Is it possible to detect from inside of GNU make whether the output is redirected to a file? -
typically shell script, can detect if output redirected file, along lines of:
if [ -t 1 ]; echo "shell"; fi but, i'd inside of makefile, means afaik, way is:
ifeq ($(shell if [ -t 1 ]; echo "1"; fi),1) ## in shell endif however, appears case time, whether output redirected file or not. guess it's down how $(shell...) implemented. question is, there can test in make let me know if output redirected file.
a little background, makefiles generate lots of useful output , make things bit more obvious, use colouring of text - on console fine, in hudson when same build job runs, output (which redirected file) has control characters in it... i'd disable colour codes in make if file redirected.
you can't use $(shell ...) this, because output of $(shell ...) always redirected: has because whole point of running $(shell ...) make capture it's output. check whether stderr tty, on assumption people redirect both of them @ same time. flawed assumption in cases.
other don't see straightforward way perform check within make. check must done within make recipe, because that's place make invoke shell without modifying stdout. can't change makefile variables, etc. within recipe.
we might able come really disgusting hack using auto-generated include files build of included file checked see if stdout terminal , wrote variable assignment included makefile. trick included makefile rebuilt once per invocation of make, not easy done. however, involve complete re-exec of make every time, set variable.
of course provide shell wrapper people run instead of running make directly, tested whether stdout tty invoked make variable assignment based on results.
Comments
Post a Comment