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: Paul D. Smith
Subject: Re: Make rebuilds when it is not necessary
Date: Mon, 6 Mar 2006 16:00:45 -0500

%% "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)

-- 
-------------------------------------------------------------------------------
 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]