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

2012-06-11 Thread Stefano Lattarini
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

OTOH, if I had invoked more than one prerequisite at the same time, I'd
have expected the ordering among them to be respected, like this:

$ make b a c # What would I expected.
c
b
a

Is this a bug in make, in its documentation, or it's just me
misunderstanding something?

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 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