On Wed, 2025-05-07 at 00:51 +0800, lijh.8 wrote:
> 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
> ```

That is correct.

But, as said in my first reply, this is an old-fashioned and no longer
recommended way to handle prerequisite tracking.

Reply via email to