【问题标题】:How to strip parameters from a variable in a makefile如何从makefile中的变量中去除参数
【发布时间】:2013-02-13 01:23:31
【问题描述】:

下面是我在 makefile 中使用的一个变量。

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

我想删除 -mthumb 并用其他选项替换它。 有什么办法可以去掉这个选项并添加一些其他选项。 我知道如何添加:示例 - copt += -O3 但不知道如何删除已经存在的选项。

谢谢!

【问题讨论】:

    标签: gcc makefile gnu gnu-make


    【解决方案1】:

    $(subst from,to,text)

    对文本文本执行文本替换:每次出现的 from 都替换为 to。结果被替换为函数调用。

    在你的情况下:

    newopts = $(subst -mthumb, new_opt, $(copt))
    

    【讨论】:

      【解决方案2】:

      比$(subst...) 使用对整个单词进行操作的东西要安全一点:

      newopts := $(filter-out -mthumb,${opts}) more opts
      

      【讨论】:

        【解决方案3】:

        sed 效果很好:

        sed -i 's/old_word/new_word/g' makefile
        

        【讨论】:

        • 你能举个例子吗?
        • 当用户在命令行中指定copt 会发生什么?
        猜你喜欢
        • 1970-01-01
        • 2011-08-03
        • 2011-11-16
        • 2023-01-05
        • 1970-01-01
        • 2014-06-18
        • 2010-11-19
        相关资源
        最近更新 更多