makefile - 如何使用 patsubst Makefile 替换?
问题描述
我有一个有点像这样的makefile。我需要生成一个文件并将其移动为 abc.cpp (基本上摆脱下划线后的任何内容,包括下划线
xyz:= abc_def
$(xyz):
(some commands here which generates a file)
mv file /tmp/$(patsubst _%,"",$@)
However this does not work. In fact it doesn't ever match the underscore "_" in $@
mv file /tmp/abc.cpp is what i want
“%”通配符在 patsusbst 中是如何工作的?
解决方案
如果您不回避使用帮助代码(即包含一个GNUmake
库),那么GNUmake 表工具包肯定可以解决问题:
include gmtt.mk
xyz:= abc_def
$(xyz):
(some commands here which generates a file)
mv file /tmp/$(firstword $(call glob-match,$@,*_*)).cpp
该glob-match
函数将字符串拆分为匹配元素的条纹,其中每个全局字符(*
, ?
, [...]
)和逐字字符串部分(在您的情况下只是_
)构成一个匹配项。或者简单地说,$(call glob-match,this_is_a_string,*_is_a_*)
分成this_is_a_string
一个列表this _is_a_ string
(注意空格)。
推荐阅读
- mysql - 如何从 mysql 5.0 中删除或删除重复的整体
- qt - 如何在数据更改时显示 QAbstractListModel 的单个项目并更新 Gui
- html - 垂直对齐网格内右对齐的导航栏项目
- dart - Flutter 'Compute' 内存泄漏 - 如何停用计算实例使用的堆变量?
- json - 使用 Git 管理 package.json 和 package-lock.json
- android - 使用 Android Jetpack Navigation 时如何防止 Navigation
- python - python中的数学公式不起作用
- macos - 从 Mojave 上的 MacOS 扩展坞自动删除已关闭应用程序的命令?
- python - Flask拒绝在vscode调试中加载服务器
- django - Django 表单看不到文件上传中的任何数据