最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】makefile中如何在输出信息时添加空格或Tab或换行

makefile crifan 7211浏览 0评论

折腾:

【已解决】给makefile添加make help输出帮助信息

期间,想要给:

<code>Author=crifan.com
Version=20171207
Function=Auto use gitbook to generated files: website/pdf/epub/mobi
RunHelp = Run 'make help' to see usage
$(info --------------------------------------------------------------------------------)
$(info Author: $(Author))
$(info Version: $(Version))
$(info Function: $(Function). $(RunHelp))
$(info --------------------------------------------------------------------------------)

</code>

的:

<code>➜  http_summary git:(master) ✗ make dir_info
--------------------------------------------------------------------------------
Author: crifan.com
Version: 20171207
Function: Auto use gitbook to generated files: website/pdf/epub/mobi. Run 'make help' to see usage
--------------------------------------------------------------------------------
</code>

中添加空格,tab,换行,回车,变成:

<code>Function: Auto use gitbook to generated files: website/pdf/epub/mobi
          Run 'make help' to see usage
</code>

试了:

<code>$(info Function: $(Function))
$(info          $(RunHelp))
</code>

结果没用,空格不起效果:

<code>Function: Auto use gitbook to generated files: website/pdf/epub/mobi
Run 'make help' to see usage
</code>

试了:

<code>$(shell echo $(RunHelp))
</code>

结果语法就出错:

<code>Makefile:9: *** missing separator.  Stop.
</code>

make info

gnu make – How to print out a variable in makefile – Stack Overflow

Makefile 的函数(2) – omicron的日志 – 网易博客

GNU make: Make Control Functions

makefile new line

gnu make – How to break a string across lines in a makefile without spaces? – Stack Overflow

Add a newline in Makefile ‘foreach’ loop – Stack Overflow

好像是行未加上反斜杠就可以换行了。

newline – Insert a new-line in a Makefile $(foreach ) loop – Stack Overflow

可以定义变量是换行?

Can you make valid Makefiles without tab characters? – Stack Overflow

Makefile: When to use space or tab? – Stack Overflow

结果:

<code>define NEWLINE

endef
$(info Function: $(Function)$(NEWLINE)$(RunHelp))
</code>

并没用。

无意间试了换两行:

<code>define NEWLINE


endef

</code>

$(info Function: $(Function)$(NEWLINE)$(RunHelp))

就可以了。

然后继续优化:

【总结】

<code>define NEWLINE
</code>

endef

define TAB

  

endef

Author=crifan.com

Version=20171207

Function=Auto use gitbook to generated files: website/pdf/epub/mobi

RunHelp = Run ‘make help’ to see usage

$(info ——————————————————————————–)

$(info Author: $(Author))

$(info Version: $(Version))

$(info Function: $(Function)$(NEWLINE)$(TAB)$(TAB)$(RunHelp))

$(info ——————————————————————————–)

输出效果:

<code>➜  http_summary git:(master) ✗ make dir_info
--------------------------------------------------------------------------------
Author: crifan.com
Version: 20171207
Function: Auto use gitbook to generated files: website/pdf/epub/mobi
        Run 'make help' to see usage
--------------------------------------------------------------------------------
</code>

转载请注明:在路上 » 【已解决】makefile中如何在输出信息时添加空格或Tab或换行

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.188 seconds, using 22.12MB memory