copy value of an automatic variable to another variable in makefile -


i'd rule variable contain value of $@ in attribution line, instead of reference. example:

rule=$@  all:     @echo "running rule: $(rule)"  rule1:     @echo "do here"  rule2:     @echo "do thing here" 

my expected result be:

running rule: rule2

do thing here

when run make rule2. result have is:

running rule: all

do thing here

is possible make attribution?


[edit]

in others words, need parent target name, i.e. parameter of make command typed user in terminal console.

no. $@ set current target, never parent target (why that?)

the best option available (given limited description have of you're trying do) use target-specific variables:

all:         @echo "running rule: $(rule)"  rule1: rule = rule1 rule1:         @echo "do here"  rule2: rule = rule2 rule2:         @echo "do thing here" 

Comments