加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何替换字符串并在Microsoft NMake中添加前缀或后缀?

发布时间:2020-12-14 02:56:14 所属栏目:Windows 来源:网络整理
导读:我正在将GNU Make makefile翻译为Microsoft Visual Studio Makefile.我有三个疑问: 1)如何替换字符串.例如在包含以下内容的文件夹中 namespace_type_function1.cppnamespace_type_function2.cppnamespace_type_function3.cpp 我想改变类型让我们说“INT”字
我正在将GNU Make makefile翻译为Microsoft Visual Studio Makefile.我有三个疑问:

1)如何替换字符串.例如在包含以下内容的文件夹中

namespace_type_function1.cpp
namespace_type_function2.cpp
namespace_type_function3.cpp

我想改变类型让我们说“INT”字符串,所以我终于得到了

namespace_INT_function1.cpp
namespace_INT_function2.cpp
namespace_INT_function3.cpp

2)如何以类似的方式添加前缀
3.如何以相同的方式添加后缀.

解决方法

在环境变量或内部nmake变量中包含字符串后,可以使用以下内容将一个固定字符串替换为另一个:

$(MY_VAR:REPLACE_THIS=WITH_THIS)

“WITH_THIS”可以是空字符串.

示例makefile:

MY_VAR=123451234512345
ALL:
   @echo $(MY_VAR:12=XX)
   @echo $(MY_VAR:12=)

输出:

XX345XX345XX345
345345345

从Microsoft文档:

Macro substitution is case sensitive and is literal; string1 and
string2 cannot invoke macros. Substitution does not modify the
original definition. You can substitute text in any predefined macro
except $$@.

No spaces or tabs precede the colon; any after the colon are interpreted as literal. If string2 is null,all occurrences of string1 are deleted from the macro’s definition string.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读