The following makefile.1 produces correct results:
-------------------------------
target1 : var := one
target2 : var := two

targets := target1 target2

all : $(targets)

.SECONDEXPANSION:
$(targets) : foo/$$(var)/bar

foo/%/bar :
    mkdir -p $(dir $@)
    touch $@

.PHONY : target1 target2
-------------------------

> make -f makefile.1
mkdir -p foo/one/
touch foo/one/bar
mkdir -p foo/two/
touch foo/two/bar

However, makefile.2 does not pick up var:
-----------------------------------------
target1 : var := one
target2 : var := two

targets := target1 target2

all : $(targets)

.SECONDEXPANSION:
$(targets) : test/$$@

$(targets:%=test/%) : foo/$$(var)/bar

foo/%/bar :
    mkdir -p $(dir $@)
    touch $@

.PHONY : $(targets) $(targets:%=test/%)
------------------------------------

> make -f makefile.2
make: *** No rule to make target `foo//bar', needed by `test/target1'. Stop.

According to make documentation:
"when you define a target-specific variable that variable value is also in effect for all prerequisites of this target, and all their prerequisites, etc."

Since test/target1 is a prerequisite for target1 and var is defined for target1, it should be available also for test/target1. Secondary expansion works when expanding 'var' for target1 and target2 in makefile.1, but it doesn't when expanding it in makefile.2

Am I doing something incorrect here or is it an unimplemented functionality, specifically that target specific variables are not inherited in prerequisites of prerequisite?

The behavior is the same in 3.81 and 3.82.

_______________________________________________
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make

Reply via email to