Creating pattern rules

From Notes_Wiki
Revision as of 08:57, 12 September 2018 by Saurabh (talk | contribs)

<yambe:breadcrumb self="Creating pattern rules">Makefile|Makefile</yambe:breadcrumb>

Creating pattern rules

Make supports implicit pattern rules for creating .o files from .c files. It is possible to extend the rule-set and create more rules to create user-defined rules. To create own rules the target must contain exactly one % character which will match with any string or length one or more. Example pattern rule is:

%.svg : %.dot ; dot -Tsvg $< > $@

Note the use of special variables $< and $@ which refer to source and target respectively in creation of pattern. Also note that pattern rule has two patterns separated by ':' then a recipe at the end separated from second pattern by ';'. This pattern rule will allow creation of .svg files from .dot files


<yambe:breadcrumb self="Creating pattern rules">Makefile|Makefile</yambe:breadcrumb>