On Tue, 2025-05-06 at 20:16 +0800, lijh.8 via Users list for the GNU implementation of make wrote: > 1.
It's a bit hard to read your email with these HTML markers scattered throughout. I recommend you do not try to use this method for tracking header file prerequisites. Instead, look at this method: https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ > Why will the rule for `.d` dependency file be triggered when I do > `make clean`? Because you've included the .d file as a makefile, in this line: -include $(patsubst %.c,%.d,$(wildcard *.c)) Make always tries to rebuild all its included files. See: https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html > Why it tries to stop me from deleting the temporary `.d` file? I don't understand this question: how is it stopping you? Or, is this just another way of asking the same question as above? > 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? Because you are not trying to include the .o file as a makefile. > 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. I don't understand what change you are proposing to make here. You have defined a pattern rule to build .d files (e.g, "%.d : %.c") so if the .d file doesn't exist, make will invoke that recipe to try to rebuild the .d file to cause it to exist. If there is no pattern rule to build a .d file, then make will not invoke that recipe (obviously).