1

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

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.