variable reassign value in same makefile

anand akhare <[email protected]> Wed, 3 Apr 2024 09:52:31 +0000
Newsgroups gmane.comp.gnu.make.general
Message-ID <KL1PR04MB7792CF54D5106A28F45B4171BE3D2@KL1PR04MB7792.apcprd04.prod.outlook.com>
Hello make team,
    according to the info make page, recursive variable takes value at the time it is used. However, no reference is there in doc what happens if value is changed for the variable. To verify this I created small makefile as below and on executing make trg1, it shows VAR value as jklmn. Output pasted below the makefile. Pls clarify if value of variable is taken once in makefile as last one assigned and rest are discarded. My idea is that intermediate values of variable should be used until changed for target and recipe. Same behavior is seen with non-recursive variables. (like VAR:=abc)

Regards
Anand

---------------------
VAR="abc"

trg1:
        echo "trg1 ${VAR}"

VAR="def"

trg2:
        echo ${VAR}

trg3:
        echo ${VAR}


all: trg1 trg2 trg3


VAR="jklmn"
----------------------

output of make trg1:

$ make trg1
echo "trg1 "jklmn""
trg1 jklmn