在 GNU Make 中,如何将路径的驱动器替换为小写?

发布于 2025-01-07 01:58:49 字数 173 浏览 1 评论 0原文

在 GNU Make 中,目前我使用以下替换来降低驱动器号的大小写。

$(eval _ABS_PATH=$(subst C:,c:,$(abspath $(DIRECTORY))))

我如何修改它,以便可以将驱动器号的 AZ 替换为 az?

谢谢!

In GNU Make, currently I am lowering the case of a drive letter using the following substitution.

$(eval _ABS_PATH=$(subst C:,c:,$(abspath $(DIRECTORY))))

How can I modify this such that I can have A-Z substitution to a-z for the drive letter?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玉环 2025-01-14 01:58:49

我不确定你为什么在这里使用 eval ;为什么不只是:

_ABS_PATH = $(subst C:,c:,$(abspath $(DIRECTORY)))

但是,无论如何,任何时候你需要在 GNU 中做一些非常聪明的字符串翻译等事情,我敢打赌 John Graham-Cumming 已经为你做到了。查看他最优秀的工具包GMSL(GNU Make Standard Library),了解许多常见功能。其中包括 lc(小写)的变体。您可以获取一份副本,而不是在此处复制它(连同版权声明,因为它采用 BSD 许可证)。

一旦你拥有它,如果你想要整个路径小写,你可以做这样的事情:

include gmsl
_ABS_PATH = $(call lc,$(abspath $(DIRECTORY)))

如果你只想驱动器字母小写,而不是其余的,它会更复杂,这样的事情应该工作:

include gmsl
_DRIVE = $(word 1,$(subst :, ,$(abspath $(DIRECTORY))))
_ABS_PATH = $(call lc,$(_DRIVE)):$(patsubst $(_DRIVE):%,%,$(abspath $(DIRECTORY)))

可能有更简单的方法。另外,如果您确定 DIRECTORY 的值已经设置,您应该考虑在此处使用“:=”而不是“=”,因为它会使事情变得更加高效(特别是如果 $(_ABS_PATH) 被大量使用)。

I'm not sure why you're using eval here; why not just:

_ABS_PATH = $(subst C:,c:,$(abspath $(DIRECTORY)))

But, anyway, anytime you need to do something massively clever with string translations, etc. in GNU make there's a good bet that John Graham-Cumming has already done it for you. Check out his most excellent toolkit GMSL (GNU Make Standard Library) for many common functions. Included there is a variation of lc (lowercase). Rather than reproduce it here (along with the copyright notice as it's under a BSD license) you can go get a copy.

Once you have it you can do something like this if you want the entire path lowercased:

include gmsl
_ABS_PATH = $(call lc,$(abspath $(DIRECTORY)))

If you just want the drive letter to be lowercased but not the rest it's more complex, something like this should work:

include gmsl
_DRIVE = $(word 1,$(subst :, ,$(abspath $(DIRECTORY))))
_ABS_PATH = $(call lc,$(_DRIVE)):$(patsubst $(_DRIVE):%,%,$(abspath $(DIRECTORY)))

There may be simpler ways. Also if you're sure the value of DIRECTORY is already set you should consider using ":=" here instead of "=" as it will make things MUCH more efficient (especially if $(_ABS_PATH) is used a lot).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文