I am reading dist section of Makefile.
It contains syntax which is unknown to me: http://www.gnu.org/software/make/manual/make.html#Pattern-Rules
Why do one want to use rules like "%-operation: echo ..." ? "all-recursive", "clean-recursive", "install-recursive", "uninstall-recursive", "distcheck-recursive" - they all match to rule %-recursive,
I don't understood how that % rule works differently in these different cases
I'm not sure I understand your question: it's not very clear.
However, what I think you're asking is, if the same rule is used for a family of targets (that match the %
pattern character) then how do you know what the real target is?
This is done using automatic variables. These are helpful in any rule to reduce typos and make recipes easier to read, but they were originally created for use in implicit rules and they're absolutely essential there.
In the recipe of the pattern rule, the $@
variable will expand to the name of the target being built, $<
will expand to the first prerequisite, and $*
will expand to the part of the target that matched the pattern. So for a rule like this:
%-foo : %-bar
echo $@ / $< / $*
when make builds a target blah-foo
, the output will be:
blah-foo / blah-bar / blah