用make删除前缀 [英] Remove prefix with make

查看:158
本文介绍了用make删除前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从make中的字符串(在我的情况下为路径名)中删除前缀?

Is there a way to remove a prefix from a string (a pathname in my case) in make?

作为一个例子,假设我有一个字符串:

As an example, suppose I had the string:

FILES = a/b/c.d a/b/e.f

我要删除a/,并留下b/c.d b/e.f

我尝试使用 GNU制作手册,但似乎没有一个提供很好的解决方案.

I have tried using various combinations of dir, notdir and basename from the GNU make manual, but none seem to provide a nice solution.

$(dir $(FILE))      # a/b a/b
$(notdir $(FILE))   # c.d e.f
$(basename $(FILE)) # a/b/c a/b/e

到目前为止,我发现这样做的唯一方法是:

The only way I've found to do this so far is:

$( join $(basename $(dir $(FILE))), $(notdir $(FILE)) )

这真是丑陋而漫长.我真正需要的是某种$(removeprefix ...)函数.假设我知道要删除的前缀(a/),可以通过某种字符串操作来做到这一点吗?

Which is really ugly and long-winded. What I really need is some kind of $(removeprefix ...) function. Assuming that I know the prefix (a/) to be removed, can this be done with some kind of string manipulation?

推荐答案

您可以使用

$(FILE:a/%=%)

有关更多选项,请参见文本替换功能参考. &详细信息.

See the text substitution function reference for more options & details.

这篇关于用make删除前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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