本文介绍了覆盖makefile中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my makefile I have a variable FOO:

FOO = /path/to/bar

在makefile调用期间是否可以覆盖此变量?如下所示:

Is it possible to overwrite this variable during the makefile call? Somthing like the following:

FOO=/path/to/foo make all

推荐答案

变量如何获取其值在GNU制作手册中.

The ways that variables get assigned values is specified in the How Variables Get Their Values section of the GNU make Manual.

  • You can specify an overriding value when you run make. See Overriding Variables.
  • You can specify a value in the makefile, either with an assignment (see Setting Variables) or with a verbatim definition (see Defining Multi-Line Variables).
  • Variables in the environment become make variables. See Variables from the Environment.
  • Several automatic variables are given new values for each rule. Each of these has a single conventional use. See Automatic Variables.
  • Several variables have constant initial values. See Variables Used by Implicit Rules.

因此,正如"32上校"指出的那样,您可以在命令行上覆盖在makefile中设置的变量.

So, as Colonel Thirty Two indicates, you can override variables set in the makefile on the command line.

如果您希望将其作为要永久设置的变量,也可以使用?= 赋值,然后使用该变量的环境值.

You can also, if you expect this to be a variable that you want to set persistently, use the ?= assignment and then environment values for that variable will be used.

这篇关于覆盖makefile中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 12:20
查看更多