【发布时间】:2013-02-13 01:23:31
【问题描述】:
下面是我在 makefile 中使用的一个变量。
copt = -mcpu=cortex-m3 -mthumb -g -c
我想删除 -mthumb 并用其他选项替换它。 有什么办法可以去掉这个选项并添加一些其他选项。 我知道如何添加:示例 - copt += -O3 但不知道如何删除已经存在的选项。
谢谢!
【问题讨论】:
下面是我在 makefile 中使用的一个变量。
copt = -mcpu=cortex-m3 -mthumb -g -c
我想删除 -mthumb 并用其他选项替换它。 有什么办法可以去掉这个选项并添加一些其他选项。 我知道如何添加:示例 - copt += -O3 但不知道如何删除已经存在的选项。
谢谢!
【问题讨论】:
$(subst from,to,text)对文本文本执行文本替换:每次出现的 from 都替换为 to。结果被替换为函数调用。
在你的情况下:
newopts = $(subst -mthumb, new_opt, $(copt))
【讨论】:
比$(subst...) 使用对整个单词进行操作的东西要安全一点:
newopts := $(filter-out -mthumb,${opts}) more opts
【讨论】:
sed 效果很好:
sed -i 's/old_word/new_word/g' makefile
【讨论】:
copt 会发生什么?