如何在GNU Make中正确注释变量定义? [英] How do I properly comment a variable definition in GNU Make?

查看:131
本文介绍了如何在GNU Make中正确注释变量定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在线注释Makefile中的变量定义。问题是Make不会在定义及其注释之间去除空格。这是我的意思的示例:

So I want to comment variable definitions in Makefile in-line. The problem is that Make doesn't strip white spaces between the definition and its comment. Here is an example of what I mean:

OPTS += -DBLA       # Does bla
OPTS += -DBLUBB     # Does blubb
OPTS += -DEND

.PHONY test
test:
    @echo $(OPTS)

输出

-DBLA       -DBLUBB     -DEND

在选项之间有多余的空格。我想要的是这样:

with annoying extra white spaces between the options. What I want is this:

-DBLA -DBLUBB -DEND

如何解决此问题? Make字符串函数 @echo $(strip $(OPTS))仅会删除 -DEND 之后或 -DBLA ,而不是两者之间。到目前为止,我的肮脏技巧是 @echo $(shell $(OPTS)),该方法会删除不需要的空间,但使用shell调用会这样做,这可能会带来其他问题,即通过 $(OPTS)变量进行不必要的外壳注入。有更好的方法吗?简单的 @echo($ subst ...)在混合空格上不起作用,除非一个空格全部替换掉​​然后在-中重新插入code>。

How do I get around this Problem? The Make string function @echo $(strip $(OPTS)) would only strip whitespaces after -DEND or before -DBLA, not inbetween. My dirty hack so far is @echo $(shell $(OPTS)), which strips the unwanted spaces but uses a shell call to do so, that probably will introduce other problems, i.e. unwanted shell injection via the $(OPTS) variable. Is there a better way to do it? Simple @echo ($subst ...) doesn't work on mixed whitespaces unless one replaces all of them an then reinserts at the -.

推荐答案




当然,'zZz'可以替换为任何不可能的匹配项...


Of course, 'zZz' could be replaced with any "impossible" match...

这篇关于如何在GNU Make中正确注释变量定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆