BOSTON
BOSTON

Reputation: 1

Append to variable not working when passing += assign variables from command line to make

I am trying to append value to variable already has assign value from inside of makefile from cmdline but it doesn't working and I don't know what am I doing wrong.

In my Makefile:

FPP+=ONE
FOO+=TWO

target:
     echo "Value: $(FOO)"

If I run: make

it displays:

Value: ONE TWO

But if I run: make FOO+=THREE

I was expecting:

Value: ONE TWO THREE

But instead of I am getting:

Value: THREE

So cmdline FOO+=THREE is override FOO instead of append. What am I doing wrong?

Upvotes: 0

Views: 493

Answers (1)

Beta
Beta

Reputation: 99134

Variables set on the command line cannot be modified by ordinary assignments within the makefile. You must use the override directive:

override FOO+=ONE
override FOO+=TWO

Upvotes: 3

Related Questions