如何在 make variable/function 中使用多个空格?

How do I use multiple spaces in a make variable/function?

通常,make 组合多个连续的白色 space 字符。有时这种行为是不需要的。这是一个针对这种情况的 示例

.PHONY: help

help:
    $(info Usage: make [command] [VARIABLES])
    $(info )
    $(info command1 ..... Do what command1 does and)
    $(info                let the sentence continue.)
    $(info command2 ..... Description of command2)

想要的输出:

Usage: make [command] [VARIABLES]

command1 ..... Do what command1 does and
               let the sentence continue.
command2 ..... Description of command2

实际输出:

Usage: make [command] [VARIABLES]

command1 ..... Do what command1 does and
 let the sentence continue.                 # Not aligned with "Do" in line above
command2 ..... Description of command2

换句话说,有没有办法在 make 中对齐或引用 spaces?

有个老套路:

EMPTY=
SPACE=$(EMPTY) $(EMPTY)

因此,在您的情况下:

.PHONY: help

EMPTY=
SPACE=$(EMPTY) $(EMPTY)

help:
    $(info Usage: make [command] [VARIABLES])
    $(info )
    $(info command1 ..... Do what command1 does and)
    $(info $(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)let the senten\
ce continue.)
    $(info command2 ..... Description of command2)

第一个想法:不要在食谱中使用 $(info ...)。而是使用 shell 命令,例如 echo 等。然后您可以使用引号等来保留空格。

第二种思路,用一个define变量定义来包含完整的内容:

define USAGE
Usage: make [command] [VARIABLES]

command1 ..... Do what command1 does and
               let the sentence continue.
command2 ..... Description of command2
endef

.PHONY: help
help: ; $(info $(value USAGE))