Re: Order-only prerequisites

2023-06-09 Thread Frank Heckenbach
Henrik Carlqvist wrote:

> On Wed, 07 Jun 2023 08:29:15 +0200
> > As I said, a way to specify in which order recipes are invoked
> > (here, a before b) if they are invoked, without influencing whether
> > they are invoked (only a, only b or a and b, as given on the command
> > line).
> 
> So you really don't want any target to depend upon another target? Then why do
> you care about the order? If order is important, what would happen if make is
> run with -j and starts several jobs in parallell? 

They should run after each other, as per the manual ("... will be
completed before ...").

Roughly speaking, my project consists of several major parts and I
want to be able to selectively rebuild them. E.g., B does depend on
A, but sometimes I want to only rebuild B even though there were
changes to A, because I don't care about those changes at the moment
and rebuilding A takes a long time.

But when I rebuild both of them, especially when I do a full
rebuild, they should be built in the order of their dependencies, as
usual.

I had hoped that order-only prerequisites would do what I want, but
I see now they don't and I'll have to do it some other way.
(Basically, I'm duplicating the rules, one copy with and one without
dependencies, "all" depends on those with dependencies, but manually
I can use those without.)

Paul Smith wrote:

> The documentation of order-only prequisites says what they're for:
> 
> > A normal prerequisite makes two statements: first, it imposes an
> > order in which recipes will be invoked: the recipes for all
> > prerequisites of a target will be completed before the recipe for the
> > target is run.  Second, it imposes a dependency relationship: if any
> > prerequisite is newer than the target, then the target is considered
> > out-of-date and must be rebuilt.
> > 
> > [Order-only prerequisites] impose a specific ordering on the rules to
> > be invoked _without_ forcing the target to be updated if one of those
> > rules is executed.
> 
> Makes treats order-only prereqs identically to "normal" prereqs in
> every way, EXCEPT that at the time where it checks to see whether the
> target needs to be rebuilt it doesn't consider the timestamps of the
> order-only prerequisites.  That's all there is.

I still suggest mentioning that they still cause the prerequisites
to be built (when necessary), and I'm still not happy with the
naming. Maybe that's because I'm a mathematician and used to exact
wording, but to me "a b" and "b a" are different orders of the same
set, but "b" and "a b" are not, so they're not about order only.



Re: Order-only prerequisites

2023-06-07 Thread Paul Smith
On Wed, 2023-06-07 at 04:20 +0200, Frank Heckenbach wrote:
> What I want to achieve is that a and b can be made independently,
> but when both of them are made, a is always made first. I assumed
> that's what order-only prerequisites are for

That's not what it's for.  In fact, you can't achieve that in GNU Make
(certainly not easily) or any other make I'm aware of.  That's because
such a feature would be quite difficult to implement without
fundamentally changing the way make is typically designed.

The documentation of order-only prequisites says what they're for:

> A normal prerequisite makes two statements: first, it imposes an
> order in which recipes will be invoked: the recipes for all
> prerequisites of a target will be completed before the recipe for the
> target is run.  Second, it imposes a dependency relationship: if any
> prerequisite is newer than the target, then the target is considered
> out-of-date and must be rebuilt.
> 
> [Order-only prerequisites] impose a specific ordering on the rules to
> be invoked _without_ forcing the target to be updated if one of those
> rules is executed.

Makes treats order-only prereqs identically to "normal" prereqs in
every way, EXCEPT that at the time where it checks to see whether the
target needs to be rebuilt it doesn't consider the timestamps of the
order-only prerequisites.  That's all there is.



Re: Order-only prerequisites

2023-06-07 Thread Henrik Carlqvist
On Wed, 07 Jun 2023 08:29:15 +0200
> As I said, a way to specify in which order recipes are invoked
> (here, a before b) if they are invoked, without influencing whether
> they are invoked (only a, only b or a and b, as given on the command
> line).

So you really don't want any target to depend upon another target? Then why do
you care about the order? If order is important, what would happen if make is
run with -j and starts several jobs in parallell? 

In practice, targets are built in the order that they are given on the command
line or as dependencies in a rule. However, there is no guarantee that any
Make is implemented that way. If you really have a need to specify the order
of things you probably have that need because of some dependency between
targets.

regards Henrik



Re: Order-only prerequisites

2023-06-07 Thread Frank Heckenbach
Henrik Carlqvist wrote:

> > Consider this makefile:
> > 
> > .PHONY: a b
> > a:; @echo a
> > b:; @echo b
> > b: | a
> 
> Your problem with this Makefile is that it never creates any files a or b.

That's why I made them phony. But that was just for demonstration.
I get the same effects with this makefile (when a and b don't exist
before):

a:; touch a
b:; touch b
b: | a

except for "'a' is up to date." instead of "Nothing to be done for 'a'.".

> > If so, is there another way to achieve what I want?
> 
> This totally depends upon what you want.

As I said, a way to specify in which order recipes are invoked
(here, a before b) if they are invoked, without influencing whether
they are invoked (only a, only b or a and b, as given on the command
line).



Re: Order-only prerequisites

2023-06-06 Thread Henrik Carlqvist
> Consider this makefile:
> 
> .PHONY: a b
> a:; @echo a
> b:; @echo b
> b: | a

Your problem with this Makefile is that it never creates any files a or b.
This means that your order only prerequisite on a allways has to be made.

> % make b a
> a
> b
> make: Nothing to be done for 'a'.
> 
> Correct order, but the last message seems strange.

First as a (order-only) prerequisite for b, a is made. Then b is made. Then
make was asked to make a but it does remember that a already has been made and
prints out that nothing to be done.

If  your Makefile would have created the file a the order-only prerequisite
would have made sense. It would then mean that b would depend upon the
existance of a but it would not care about the timestamp of a. So if a exist
and is newer than b there is no need to remake b of a is a order-only
prerequisite.

> If so, is there another way to achieve what I want?

This totally depends upon what you want.

regards Henrik



Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-12 Thread Stefano Lattarini
Hi Paul, thanks for the quick answer.

On 06/12/2012 07:14 AM, Paul Smith wrote:
 On Mon, 2012-06-11 at 18:40 +0200, Stefano Lattarini wrote:
 The GNU make 3.82 manual reads:

 Normally, this is exactly what you want: if a target's prerequisite
 is updated, then the target should also be updated.

 Occasionally, however, you have a situation where you want to impose
 a specific ordering on the rules to be invoked without forcing the
 target to be updated if one of those rules is executed.

 But if I write a makefile like this:

 ALL = a b c d
 default:
  echo Specify a target: $(ALL); exit 1
 .PHONY: $(ALL)
 $(ALL):
 @echo $@
 a: | b
 b: | c
 c: | d

 then I get:

 $ make a # Not what I expected, but what actually happened.
 d
 c
 b
 a

 which is not what I'd have expected reading the documentation above; what
 I would have expected was that a alone would be run:

 $ make a # What I expected, but did not happen.
 a
 
 No, that's not how order-only prerequisites work.  An order-only
 prerequisite is treated identically to a normal prerequisite except for
 exactly one thing: when make checks to see if a target needs to be
 remade, the time-last-modified values for any order-only prerequisites
 are not considered.

Ah, all is clear now.  Then I think we are dealing with a documentation
bug here; in particular:

  - the name order-only prerequisites is IMHO poorly chosen, and don't
really correspond to their actual semantics; a more appropriate might
be weak prerequisites or existence-only prerequisites;

  - the explanation given in the manual is imprecise and confusing; since
the explanation you've given here is OTOH very clear and concise, I
suggest you report it in the manual;

  - it might make sense to state explicitly that order-only prereqs
which are phony behaves in all ways like standard prerequisites.

 However, they are still considered prerequisites in that they are still
 built, themselves, if necessary, before the target.  Since your targets
 are all phony (and none of them update their target file either) they
 will all always be remade every time.  You can't see how order-only
 prerequisites work using this makefile.
 

Thanks,
  Stefano

___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-12 Thread Stefano Lattarini
On 06/12/2012 02:06 AM, Philip Guenther wrote:
 On Mon, Jun 11, 2012 at 12:53 PM, Stefano Lattarini
 stefano.lattar...@gmail.com wrote:
 ...
 I was hoping to be able to the order-only prerequisites to enforce ordering
 between .PHONY targets.  At this point, I guess I should state the problem
 I am trying to solve rather than just the attempts I've made at solving it.

   Is there an easy, scalable way to specify in a GNUmakefile that, whenever
   two given targets T1 and T2 (either phony or not) are to be updated, T1's
   recipe must be executed before T2's, all without declaring any dependency
   of T2 on T1?  So that for example, assuming T1 and T2 are both phony:

 $ make T1 # Only run T1's recipe
 $ make T1 # Only run T2's recipe
 
 (I think you meant make T2 there...)

Yes, sorry.

 
 $ make T2 T1 # Run T1's recipe, then T2's recipe
 $ make -j8 T2 T1 # Again, run T1's recipe, then T2's recipe
 
 I think I would use a test on $(MAKECMDGOALS) to make T1 a
 prerequisite of T2 if and only if T1 is a goal, say...
 
  ifneq ($(filter T1,${MAKECMDGOALS}),)
  T2: T1
  endif

Not good enough; the order dependency I want between T1 and T2 should
have to work also when they are updated as dependencies of other targets:

$ cat Makefile
all: T1 T2
...
$ make all # Ought to work executing T1 before T2.

Regards,
  Stefano


___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-12 Thread Philip Guenther
On Tue, Jun 12, 2012 at 12:59 AM, Stefano Lattarini
stefano.lattar...@gmail.com wrote:
 On 06/12/2012 02:06 AM, Philip Guenther wrote:
 On Mon, Jun 11, 2012 at 12:53 PM, Stefano Lattarini
 stefano.lattar...@gmail.com wrote:
 ...
 I was hoping to be able to the order-only prerequisites to enforce ordering
 between .PHONY targets.  At this point, I guess I should state the problem
 I am trying to solve rather than just the attempts I've made at solving it.

   Is there an easy, scalable way to specify in a GNUmakefile that, whenever
   two given targets T1 and T2 (either phony or not) are to be updated, T1's
   recipe must be executed before T2's, all without declaring any dependency
   of T2 on T1?  So that for example, assuming T1 and T2 are both phony:

     $ make T1 # Only run T1's recipe
     $ make T2 # Only run T2's recipe
     $ make T2 T1 # Run T1's recipe, then T2's recipe
     $ make -j8 T2 T1 # Again, run T1's recipe, then T2's recipe

 I think I would use a test on $(MAKECMDGOALS) to make T1 a
 prerequisite of T2 if and only if T1 is a goal, say...

      ifneq ($(filter T1,${MAKECMDGOALS}),)
      T2: T1
      endif

 Not good enough; the order dependency I want between T1 and T2 should
 have to work also when they are updated as dependencies of other targets:

    $ cat Makefile
    all: T1 T2
    ...
    $ make all # Ought to work executing T1 before T2.

Given the design of make, with its lazy DAG building, what you are
asking for cannot be done automatically by make, as when it hits T2 as
a prerequisite it cannot know whether a not-yet-considered target will
end up having T1 as a prerequisite.

My gut reaction is that something in this setup is over-simplifying
things or misleading make.  If T1 needs to be done before T2 _ever_,
then why not _always_ have it as a prerequisite of T2?  Is the
.PHONYness of T1 a hack to get around some other limitation and using
some sort of timestamp file would let T1 be not-.PHONY and always be a
dependency of T2?

Whatever.  Insufficient data.  Workaround: use the MAKECMDGOALS test
previously cited but list all the targets that depend on T1 as well in
the $(filter) clause.


Philip Guenther

___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-11 Thread Philip Guenther
On Mon, Jun 11, 2012 at 9:40 AM, Stefano Lattarini
stefano.lattar...@gmail.com wrote:
 The GNU make 3.82 manual reads:

    Normally, this is exactly what you want: if a target's prerequisite
    is updated, then the target should also be updated.

    Occasionally, however, you have a situation where you want to impose
    a specific ordering on the rules to be invoked without forcing the
    target to be updated if one of those rules is executed.

 But if I write a makefile like this:

    ALL = a b c d
    default:
        echo Specify a target: $(ALL); exit 1
    .PHONY: $(ALL)

What is your intent for declaring all the targets PHONY in this Makefile?

(Note: to quote 4.6 Phony Targets:
A phony target should not be a prerequisite of a real target file;
if it is, its recipe will be run every time `make' goes to update that
file.  As long as a phony target is never a prerequisite of a real
target, the phony target recipe will be executed only when the phony
target is a specified goal (*note Arguments to Specify the Goals:
Goals.).
)


Philip Guenther

___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-11 Thread Stefano Lattarini
On 06/11/2012 07:03 PM, Philip Guenther wrote:
 On Mon, Jun 11, 2012 at 9:40 AM, Stefano Lattarini
 stefano.lattar...@gmail.com wrote:
 The GNU make 3.82 manual reads:

Normally, this is exactly what you want: if a target's prerequisite
is updated, then the target should also be updated.

Occasionally, however, you have a situation where you want to impose
a specific ordering on the rules to be invoked without forcing the
target to be updated if one of those rules is executed.

 But if I write a makefile like this:

ALL = a b c d
default:
echo Specify a target: $(ALL); exit 1
.PHONY: $(ALL)
 
 What is your intent for declaring all the targets PHONY in this Makefile?

I was hoping to be able to the order-only prerequisites to enforce ordering
between .PHONY targets.  At this point, I guess I should state the problem
I am trying to solve rather than just the attempts I've made at solving it.

   Is there an easy, scalable way to specify in a GNUmakefile that, whenever
   two given targets T1 and T2 (either phony or not) are to be updated, T1's
   recipe must be executed before T2's, all without declaring any dependency
   of T2 on T1?  So that for example, assuming T1 and T2 are both phony:

 $ make T1 # Only run T1's recipe
 $ make T1 # Only run T2's recipe
 $ make T2 T1 # Run T1's recipe, then T2's recipe
 $ make -j8 T2 T1 # Again, run T1's recipe, then T2's recipe

 (Note: to quote 4.6 Phony Targets:
 A phony target should not be a prerequisite of a real target file;
 if it is, its recipe will be run every time `make' goes to update that
 file.  As long as a phony target is never a prerequisite of a real
 target, the phony target recipe will be executed only when the phony
 target is a specified goal (*note Arguments to Specify the Goals:
 Goals.).
 )
 
 
 Philip Guenther

Regards,
  Stefano

___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-11 Thread Philip Guenther
On Mon, Jun 11, 2012 at 12:53 PM, Stefano Lattarini
stefano.lattar...@gmail.com wrote:
...
 I was hoping to be able to the order-only prerequisites to enforce ordering
 between .PHONY targets.  At this point, I guess I should state the problem
 I am trying to solve rather than just the attempts I've made at solving it.

   Is there an easy, scalable way to specify in a GNUmakefile that, whenever
   two given targets T1 and T2 (either phony or not) are to be updated, T1's
   recipe must be executed before T2's, all without declaring any dependency
   of T2 on T1?  So that for example, assuming T1 and T2 are both phony:

     $ make T1 # Only run T1's recipe
     $ make T1 # Only run T2's recipe

(I think you meant make T2 there...)


     $ make T2 T1 # Run T1's recipe, then T2's recipe
     $ make -j8 T2 T1 # Again, run T1's recipe, then T2's recipe

I think I would use a test on $(MAKECMDGOALS) to make T1 a
prerequisite of T2 if and only if T1 is a goal, say...

 ifneq ($(filter T1,${MAKECMDGOALS}),)
 T2: T1
 endif


Philip Guenther

___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: order-only prerequisites don't behave as I'd have expected after reading the documentation

2012-06-11 Thread Paul Smith
On Mon, 2012-06-11 at 18:40 +0200, Stefano Lattarini wrote:
 The GNU make 3.82 manual reads:
 
 Normally, this is exactly what you want: if a target's prerequisite
 is updated, then the target should also be updated.
 
 Occasionally, however, you have a situation where you want to impose
 a specific ordering on the rules to be invoked without forcing the
 target to be updated if one of those rules is executed.
 
 But if I write a makefile like this:
 
 ALL = a b c d
 default:
   echo Specify a target: $(ALL); exit 1
 .PHONY: $(ALL)
 $(ALL):
 @echo $@
 a: | b
 b: | c
 c: | d
 
 then I get:
 
 $ make a # Not what I expected, but what actually happened.
 d
 c
 b
 a
 
 which is not what I'd have expected reading the documentation above; what
 I would have expected was that a alone would be run:
 
 $ make a # What I expected, but did not happen.
 a

No, that's not how order-only prerequisites work.  An order-only
prerequisite is treated identically to a normal prerequisite except for
exactly one thing: when make checks to see if a target needs to be
remade, the time-last-modified values for any order-only prerequisites
are not considered.

However, they are still considered prerequisites in that they are still
built, themselves, if necessary, before the target.  Since your targets
are all phony (and none of them update their target file either) they
will all always be remade every time.  You can't see how order-only
prerequisites work using this makefile.



___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make