Red Hat Bugzilla – Bug 22000
Variables for rules are evaluated at different times than prerequisites
Last modified: 2015-05-04 21:32:03 EDT
Create a Makefile called Makefile.1 containing:
In Makefile.2 put:
FILE = file2
Now type "gmake -f Makefile.1". You get:
gmake: *** No rule to make target `file1', needed by `foo'. Stop.
Now remove the dependency on foo. (i.e. Change "foo: $(FILE)" to just
:"foo:"). You get:
This shows that FILE evaluates to file1 for the prerequisite and to file2
for the rule. It should be file2 in both cases.
This is documented feature of gnu make. It does variable expansion in two
passes, and expansion of rule contents is deferred until second pass.