Reputation: 602
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.
Upvotes: 4
Views: 2714
Reputation: 29280
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).
Upvotes: 5