help-make
[Top][All Lists]
Advanced

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

Re: make always builds, part 2


From: Paul Smith
Subject: Re: make always builds, part 2
Date: Tue, 15 Nov 2011 07:53:09 -0500

On Tue, 2011-11-15 at 00:24 -0600, Edgar wrote:
> I can't get my makefile to work correctly. I have an .a file that 
> depends on .o files that depend on .d files that depend on an output 
> object directory existing. The problem is that the d files always
> build because make says the directory is newer than the d files, but
> it was created 8 days ago, and the d files were just created.

You appear to be running your builds in Windows; some aspects of the
Windows filesystem are not the same as other systems so some of my
comments below might not be 100% accurate for Windows.  You might
consider asking on the make-w32 mailing list which is specifically for
people using GNU make on Windows.

However it's possible that your problem is the same as it would be on a
POSIX-based system; if you were on a POSIX-based system then this would
be the problem:

Recall that make cares about the modification time of its targets and
prerequisites, not the creation time.  You're under the impression that
the modification time of a directory is set at the time it was created
and not changed, but that's not true: the modification date of a
directory is updated every time the directory is modified.  On POSIX
systems a directory is considered modified any time a file or
subdirectory is created, removed, or renamed in that directory.

It's almost never correct to list a directory as a prerequisite in a
make rule.


There are three ways you can get directories to exist:

First you can use $(shell ...) in an immediate context, which will
create the directory as soon as the makefile is read in, before any
recipe wants to use it:

        __dummy := $(shell mkdir $(OBJDIRECTORY))

Second, you can create it as a side-effect of every target that needs it
(in the script for that target).

And third, you can use order-only prerequisites:

        %.d : %.cpp | $(OBJDIRECTORY)
                ...

See the GNU make manual for details.

Also note that (a) you should never use explicit compiler names or flags
in your real makefiles, always use variables, and (b) there's a better
method of generating automated dependencies, described at my site below.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "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]