gpt4 book ai didi

makefile - 使用 make 删除前缀

转载 作者:行者123 更新时间:2023-12-02 19:06:05 24 4
gpt4 key购买 nike

有没有办法在 make 中从字符串(在我的例子中是路径名)中删除前缀?

举个例子,假设我有字符串:

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

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

我尝试使用 GNU make manual 中的 dirnotdirbasename 的各种组合。 ,但似乎都没有提供一个很好的解决方案。

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

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

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

这真是丑陋又啰嗦。我真正需要的是某种 $(removeprefix ...) 函数。假设我知道要删除的前缀 (a/),可以通过某种字符串操作来完成吗?

最佳答案

您可以使用

去掉前导的 a/
$(FILE:a/%=%)

请参阅text substitution function reference了解更多选项和详细信息。

关于makefile - 使用 make 删除前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19571391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com