makefile Pattern Rules with multiple targets


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 build both debug and release objects when one of them has to be built. If we wrote something like:

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

It would work when only one of debug/*.o or release/*.o is built, but it would only build the first target (and consider the second one to be up-to-date) when both have to be built.