GNU make manual 翻译( 一百六十五)
继续翻译
6.7 The `override' Directive ============================ If a variable has been set with a command argument (*note Overriding Variables: Overriding.), then ordinary assignments in the makefile are ignored. If you want to set the variable in the makefile even though it was set with a command argument, you can use an `override' directive, which is a line that looks like this: override VARIABLE = VALUE or override VARIABLE := VALUE To append more text to a variable defined on the command line, use: override VARIABLE += MORE TEXT *Note Appending More Text to Variables: Appending. Variable assignments marked with the `override' flag have a higher priority than all other assignments, except another `override'. Subsequent assignments or appends to this variable which are not marked `override' will be ignored. The `override' directive was not invented for escalation in the war between makefiles and command arguments. It was invented so you can alter and add to values that the user specifies with command arguments. For example, suppose you always want the `-g' switch when you run the C compiler, but you would like to allow the user to specify the other switches with a command argument just as usual. You could use this `override' directive: override CFLAGS += -g You can also use `override' directives with `define' directives. This is done as you might expect: override define foo = bar endef *Note Defining Multi-Line Variables: Multi-Line.
6.7 override 指令
============================
如果一个变量被一个命令参数设定(*note Overriding Variables: Overriding.),那么在makefile中的普通设定会被忽略。如果你希望,尽管已经在命令行参数进行了设定,还是想要makefile中的设定值,你可以使用 override 指令,像如下这样的:
override VARIABLE = VALUE
or
override VARIABLE := VALUE
为了从被命令行定义的变量中追加更多的文本,使用:
override VARIABLE += MORE TEXT
*Note Appending More Text to Variables: Appending.
被override标志设定的变量赋值拥有比其他的变量赋值更高的优先级,除非是被另一个override所设置掉。
后续的,没有用override,而对此变量的赋值,将要被忽略。
override 指令不是用来引起makefile和命令行参数的冲突的。它是用来让你可以在命令行参数的基础上追加值的。
例如,设想一下,你当你运行C编译器的时候,你总是想要 -g 选项,但是你想要允许用户在命令行提供其他的选项。你可以使用这个 overrride 指令:
override CFLAGS += -g
你也可以用 override 指令配合 define 指令,正如你所预料的:
override define foo =
bar
endef
*Note Defining Multi-Line Variables: Multi-Line.
后文待续