makefile GNU Pattern Rules Pattern Rules with multiple targets

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any makefile Question?