[Top][All Lists]

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

Re: how to create a single rule to build a directory as necessary

From: Sam Steingold
Subject: Re: how to create a single rule to build a directory as necessary
Date: Tue, 22 Sep 2009 13:19:51 -0400
User-agent: Thunderbird (X11/20090625)

Thanks for the informative reply!

Paul Smith wrote:
On Tue, 2009-09-22 at 11:44 -0400, Sam Steingold wrote:
I, too, am struggling with rebuilding a directory.
it appears that the rule:

gllib: config.status
        mkdir -p gllib; cd gllib; make

is wrong because the script "mkdir ..." is always executed, regardless of whether config.status has changed or not.
So, what is the right way to handle this?

The short answer is that using a directory as a target in make is almost
never correct, unless it's a .PHONY target or the equivalent.

so what is this SUBDIRS automake thingie?
how does it work?

Why is that?  It's because make doesn't treat directories any different
than files, when it computes whether the item is up to date: if the time
modified on the directory is newer than all its prerequisites then the
command is not executed.  If the modification time on the directory is
older than any of its prerequisites, then the command is executed.

The problem is that the modification time on a directory means something
that is not really appropriate for make: the modification time on a
directory changes whenever the DIRECTORY ITSELF changes.  When does a
directory change?  It changes whenever any element in the directory is
renamed or deleted, or a new element is created in the directory.  In
short, if you run "ls -a" before and after some command and the output
is identical, then the directory was not modified.

this makes perfect sense.
how about this addition then:

gllib: config.status
        mkdir -p gllib; cd gllib; make
        touch gllib/.stamp; rm -f gllib/.stamp

adding and removing the .stamp file will modify the directory, right?

which by the way, is not well-formed; it should be:

        mkdir -p $@ && cd $@ && $(MAKE)

I am afraid I cannot use the "gnuisms" (as they were called by a NetBSD user who was bitten by these variables when I used them)

Your problem here is more conceptual than anything.  What, in words, are
you really trying to get make to do?  How does the upper level makefile
know, really, that it does or doesn't need to invoke the sub-make?  It
can't know that... unless it invokes the submake to see whether anything
needs to be done.

I need a few files which are created in gllib by make.

Do I need to explicitly type

gllib/foo gllib/bar : config.status
        mkdir -p gllib; cd gllib; make

In a standard recursive make environment, sub-makes are almost always
set up as .PHONY, so they're always invoked, to be sure that their
content is up to date.  That's why recursive makes are slower,
typically, than non-recursive makes.

so, if I add gllib to .PHONY, the commands will be always executed, even with the .stamp trick?


reply via email to

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