Date: Mon, 3 Mar 1997 13:17:01 +0200 (IST) From: Eli Zaretskii To: "John M. Aldrich" cc: djgpp AT delorie DOT com, "Vyacheslav O. Myskin" Subject: Re: Another makefile question In-Reply-To: <331A13A5.C1C@cs.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Sun, 2 Mar 1997, John M. Aldrich wrote: > First, you have to remember that no matter what, the dependency > information won't be available until the second time you run the > makefile (unless you run Make recursively, that is). This is incorrect, AFAIK. Files included with `include' directives are treated by Make as if they were additional Makefiles. GNU Make always considers all makefiles as goal targets and attempts to update them (using the specified and/or implicit rules). After all makefiles have been checked, if any have actually been updated, GNU Make re-reads all the makefiles again and restarts, thus effectively calling itself recursively. (This is explained in more detail in the ``Remaking Makefiles'' section of the GNU Make on-line manual.) > 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?) > There's no need to mess > around with sed scripts or anything messy like that. 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. > What this bit does is look for any .d files in the current directory, > and if it finds them it includes them in the makefile. It's as simple > as that. :) 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. The method you suggest may be elegant, but it has 2 major drawbacks: 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.) 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.