Mail Archives: djgpp/2000/04/19/17:12:58
Jeff Williams <jeffw AT darwin DOT sfbr DOT org> wrote:
> As described in the info file for `make', I am using a pattern rule to
> generate `.d' files for each C source file, then including the `.d'
> files, as follows:
>
> depends=$(sources:.c=.d)
> include $(depends)
>
> But now `make clean' will insist on remaking any stale `.d' files
> before deleting anything (including the `.d' files!). And `make info'
> will remake stale `.d' files which have nothing to do with the `.txi'
> sources! This is really annoying; I understand why this is happening,
Is it because you include the the .d files, and so they effectively
become targets even with `make info'? Also the reason you need a .c.d
rule (which you did not show) is because otherwise make would complain
the first time it is run, or after `make clean', that the .d files to
include do not exist?
> but is there a more efficient way to include the `.d' files?
This is my two line solution to managing header dependencies.
First add -MMD to the preprocessor flags, and then -include the .d
files (with the '-' make does not complain if they do not exist):
CPPFLAGS += -MMD
-include $(sources:.c=.d)
No rule to build the .d files is required. The .d files are not
required initially because the first `make' will compile every .c file
anyway. From then on the .d files will be included. If a .c file
changes it will be recompiled and the .d file will be updated.
I have been using the above solution to manage header dependencies for
a while now and have noticed no ill effects. If anyone can see a
downside to this method then of course please let me know!
- Raw text -