从 Makefile 变量中删除项目?
我有一个 makefile,其中包含几个其他 makefile,这些文件依次添加到一个变量中,如下所示:
VAR := Something SomethingElse
VAR += SomeOtherThing
(...)
现在我希望从 VAR
变量中删除 SomethingElse
。我应该用什么来代替 (...)
来做到这一点?
我正在使用 GNU Make,并且 GNU Make 特定的解决方案就可以了。
I have a makefile, which includes several other makefiles, which in turn all add to a variable like this:
VAR := Something SomethingElse
VAR += SomeOtherThing
(...)
Now I wish to remove SomethingElse
from the VAR
variable. What do I put in place of (...)
to do this?
I am using GNU Make, and a GNU Make specific solution will be fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
filter-out
文本函数(如果您使用的是 GNU Make)。You could use the
filter-out
text function if you're using GNU Make.在上面的正确答案之上:
输出:
VAR 为: bla1 bla2 bla4 bla5
请注意,执行过滤时这会破坏所有“递归性”,但这在您的情况下可能并不重要。
On top of the correct answer above:
Output:
VAR is: bla1 bla2 bla4 bla5
Note that this breaks all "recursivity" when filter-out is executed, but that might not matter in your case.
由于我也有类似的情况,所以我想添加一个新的答案。在我的例子中,变量字符串中也有逗号,而且,我想删除逗号和最后一个单词:
在这种情况下,过滤掉不起作用(即使在前面的答案中,没有引号时也不起作用)
我的解决方案是使用
subst
:As I also have a similar situation, I want to add a new answer. In my case there were also commas into the variable string and, more, I wanted to remove the comma and the last word :
In this case filter out is not working (not even in the previous answers, when there are no quotes)
My solution is to use
subst
: