help-make
[Top][All Lists]
Advanced

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

Re: Make rebuilds when it is not necessary


From: Ted Stern
Subject: Re: Make rebuilds when it is not necessary
Date: Tue, 07 Mar 2006 11:23:19 -0800
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

[Crossposted to OP and newsgroup gmane.comp.gnu.make.general]

On 06 Mar 2006 13:00:45 -0800, Paul Smith wrote:
>
> %% "Rupal Desai" <address@hidden> writes:
>
>   rd> $(OBJS):$(OBJDIR)/%.o: %.cpp $(OBJDIR)
>
> This is (at least one of) your problem(s).
>
> You've added OBJDIR as a prerequisite.  That means that any time OBJDIR
> is newer than the target (xxxx.o), the .o file will be considered out of
> date and rebuilt.
>
> Well, on UNIX anyway, a directory's last modified timestamp is changed
> whenever the directory is changed, which means whenever a file is added,
> removed, or renamed in that directory.
>
> So, every time a .o is created in that directory it becomes newer than
> all the .o's that were already there, and they all rebuild.
>
>
> For this reason it's virtually always a very bad idea to list a
> directory as a normal prerequisite of a target.
>
> You have two choices.  I personally prefer to simply always create the
> directory immediately when make starts, like this:
>
>     __dummy := $(shell [ -d "$(OBJDIR)" ] || mkdir -p "$(OBJDIR)")
>
> or similar.
>
> The alternative, if you have a sufficiently new version of GNU make, is
> to use order-only prerequisites:
>
>   $(OBJS):$(OBJDIR)/%.o: %.cpp | $(OBJDIR)

Another alternative: Instead of using a directory as a prerequisite,
use a "touch" file in the directory instead:

    # Touch file pattern rule
    %.touch:
          -mkdir -p $(<D); touch $<

    $(OBJS): $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.touch
          # ...

The touch file's timestamp won't be updated when the directory
contents change, but its rule will ensure that the directory is
created.

Ted
-- 
 dodecatheon at gmail dot com
 Frango ut patefaciam -- I break so that I may reveal





reply via email to

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