'Quoting shell env vars in Makefile

I thought I understood that simply-expanded variables got their value once, when the Makefile is read -- but I've got confused:

var := $$RANDOM

echo:
        @echo v1: $(var)
        @echo v2: $(var)

With result

$ make
v1: 11478
v2: 24064

So how come the shell env var is referenced twice?

I see that var := $(shell echo $$RANDOM) don't do the second value assignment -- how is this machinery different?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source