问题描述:

I have a test Makefile

CPPFLAGS += "option B"

$(info CPPFLAGS = $(CPPFLAGS))

when I do make, I get

CPPFLAGS = "option B"

make: *** No targets. Stop.

but when I do make CPPFLAGS="options A", I get

CPPFLAGS = option A

make: *** No targets. Stop.

I wanted the string "option B" to be appended to "option A" coming from the command line.

What is wrong with this?

Thanks in advance.

网友答案:

That is because variables from the command-line take precedence over the rest. From here:

If a variable has been set with a command argument, 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

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.

Try this:

override CPPFLAGS += option B
相关阅读:
Top