help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the target of a pattern rule as a prerequisite


From: Paul D. Smith
Subject: Re: Using the target of a pattern rule as a prerequisite
Date: Fri, 4 Jun 2004 10:12:47 -0400

%% David Boyce <address@hidden> writes:

  db> This whole conversation seems to be conflating the concept of
  db> "having a directory as a prerequisite" with that of "having a
  db> directory as a target".  Paul says that depending on a directory
  db> isn't a good idea, and maybe that's true where the goal is to
  db> create dirs automatically, but there's a different situation where
  db> depending on a directory is always (IMO of course) a good idea:
  db> when a (non-target) directory appears on a searched path.

  db> The canonical example is where you compile with a series of -I flags:

  db>          % cc -I/dir1 -I/dir2 -I/dir3 -I/dir4 ...

  db> Say the first time you built, the file foo.h was found in
  db> /dir3. But then you - or someone else - subsequently adds a foo.h
  db> to /dir2. Now the target is out of date just as surely as if the
  db> source file was modified, but there's no way for make to know
  db> it.

True.

  db> The only solution to this is to treat the directories searched (in
  db> any path, -I or -L or potentially even $PATH) as
  db> prerequisites. It's not hard to use standard GNU make functions to
  db> grab the -I or -L flags from CFLAGS or LDFLAGS or wherever and
  db> list them as explicit dependencies. If there's an argument for why
  db> that's a bad idea, I haven't heard it.

The reason is that you get a lot of unnecessary rebuilds.

99% of the time when the directories dir2 or dir3 are changed it _WON'T_
be because someone created a new header that eclipses an existing one
(at least that's true in the build systems I work with--such an
eclipsing header would be considered very bad style).

Recall that directory modification times change whenever any
file/subdirectory is added, removed, or renamed in that directory.  That
makes for a lot of timestamp changes, the vast majority of which don't
require you to rebuild at all.

Of course, it may be worth doing anyway for the extra security in your
builds; that's a tradeoff everyone has to decide for themselves.  But
adding directories containing global header files which are fairly
stable is one thing.  Adding as a prerequisite the directory where
you'll put all the DOs your build creates is something else again!

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]