On Fri, Mar 7, 2025 at 4:59 AM Paul Smith <psm...@gnu.org> wrote:
>
> On Thu, 2025-03-06 at 13:28 -0900, Britton Kerin wrote:
> > In this example, I would not expect bar to be updated due to
> > actual_source when foo is requested.  The timestamp dependency chain
> > should be broken between foo and bar and Make should be able to
> > figure that out when handling an explicit request for foo.  Is this a
> > bug?
> >
> > $ cat Makefile
> > foo: | bar
> >         cp $| $@
> >
> > bar: actual_source
> >         cp $< $@
> >
> > clean:
> >         rm -f foo bar
>
> Possibly I'm misunderstanding your test case but none of the results
> you showed look wrong to me.
>
> Order-only prerequisites are defined in what I hope is a clear way in
> this paragraph:
>
> https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html#index-order_002donly-prerequisites
>
> I'm not sure what you mean exactly by "the timestamp dependency chain
> should be broken", but nothing about the order-only status of the
> prerequisites of "foo" makes any difference when deciding whether to
> build "bar".  It only impacts "foo".
>
> If make considers "bar" for any reason, then it will be rebuilt if it
> is out of date.
>
> The only difference between making "bar" and order-only prereq vs. a
> normal prereq of "foo", is whether "foo" is updated or not when "foo"
> is out of date with respect to "bar".  Every other aspect of this
> makefile behaves the same regardless.
>
> "Order-only" means that the prerequisite is only considered to define
> an order of build operation, but doesn't impact the out-of-date
> calculations of its target.

What confuses me is that since the explicitly requested foo exists and
isn't out of date with respect to any non-order-only prereqs (in the
example it doesn't have any) and therefore isn't getting rebuilt, I
wouldn't expect there to be any need to rebuild it's order-only
prereqs either.  I would think "order-only" would only impose an order
constraint on the execution of the recipes, and since foo's recipe
isn't happening why should bar's need to?  There's no order violation
if it doesn't, and in fact it's a bit of a misuse of the term "order"
to describe the current behavior since (in the example) only one
recipe is executing.  Make is building slightly too much here which is
contrary to its purpose.

I've run into need for order-only a number of times and really
appreciate the feature.  I've read the docs on it many times and it's
always sort of bothered me as I felt my understanding was somehow
imperfect, as now indeed I find.  It's obviously far too late to even
consider changing the way this works but I do think the documentation
could be improved somehow, though I'm not sure exactly how.  It sounds
like implementation simplicity (keeping order-only prereqs
implementation almost identical to regular rules) is part of why it's
like it is.
Maybe the simple solution of explicitly documenting that order-only
prerequisites are themselves rebuilt if mentioned by a required target
even if the "depending" target itself isn't being rebuilt would be
best.

Britton

Reply via email to