help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to adding pathes to dependencies in rules of `.d` files


From: Paul Smith
Subject: Re: How to adding pathes to dependencies in rules of `.d` files
Date: Sat, 04 Mar 2023 12:37:10 -0500
User-agent: Evolution 3.46.4 (by Flathub.org)

On Sat, 2023-03-04 at 21:49 +0800, ljh wrote:
> I managed to do out-of-source build.
> 
> I use `CPPFLAGS += -MMD -MP` to generate `.d` files. 
> The `.d` files and the source files are not in the same directory
> now.  `make` addes path the the target `.o` part, 
> but not the prerequisites parts `.c`, `.h`.
> 
> So, the rules in `.d` files will not take effect.
> Now, If I `touch` my `.h` files, it will not re-build the source
> files.

You're incorrect about the problem you're having.

You don't need any paths on the prerequisites.  The compiler puts the
paths that it found the files at, into the dependency file.  If it
found them there before, it will find them there again.  If they can't
be found, then both make AND the compiler will throw errors saying so,
they won't just quietly not recompile things.

The bug in your makefile has nothing to do with the content of the .d
files, it's right here:

> -include $(shell find . -type f -name "*.d")

This is being invoked from the source directory (where foo.c and foo.h
live), and it's running a find for all the "*.d" files under the
current directory ".".  But, there are no "*.d" files there; all the
"*.d" files are living under the $(DIR) out-of-source directory.  So
this find command expands to the empty string, and you include no
files, and so none of your prerequisite statements are present, and
make doesn't rebuild anything when the header files change.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]