I saw the question:
then I did as below:
HELLO='hello 1st'
HELLO_WORLD='$(HELLO) world!'
HELLO='hello 2nd'
all :
echo $(HELLO_WORLD)
HELLO='hello 3rd'
echo $(HELLO_WORLD)
HELLO='hello 4th'
echo $(HELLO_WORLD)
the result is that:
root@ubuntu:~# make all -s
hello 2nd world!
hello 2nd world!
hello 2nd world!
I confused, why the value of 'HELLO' was not set to hello 4th but hello 2nd
update:
I update my code :
HELLO='hello 1st'
HELLO_WORLD='$(HELLO) world!'
HELLO='hello 2nd'
all :
HELLO='hello 3rd' && echo $(HELLO_WORLD)
HELLO='hello 4th' && echo $(HELLO_WORLD)
And the result:
root@ubuntu:~# make all -s
hello 2nd world!
hello 2nd world!
I have realized the sentences like HELLO='hello 3rd' is not variable assignments finally.
You two help me a lot. Thanks the answers!
HELLO='hello 3rd'; echo $(HELLO); echo $$HELLOoutputs what it does?hello 3rdand a blank lineecho $$HELLOis equal toecho $('hello 3rd')HELLOfirst. The first$(HELLO)is a makefile variable, and make expands it tohello 2nd– but the$$HELLOincludes the make variable$$, which expands to$, so that make expands this line toHELLO='hello 3rd'; echo hello 2nd; echo $HELLOand that sequence of three commands is what it executes in the shell. At that point, the shell (1) defines the variableHELLO, then (2) echoes the two literal argumentshelloand2nd, then (3) expands the shell variable$HELLOtohello 3rdand prints that. Hencehello 2ndthenhello 3rd.