3

I am looking to do some formatting of the output from my makefile using tput. An example: if you simply type

echo $(printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' –)

as a command in your shell it will output a nice line spanning the entire width of your terminal window.

I am wondering if there's any way to carry this over in a makefile? The following only produces a blank line:

lineTest:
    @echo $$( printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' – )

Definitely a silly question, but please do chime in if you happen to know.

Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
Audun Olsen
  • 597
  • 6
  • 17

1 Answers1

4

You have to escape ALL the $ you want to pass to make. You only escaped the first one. Also I don't know why you're invoking printf in a subshell then echoing the results...??

This works for me:

lineTest:
        @printf '%*s\n' "$${COLUMNS:-$$(tput cols)}" '' | tr ' ' -

I should point out, this won't work reliably if you invoke make with parallel builds enabled, because in parallel mode not all of the jobs get access to the terminal.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • In makefiles I define the columns like this: ```# Define Terminal Info``` ```COLUMNS := $(shell tput cols)``` – MERM Apr 07 '23 at 14:35