delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/19/17:12:58

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: OT: `make clean' wants to rebuild `.d' files
Date: Wed, 19 Apr 2000 22:25:53 +0100
Organization: Customer of Planet Online
Lines: 37
Message-ID: <u66sfso397b17skt2lk2du0pijk1paa437@4ax.com>
References: <200004191406 DOT JAA04929 AT darwin DOT sfbr DOT org>
NNTP-Posting-Host: modem-108.boron.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: news5.svr.pol.co.uk 956180317 10227 62.136.4.108 (19 Apr 2000 21:38:37 GMT)
NNTP-Posting-Date: 19 Apr 2000 21:38:37 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019