www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/06:31:11

Date: Mon, 3 Mar 1997 13:17:01 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "John M. Aldrich" <fighteer AT cs DOT com>
cc: djgpp AT delorie DOT com, "Vyacheslav O. Myskin" <V DOT O DOT Myskin AT inp DOT nsk DOT su>
Subject: Re: Another makefile question
In-Reply-To: <331A13A5.C1C@cs.com>
Message-ID: <Pine.SUN.3.91.970303131626.9009H-100000@is>
MIME-Version: 1.0

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.

- Raw text -


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