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: Noel Yap
Subject: Re: Using the target of a pattern rule as a prerequisite
Date: Fri, 04 Jun 2004 10:18:45 -0400
User-agent: Mozilla Thunderbird 0.5 (Windows/20040212)

David Boyce wrote:

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

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

Say the first time you built, the file foo.h was found in /dir3. But then you - or someone else - subsequently adds a foo.h to /dir2. Now the target is out of date just as surely as if the source file was modified, but there's no way for make to know it. Even if you generate dependencies such that it sees an explicit dependency on /dir3/foo.h, it cannot know that the path search would find /dir2/foo.h instead if rebuilt.

First, I think the above is a really bad idea -- you have two files named foo.h 
and, depending upon the order of the include path, either can be included.

Having said this, things you might be able to do are:
- make clean # although I understand this'll probably rebuild too much
- use $(firstword $(wildcard)) to search the include path for the first header 
file.  This will complicate the dependencies file generation.

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

Directory timestamps are usually updated each time a file is added or removed from the directory. This can potentially lead to things being built /all/ the time (eg if an object file depended upon its directory, after the object file is built, the directory's timestamp may be later than the object file's timestamp).

HTH,
Noel





reply via email to

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