help-make
[Top][All Lists]
Advanced

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

Re: first questions - which timestamp does make use & can someone explai


From: Paul Smith
Subject: Re: first questions - which timestamp does make use & can someone explain this old style syntax for phony target
Date: Mon, 29 Jul 2013 00:56:19 -0400

On Mon, 2013-07-29 at 13:04 +1000, Richard McLean wrote:

> 1.  Can someone elaborate a little on the algorithm Make uses to
> determine when a file is out of date ?
> -in the manual and the book, it says the file's modification time
> -does this represent the ctime or the mtime ?
> -are there any other factors determining whether a file is out of
> date ?
> -I found on a web page somewhere (could have been about non-GNU make)
> that file size was also used... is that true ?

mtime == modification time.  That's the only time that's used.

There is no standard make program that uses anything other than mtime.
Other make-like programs may use other things.  The critical thing to
know is that GNU make, and all traditional makes, have no "database"
they maintain of information from the previous build.  They use _only_
information provided by the filesystem: the mtime.  And they _only_
compare the current mtime to current mtimes of prerequisites to see
which is newer.  Make is completely stateless from invocation to
invocation, other than the state automatically kept by the filesystem.

If a make program wanted to use any other information, such as file
size, a checksum, etc. then it would have to maintain its own database
of the previous values from the last time it ran, so they could be
compared.  This is obviously possible, but it's a significant difference
from how make traditionally works.

> An old fashioned, slightly less intuitive way of producing the same
> effect (as declaring a target .PHONY) is to add another rule for the
> target with no prerequisites and no commands :
> 
> bin : circle
>       $(MKDIR)  $@
>       $(CP)  $<  $@/
>       $(CHMOD)  600  $@/$<
> 
> bin:

This is not the same thing as .PHONY at all.  Is this verbatim from the
O'Reilly book?  If so that's a bad mistake in that book.

It would be close to the same thing if the final, empty target was
"circle" and not "bin"; see below.

>  The .PHONY target is preferable if only because it is so explicit,
> but you may see the other technique in automatically generated
> dependency rules, for example.

The .PHONY target is also preferable because it's more efficient,
especially for targets with no recipe: GNU make knows to not bother to
try to perform implicit rule search on those targets.

> I was under the impression that the final prerequisite list for a
> given target is the concatenation of all the prerequisites listed for
> that target which can appear in several rules.  Why doesn't the line
> "bin:", just add zero additional prerequisites to the list and do
> nothing else ?

It does.

> Why does the "old fashioned" code have the same effect as the .PHONY
> code ?

The code you show above does not have the same effect.  The "old
fashioned" method is to have a _prerequisite_ be a target with no
prerequisites or recipe, which forces the target to be rebuilt.  The GNU
make manual describes this in the section _Rules with Recipes or
Prerequisites_:

http://www.gnu.org/software/make/manual/html_node/Force-Targets.html

        If a rule has no prerequisites or recipe, and the target of the
        rule is a nonexistent file, then make imagines this target to
        have been updated whenever its rule is run. This implies that
        all targets depending on this one will always have their recipe
        run.

        An example will illustrate this:
        
             clean: FORCE
                     rm $(objects)
             FORCE:

Note how this is not the same thing at all as your example.




reply via email to

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