makefile GNU Pattern Rules Basic Pattern Rule


A pattern rule is indicated by a single % character in the target. The % matches a non-empty string called the stem. The stem is then substituted for every % that appears in the prerequisite list.

For example, this rule:

%.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

Will match any target ending in .o. If the target was foo.o, the stem would be foo and it would compile foo.c to foo.o. Targets and prerequisites can be accessed using automatic variables.