【问题标题】:Overwrite variable from makefile从makefile覆盖变量
【发布时间】:2015-04-03 15:05:22
【问题描述】:

在我的 makefile 中有一个变量 FOO:

FOO = /path/to/bar

是否可以在 makefile 调用期间覆盖此变量?类似于以下内容:

FOO=/path/to/foo make all

【问题讨论】:

    标签: makefile


    【解决方案1】:

    在指定目标之前将它们指定为Var=Value,例如make FOO=/path/to/foo all

    $ cat Makefile 
    Foo = asdf
    
    all:
        echo $(Foo)
    
    $ make all
    echo asdf
    asdf
    $ make Foo=bar all
    echo bar
    bar
    

    【讨论】:

    • 命令行上相对于目标名称的位置无关紧要。它们不是位置的。
    • 答案应该是这样的,简单明了的例子,直截了当
    【解决方案2】:

    变量获得赋值的方式在 GNU make 手册的How Variables Get Their Values 部分中指定。

    变量可以通过几种不同的方式获取值:

    因此,正如三十二号上校所说,您可以在命令行上覆盖在 makefile 中设置的变量。

    如果您希望这是一个要永久设置的变量,您也可以使用?= 赋值,然后将使用该变量的环境值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2017-02-25
      • 2021-08-24
      • 2020-09-30
      相关资源
      最近更新 更多