Shawn, Shawn Halpenny <[EMAIL PROTECTED]> writes:
> dir/dbg/%.o : V = dir/dbg > dir/dbg/%.o : %.cpp | $$(V)/. dbg ; echo dbg-V:$(V); touch $@ > > dir/%.o : V = dir/nondbg > dir/%.o : %.cpp | $$(V)/. nondbg ; echo nondbg-V:$(V); touch $@ > > > The value of V seems to come from the nondbg pattern rule, although > the dbg pattern rule's commands are executed. I think this is also > why there is no 'mkdir -p dir/dbg' when there should be (because the > order-only 'dbg' prerequisite was run). GNU make "gathers" variables in the order they appear in the makefile. In this case the second definition of patter-specific variable V overrides the first one. > This is a serious problem for non-recursive make scenarios that make > extensive use of pattern rules for commands to build objects from > source in various subdirectories, because the pattern-specific > variable values that are used depend on the order of the rules. Agree. You can fix this in your particular case by rewriting the makefile like this: dir/%.o : V = dir/nondbg dir/dbg/%.o : V = dir/dbg dir/dbg/%.o : %.cpp | $$(V)/. dbg ; echo dbg-V:$(V); touch $@ dir/%.o : %.cpp | $$(V)/. nondbg ; echo nondbg-V:$(V); touch $@ In other words, you need to write the most specialized variable definitions last and the most specialized rules first. Some time ago I proposed changing pattern rules selection algorithm from picking the first applicable rule to picking the most specialized one (formally, the one with the shortest stem). I guess this will also be useful (or even more so) for pattern-specific variables. > I found this surprising enough to file bug 14126: > https://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=14126 Thanks, I will add a comment. hth, -boris _______________________________________________ Help-make mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-make
