在 GNU Make 中,如何将路径的驱动器替换为小写?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你为什么在这里使用 eval ;为什么不只是:
但是,无论如何,任何时候你需要在 GNU 中做一些非常聪明的字符串翻译等事情,我敢打赌 John Graham-Cumming 已经为你做到了。查看他最优秀的工具包GMSL(GNU Make Standard Library),了解许多常见功能。其中包括 lc(小写)的变体。您可以获取一份副本,而不是在此处复制它(连同版权声明,因为它采用 BSD 许可证)。
一旦你拥有它,如果你想要整个路径小写,你可以做这样的事情:
如果你只想驱动器字母小写,而不是其余的,它会更复杂,这样的事情应该工作:
可能有更简单的方法。另外,如果您确定 DIRECTORY 的值已经设置,您应该考虑在此处使用“:=”而不是“=”,因为它会使事情变得更加高效(特别是如果 $(_ABS_PATH) 被大量使用)。
I'm not sure why you're using eval here; why not just:
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:
If you just want the drive letter to be lowercased but not the rest it's more complex, something like this should work:
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).