Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tab character in Makefile $(info ...)

Tags:

makefile

I would like to add tabs specifically to the stdout text in a makefile. I've tried placing tabs directly into the text as well as using a \t command and neither work.

I could always achieve the same with spaces but it is just annoying.

$(info test text with tabs)

tabs are completely removed on output

$(info \ttest text)

becomes : "\ttest text" on output

Is there a reasonable way to do this? I am aware I can do this with

@echo -e "\tNow the tabs work!"

However I was trying to get rid of using echos.

Thanks

edit :

I was wrong about using spaces instead -- they are just deleted on the output just like inserted tabs are.

like image 839
gutelfuldead Avatar asked Oct 24 '25 03:10

gutelfuldead


1 Answers

make strips strings before using them as arguments of various commands or statements. So, let's first define a variable containing... nothing, use it to define a variable containing a tab and use that variable when needed:

$ cat Makefile
NULL :=
TAB  := $(NULL)<tab>$(NULL)

all:
    $(info X$(TAB)X)

$ make
X    X
make: 'all' is up to date.

I used <tab> to show where the tab character must go. Use the real tab character instead, of course. Note that NULL alone is enough for what you want:

$ cat Makefile
NULL :=

all:
    $(info $(NULL)<tab>X)

$ make
    X

But having a TAB variable is maybe more convenient.

Note also that make variables can have very strange names. If you prefer naming the variable \t instead of TAB, you can:

$ cat Makefile
NULL :=
\t   := $(NULL)<tab>$(NULL)

all:
    $(info X$(\t)X)

$ make
X    X
make: 'all' is up to date.

You can even define \n for end-of-line:

$ cat Makefile
NULL :=
\t   := $(NULL)<tab>$(NULL)
define \n


endef

all:
    $(info X$(\t)X$(\n)Y$(\t)Y)

$ make
X    X
Y    Y
make: 'all' is up to date.

The reason why we need two empty lines in the define-endef can be found in the GNU make manual:

The value in an ordinary assignment cannot contain a newline; but the newlines that separate the lines of the value in a define become part of the variable’s value (except for the final newline which precedes the endef and is not considered part of the value).

like image 141
Renaud Pacalet Avatar answered Oct 26 '25 16:10

Renaud Pacalet



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!