Makefile GNU使用前导空格生成测试输出
我想在makefile(gnumake)的规则帮助中输出一些文本 调用Makefile GNU使用前导空格生成测试输出,makefile,whitespace,gnu-make,Makefile,Whitespace,Gnu Make,我想在makefile(gnumake)的规则帮助中输出一些文本 调用make help时,我希望: 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 mak
make help
时,我希望:
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
但我得到:
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
如何保留前导空格
编辑:
解决方案也必须在Windows上运行
解决方案:
诀窍是添加一个包含空格的变量。然后,make不会剥掉绳子
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)
不要使用make的
info
功能。通常很少有理由在菜谱中使用这样的make函数:菜谱具有可用shell的全部功能,这比GNU make函数功能强大得多。改用shell的echo
函数:
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
如果您真的想使用$(info…
实现可移植性,那么您必须玩一个小把戏:
E :=
help:
$(info $E indented text)
这将生成一个空变量
$E
,然后您可以使用它,它将标记分隔函数名与其参数的空格的结尾。不要使用make的info
函数。通常很少有理由在菜谱中使用这样的make函数:菜谱具有可用shell的全部功能,这比GNU make函数功能强大得多。改用shell的echo
函数:
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
如果您真的想使用$(info…
实现可移植性,那么您必须玩一个小把戏:
E :=
help:
$(info $E indented text)
这将生成一个空变量
$E
,然后您可以使用它,它将标记分隔函数名与其参数的空白的结尾。在Windows上,shell的功能通常不太强大。但它与所有其他贝壳都大不相同。在Windows上,您的解决方案不起作用,或者至少存在其他问题(无法打印空行)。@Teddy会echo”“
在Windows上打印空行吗?您在最初的问题中没有提到任何有关Windows的内容。编写一个运行于多个系统的makefile通常非常困难@在Windows上为否(假设make调用cmd.exe而不是sh.exe)echo”“
将打印”
。Windows中的命令shell与POSIX shell的命令行处理方式相差甚远。在Windows中,您可以使用echo.
,它将打印一条空行,但这当然不会在POSIX上打印一条空行。实际上,它比我建议的要简单。您不需要创建一个包含空格的变量。您只需要一个空变量:使make停止在函数名之后和第一个参数之前使用空格。但它与所有其他贝壳都大不相同。在Windows上,您的解决方案不起作用,或者至少存在其他问题(无法打印空行)。@Teddy会echo”“
在Windows上打印空行吗?您在最初的问题中没有提到任何有关Windows的内容。编写一个运行于多个系统的makefile通常非常困难@在Windows上为否(假设make调用cmd.exe而不是sh.exe)echo”“
将打印”
。Windows中的命令shell与POSIX shell的命令行处理方式相差甚远。在Windows中,您可以使用echo.
,它将打印一条空行,但这当然不会在POSIX上打印一条空行。实际上,它比我建议的要简单。您不需要创建一个包含空格的变量。您只需要一个空变量:让make停止在函数名之后和第一个参数之前使用空格。