How to strip parameters from a variable in a makef

2019-07-23 14:01发布

Below is a variable I am using in a makefile.

copt = -mcpu=cortex-m3 -mthumb -g -c

I want to remove -mthumb and replace it with some other option. Is there any way I can strip the option and add few other options. I know how to add : Example - copt += -O3 but don't know how to remove the already existing options.

Thanks!

3条回答
smile是对你的礼貌
2楼-- · 2019-07-23 14:35

$(subst from,to,text)

Performs a textual replacement on the text text: each occurrence of from is replaced by to. The result is substituted for the function call.

In your case:

newopts = $(subst -mthumb, new_opt, $(copt))
查看更多
Explosion°爆炸
3楼-- · 2019-07-23 14:43

A tad safer than $(subst...) to to use something that operates on whole words:

newopts := $(filter-out -mthumb,${opts}) more opts
查看更多
我只想做你的唯一
4楼-- · 2019-07-23 14:48

sed works well:

sed -i 's/old_word/new_word/g' makefile
查看更多
登录 后发表回答