Reputation: 1022
I want to output some text in the rule help of a makefile (GNU make).
help:
$(info Help:)
$(info )
$(info make all Build all targets)
$(info make this Build target this)
$(info make long Build target long that has)
$(info a very long description)
$(info that must be shown on)
$(info several lines)
$(info make that Build target that)
When calling make help
I would expect:
Help:
make all Build all targets
make this Build target this
make long Build target long that has
a very long description
that must be shown on
several lines
make that Build target that
But I get:
Help:
make all Build all targets
make this Build target this
make long Build target long that has
a very long description
that must be shown on
several lines
make that Build target that
How can the leading spaces be preserved?
Edit:
The solution has to work on Windows too.
Solution:
The trick is to add a variable containing a space. Then make does not strip the string.
SPACE := $(subst ,, )
help:
$(info Help:)
$(info )
$(info make all Build all targets)
$(info make this Build target this)
$(info make long Build target long that has)
$(info $(SPACE) a very long description)
$(info $(SPACE) that must be shown on)
$(info $(SPACE) several lines)
$(info make that Build target that)
Upvotes: 0
Views: 437
Reputation: 100946
Do not use make's info
function. There is typically very little reason to use make functions like this inside a recipe: a recipe has the full power of the shell available and that's MUCH more powerful than GNU make function capabilities. Use the shell's echo
function instead:
help:
echo "Help:"
echo
echo "make all Build all targets"
echo "make this Build target this"
echo "make long Build target long that has"
echo " a very long description"
echo " that must be shown on"
echo " several lines"
echo "make that Build target that"
ETA
If you really want to use $(info ...)
for portability then you'll have to play a trick:
E :=
help:
$(info $E indented text)
This makes an empty variable $E
, then you can use that and it will mark the end of the whitespace separating the function name from its arguments.
Upvotes: 3