Re: why make clean triggers other rules
"lijh.8" via Users list for the GNU implementation of make <[email protected]> Wed, 7 May 2025 00:51:39 +0800
| Newsgroups | gmane.comp.gnu.make.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks Paul! Correct some of my misunderstanding: ``` %.d: %.c set -e; rm -f $@; \ $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ ``` the .d file depends on `.c` source file as stated in rule ` %.d: %.c `. the sed command puts the `.d` file as the target of both `.c` and `.h` files. this makes `.d` file depend on `.h` header file too. it will regenerate the `.d` file even when the header file is changed. ``` main.o : main.c defs.h main.o main.d : main.c defs.h ```