GNU Make Overview and Guidelines | Interrupt

The two examples are a little confusing; the first one is this:

DEPFLAGS = -MMD -MP -MF $<.d

test.o: test.c
    $(CC) $(DEPFLAGS) $< -c $@

That’s building in-tree, so the test.c.d file is placed next to the test.c file. The test.c.d file might contain:

test.o: test.c test.h

test.h:

For the second example, it’s placing the .d files into the ./build output directory (out of tree). To make things simpler, the .d files are constructed for the .o targets, so they’re placed more easily into the ./build directory (which is also somewhat more idiomatic, since the .d files output by the compiler have rules for the .o file anyway!).

Those .o.d files look like:

build/src/example.o: src/example.c src/example.h

src/example.h:

Hope that helps! I’d be happy to take a look at the source if you want to share it :smile: