Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tput with make

Tags:

gnu-make

gnu

tput

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.

like image 395
Audun Olsen Avatar asked Oct 20 '25 06:10

Audun Olsen


1 Answers

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.

like image 128
MadScientist Avatar answered Oct 22 '25 03:10

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!