On Thu, 28 May 2009, Yavor Doganov wrote:
[...]
> > Doesn't the above rule mean that before rebuilding lib.so we must have 
> > both build-%/rsrc.res and build-%/main.o?
> 
> In general -- yes, but this is not guaranteed.  Make simply decides it
> can go on without rsrc.res here:
> 
> ,---- (make)Chained Rules ----
> |    The first difference is what happens if the intermediate file does
> | not exist.  If an ordinary file B does not exist, and `make' considers
> | a target that depends on B, it invariably creates B and then updates
> | the target from B.  But if B is an intermediate file, then `make' can
> | leave well enough alone.  It won't bother updating B, or the ultimate
> | target, unless some prerequisite of B is newer than that target or
> | there is some other reason to update that target.
> `-----------------------------

I take this to mean that the lack of file B does not mean that targets 
that depend on it must be rebuilt. Instead make follows the trail until 
it finds B's prerequisites takes their timestamps into account instead 
of B's timestamp.

However I do not take the above as meaning that targets that depend on B 
can be rebuilt without rebuilding B.

Here's the example they give in the previous paragraph:

,------------------------
| Sometimes a file can be made by a sequence of implicit rules.  For
| example, a file `N.o' could be made from `N.y' by running first Yacc
| and then `cc'.  Such a sequence is called a "chain".
| ...
|
|   However, even if `N.c' does not exist and is not mentioned, `make'
| knows how to envision it as the missing link between `N.o' and `N.y'!
| In this case, `N.c' is called an "intermediate file".  Once `make' has
| decided to use the intermediate file, it is entered in the data base 
| as if it had been mentioned in the makefile, along with the implicit 
| rule that says how to create it.
`------------------------

So here N.o depends on N.c which depends on N.y, all through implicit 
rules. If make where to try to rebuild N.o without first creating an N.c 
file then it would be a bug.

But let's say we have something like this:

%.o: %.c foo.h
        some command

Now N.o would still depend on N.c and ultimately on N.y, but it would 
also depend on foo.h. And you're telling me that because of this extra 
dependency, make would be right to try to rebuild N.o without first 
creating N.c?

This would in effect mean that N.o depends on N.c *or* foo.h.

I don't see how this could be considered anything but a bug.


So applied to the makefile I posted it means that there is no reason to 
rebuild build-foo/lib.so just because there is no build-foo/rsrc.res 
file. Following the implicit dependencies make sees that 
build-foo/lib.so only needs to be rebuilt if rsrc.rc.in or main.c are 
newer.

However if make decides to rebuild build-foo/lib.so for any reason, then 
doing so when there's no build-foo/rsrc.res file is a bug.



> This is a common parallel-safety bug in makefiles, I'd say.  Having
> pattern rules with multiple prerequisites which are derived via
> chained rules is a luxury,

Hmm, not sure where you're going with that but...

> so you'd have to take the necessary steps to convince make about the 
> order of dependencies.

STOP STOP STOP

Where does this 'order of dependencies' come from? Where do you see any 
dependency order issue in the makefile I posted?

Where, in the makefile I posted, do you see any dependency, explicit or 
implicit in the build commands, between rsrc.res/rsrc.rc.in/rsrc.rc and 
main.o/main.c?


[...]
> > What do you suggest?
> 
> I'd mark it as .PRECIOUS, but there are several approaches depending
> on what you actually want to achieve in the real-life case.  I don't
> think this is a make bug, though.

,------------------------
| .PRECIOUS
| The targets which .PRECIOUS depends on are given the following special 
| treatment: if make is killed or interrupted during the execution of 
| their commands, the target is not deleted. See Interrupting or Killing 
| make. Also, if the target is an intermediate file, it will not be 
| deleted after it is no longer needed, as is normally done. See Chains 
| of Implicit Rules. In this latter respect it overlaps with the 
| .SECONDARY special target.
`------------------------

I think that not deleting the file if make is interrupted is wrong. 
.SECONDARY does not do this which is why I chose it as a better 
workaround.


-- 
Francois Gouget <[email protected]>              http://fgouget.free.fr/
          tcA thgirypoC muinelliM latigiD eht detaloiv tsuj evah uoY



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to