Is it possible to assign a variable that has also been passed from the command line?

I tried the following Makefile:

testvar := newassign

.PHONY: all
all:
    @echo $(testvar)

If I execute make, the output is the expected newassign. However, if I execute make testvar=asd, the output is asd, while I expect this to also be newassign.

I use GNU Make 4.1.

1 Answers

1
Aart Stuurman On

This apparently an intentional feature. Command line options always have precedence over assignments inside the Makefile. If you want to force assignment, you can use override.

override testvar := newassign

.PHONY: all
all:
    @echo $(testvar)