Francois Gouget wrote:
> 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?
No.
Make in fact sees the first prerequisite of your rule, and knows how
to rebuild it. Because these two prerequisites do not depend on each
other, when the build is run in parallel make is free to process them
together. And because make is smart enough to determine that your
.res file is an intermediate prerequisite whose own downstream
dependencies have not changed, it doesn't even attempt to rebuild it.
In fact some of make's own built-in rules are not parallel-safe...
Automake goes into great pain to circumvent such problems, and they
don't even use pattern rules because they're not portable.
> 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.
Exactly.
> 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.
Right, that's why it succeeds the first time. BTW, this is perfectly
parallel-safe, I think:
build-%/lib.so: build-%/rsrc.res build-%/main.o
cat $^ >$@ || rm $@
build-%/rsrc.res: build-%/rsrc.rc
cat $< >$@ || rm $@
build-%/rsrc.rc: rsrc.rc.in
mkdir -p `dirname $...@`
cat $< >$@ || rm $@
build-%/main.o: main.c
mkdir -p `dirname $...@`
cat $< >$@ || rm $@
Here everything is treated like intermediary files, and because they
are always deleted, the commands are always run.
> Where do you see any dependency order issue in the makefile I
> posted?
I just suggested a workaround. A better one would be to use
.SECONDARY, as it's close to what you want in practice, I think: your
real sources are main.c and rsrc.rc.in.
> 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.
Well, .PRECIOUS is useful in many situations, that's why it exists.
You are correct that sometimes it's not the right thing to use it.
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]