本文介绍了覆盖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.
- 您可以在运行make时指定一个覆盖值.请参见覆盖变量.
- 您可以在makefile中指定一个值,也可以进行赋值(请参见设置变量)或使用逐字定义(请参见定义多行变量).
- 环境中的变量成为make变量.请参见环境变量.
- 为每个规则为几个自动变量赋予新值.这些中的每一个都具有单个常规用途.请参见自动变量.
- 多个变量具有恒定的初始值.参见内隐规则使用的变量.
- 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中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!