OpenWrt/LEDE Project

  • Status Unconfirmed
  • Percent Complete
  • Task Type Bug Report
  • Category Base system
  • Assigned To No-one
  • Operating System All
  • Severity Low
  • Priority Very Low
  • Reported Version Trunk
  • Due in Version Undecided
  • Due Date Undecided
  • Private
Attached to Project: OpenWrt/LEDE Project
Opened by R. Diez - 27.01.2019

FS#2086 - IS_TTY in the makefile is broken

File include/ tries to find out whether the build is running in an interactive console like this:

export IS_TTY=$(shell tty -s && echo 1 || echo 0)

That is the wrong way to do it. The code above is testing stdin, and not stdout. As a result, piping to a log file with a tool like ‘tee’ yields a log file that still contains the same \r codes etc. as when running on an interactive console.

Other tools like systemd’s systemctl do it right by checking stdout. On an interactive console, run these 2 commands to see the difference:

systemctl –help
systemctl –help | tee test.txt

It turns out that checking stdout is not so easy to do inside a makefile. In the shell, you would normally check with “-t 1”, but a $(shell ...) construct inside a makefile won’t work, because $(shell) always redirects stdout in order to capture the command’s output.

See here for the gory details:

While there are workarounds for makefiles, I wouldn’t go that far. I would just stop trying. and let the user decide with some variable. Maybe some day there will be a wrapper shell script, instead of using the makefile directly. In such a wrapper script it would be trivial to check for things like interactive terminal and/or terminal color support.

R. Diez commented on 04.06.2020 13:48

I recently learnt that GNU Make has variables for this purpose:

New variables: $(MAKE_TERMOUT) and $(MAKE_TERMERR) are set to non-empty
values if stdout or stderr, respectively, are believed to be writing to a
terminal.  These variables are exported by default.

I have attached a patch to fix this issue in OpenWrt's build system. Please treat the patch as a suggestion. If something is not right with it, please fix this issue in whichever way you find suitable.

R. Diez commented on 30.06.2020 12:50

I have jumped through all the hoops and posted the patch with Git, which was automatically picked up by Patchwork. It is here:

build: IS_TTY is now set according to GNU Make's MAKE_TERMOUT

The reason why the patch was rejected is:

Currently OpenWrt requires "GNU make v3.82", see include/

However, there is no other practical way to fix this issue, as far as I know.

GNU Make v3.82 is 10 years old, and the one we would need, version 4.1, is 6 years old.

I could try to change the Makefile logic to identify the GNU Make version, but the way OpenWrt makes me jump through hoops to post patches has discouraged me.

Given that the IS_TTY logic is currently broken, I would still apply the patch. If an older version of GNU Make without MAKE_TERMOUT runs this line:

export IS_TTY=$(if $(MAKE_TERMOUT),1,0)

Such an old versoin will then always decide that the output is not a TTY, and you will lose message colours on your terminal. That is not a big deal. The flip side is that your build log files will no longer have terminal rubbish inside.


Available keyboard shortcuts


Task Details

Task Editing