Tutorial by Examples

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 ...
If a target matches multiple pattern rules, make will use the one whose prerequisites exist or can be built. For example: %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ %.o: %.s $(AS) $(ASFLAGS) $< -o $@ Will compile foo.c to foo.o or assemble foo.s to foo.o, depending on which one of foo...
If the target pattern doesn't contain slashes, make will remove the directory part from the target it's trying to build before matching. The directory will then be put in front of the stem. When the stem is used to build the target name and prerequisites, the directory part is stripped from it, the ...
Pattern rules can have multiple targets but, unlike normal rules, the recipe is responsible for making all the targets. For example: debug/%.o release/%.o: %.c $(CC) $(CFLAGS_DEBUG) -c $< -o debug/$*.o $(CC) $(CFLAGS_RELEASE) -c $< -o release/$*.o Is a valid rule, which will buil...

Page 1 of 1