Message-ID: <331B8C81.5933@cs.com> Date: Mon, 03 Mar 1997 18:44:17 -0800 From: "John M. Aldrich" Reply-To: fighteer AT cs DOT com Organization: Two pounds of chaos and a pinch of salt MIME-Version: 1.0 To: Eli Zaretskii CC: djgpp AT delorie DOT com, "Vyacheslav O. Myskin" Subject: Re: Another makefile question References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: > > > 1) Add -MD to the list of compiler options. This causes gcc to produce > > a .d file for each source file automatically. > > -MD doesn't prevent compilation like -M does, which makes dependency > generation slower. If at all (see below), I suggest using -MMD rather > than -MD; the former omits system headers from the dependencies (you > will hardly care about your program being dependent on stdio.h, right?) Umm... '-MD' doesn't prevent compilation either last I noticed. I use it all the time as part of my standard compiler flags in makefiles and have never seen any kind of slowdown. Is there something I missed? Anyway, I would most certainly like to know if any of the system header files change! For example, if I've updated to a new version of DJGPP, it would be wise for my programs to be recompiled, wouldn't it? At least, this makes a great deal of sense to me. :) > The Sed script makes the .d be a dependency of its corresponding .c > and the header files which .c includes. If you omit it, changing the > .c (e.g., to include additional header files) won't update the .d > file, which is a Bad Thing. Hmm... of course you are right here. But isn't it a moot point, considering that Make will recognize that the .c file has been changed and recompile it anyway? The only real use for the .d dependency information is if you change a header file without changing the source code itself. But in this case, the .d file will already be there and Make will be happy. > But if it doesn't find them, it doesn't care! Question: what will > happen if some .d file has somehow, by omission or commission, been > deleted? Answer: nothing; Make couldn't care less. There is perhaps the only real problem. That's why I always include a list of "primary" dependencies in my makefiles, listing any of my own header files that my projects depend on. > 1) It doesn't cause Make to be aware of the *necessity* of the > .d files. (They are generated as a side effect of using -MD, but Make > doesn't know that.) But they aren't necessary, except in the rare case you mentioned above when somebody both deletes the .d files _and_ changes one or more of the dependent headers without changing the source itself. It seems to be to be quite a lot of trouble to go to for a very minor result. :) > 2) The .d files are generated only when the corresponding .c > file is compiled. This is unsafe because when the Makefile is read, > the .d files might have stale info. See my above point. The only point of having the .d files around is for when a header file is changed without corresponding modifications to the .c files that use it. However, if a .c file is changed to add or delete a header file, it will be recognized by Make as changed and recompiled whether or not there is a .d file associated with it. So the "out-of-dateness" of the .d file won't matter a bit. Just my 2 bits worth. :) -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | | Plan: To find ANYONE willing to | http://www.cs.com/fighteer | | play Descent 2 on DWANGO! | Tagline: | ---------------------------------------------------------------------