Have the compiler emit `.d` files while building objects.
Section: Generated dependency files
Generate C header dependency files
makefile
makefile
CFLAGS += -MMD -MP
build/%.o: src/%.c
cc $(CFLAGS) -c $< -o $@
-include $(OBJ:.o=.d)Explanation
A classic GNU make pattern for automatic header dependency tracking.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Generated dependency files
Include generated files safely
Load dependency files only if they exist.
Separate dependency file path
Write depfiles beside objects using explicit flags.