Hi community,
1. Why will the rule for `.d` dependency file be triggered when I do `make clean`? Why it tries to stop me from deleting the temporary `.d` file? I define an explicit pattern rule for `.o` object file, and there is also an implicit rule for it. Why rule for `.o` object file is not triggered? 2. And that sed command put the `.d` file to the target, so if a `.d` file is deleted, it will be regenerated. If i do not use this the rule `.d` dependency and just put ` CPPFLAGS := -MMD `, when a `.d` file is deleted, it will not be generated. Am I correct? Thanks ``` CFLAGS := -g CPPFLAGS := main: $(patsubst %.c,%.o,$(wildcard *.c)) -include $(patsubst %.c,%.d,$(wildcard *.c)) clean: ; $(RM) *.o *.d main .PHONY: clean %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< %.d: %.c set -e; rm -f $@; \ $(CC) -MM -MP $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ ``` --- ``` $ ls foo.h main.c Makefile $ $ make set -e; rm -f main.d; \ cc -MM -MP -g main.c > main.d.$$; \ sed 's,\(main\)\.o[ :]*,\1.o main.d : ,g' < main.d.$$ > main.d; \ rm -f main.d.$$ cc -g -c -o main.o main.c cc main.o -o main $ $ ls foo.h main main.c main.d main.o Makefile $ $ make clean rm -f *.o *.d main $ $ ls foo.h main.c Makefile $ $ make clean set -e; rm -f main.d; \ cc -MM -MP -g main.c > main.d.$$; \ sed 's,\(main\)\.o[ :]*,\1.o main.d : ,g' < main.d.$$ > main.d; \ rm -f main.d.$$ rm -f *.o *.d main $ $ ls foo.h main.c Makefile $ ```