prerequisites alter choice of pattern match rules?

2013-02-25 Thread Brian J. Murrell
Hi,

I have run into something I find strange with GNU Make 3.81 (yes, I know
3.82 is latest but since it's not in EL6, my target platform, I cannot
depend on it's features).

I would think that given the following set of rules:

/tmp/%.foo: %.foo
echo foo rule 1
touch $@

%.foo:
echo foo rule 2
touch $@

/tmp/%.bar:
make $*.bar
echo bar rule 1
touch $@

%.bar:
echo bar rule 2
touch $@

Trying to create a target of /tmp/a.foo and /tmp/a.bar should result in
the same rules being run but they don't:

$ ls -l . /tmp/a.bar /tmp/a.foo
ls: cannot access /tmp/a.bar: No such file or directory
ls: cannot access /tmp/a.foo: No such file or directory
.:
total 4
-rw-rw-r--. 1 brian brian 176 Feb 25 08:48 Makefile
$ make /tmp/a.foo
echo foo rule 2
foo rule 2
touch /tmp/a.foo
$ make /tmp/a.bar
make a.bar
make[1]: Entering directory `/home/brian/chroma/deps/lustre/test'
echo bar rule 2
bar rule 2
touch a.bar
make[1]: Leaving directory `/home/brian/chroma/deps/lustre/test'
echo bar rule 1
bar rule 1
touch /tmp/a.bar

It would seem that for the /tmp/a.foo, the /tmp/%.foo pattern rule is
not being chosen but for /tmp/a.bar the /tmp/%.bar pattern rule is
being chosen.  The only difference in those choices I can see is that
the /tmp/%.foo pattern rule has a prerequisite and the /tmp/%.bar
one doesn't.

So the question is, why does a prerequisite change the behavior of
pattern match rules?  I would think the selection of a pattern match
rule would be independent of prerequisites but of course once the
pattern match rule was chosen, the rule for the prerequisite would also
need to be called to ensure it's freshness.

Thoughts?

b.



signature.asc
Description: OpenPGP digital signature
___
Bug-make mailing list
Bug-make@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-make


Re: prerequisites alter choice of pattern match rules?

2013-02-25 Thread Sebastian Pipping
On 25.02.2013 14:57, Brian J. Murrell wrote:
 Hi,
 
 I have run into something I find strange with GNU Make 3.81 (yes, I know
 3.82 is latest but since it's not in EL6, my target platform, I cannot
 depend on it's features).
 
 I would think that given the following set of rules:
 
 /tmp/%.foo: %.foo
   echo foo rule 1
   touch $@
 
 %.foo:
   echo foo rule 2
   touch $@
 
 /tmp/%.bar:
   make $*.bar
   echo bar rule 1
   touch $@
 
 %.bar:
   echo bar rule 2
   touch $@
 
 [..]

 $ make /tmp/a.foo
 echo foo rule 2
 foo rule 2
 touch /tmp/a.foo
 $ make /tmp/a.bar
 make a.bar
 make[1]: Entering directory `/home/brian/chroma/deps/lustre/test'
 echo bar rule 2
 bar rule 2
 touch a.bar
 make[1]: Leaving directory `/home/brian/chroma/deps/lustre/test'
 echo bar rule 1
 bar rule 1
 touch /tmp/a.bar
 
 It would seem that for the /tmp/a.foo, the /tmp/%.foo pattern rule is
 not being chosen but for /tmp/a.bar the /tmp/%.bar pattern rule is
 being chosen.  The only difference in those choices I can see is that
 the /tmp/%.foo pattern rule has a prerequisite and the /tmp/%.bar
 one doesn't.

Confirming the same behavior for make 3.82.


It seems like normally GNU make walks the path of the most specific
match in case of ambiguities.  I wonder if that's specified/documented
anywhere.  For this Makefile

  xxx%:
@echo '$@ -- xxx%'

  x%:
@echo '$@ -- x%'

  xx%:
@echo '$@ -- xx%'

the most specific rule is chosen one might expect:

  # make x1 xx2 xxx3 4
  x1 -- x%
  xx2 -- xx%
  xxx3 -- xxx%
  4 -- xxx%


Side notes on the above Makefile:

 - make $*.bar in there does not seem to be relevant.
   After removing that line, the file still reproduces your case.

 - make $*.bar should be $(MAKE) $*.bar, use $(MAKE)
   to invoke make to not run into parallel build issues

 - To reduce output noise, you can use lines like

 @echo foo rule 1
 ^
   instead of

 echo foo rule 1


 So the question is, why does a prerequisite change the behavior of
 pattern match rules?

Good question.

Best,



Sebastian


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


Re: prerequisites alter choice of pattern match rules?

2013-02-25 Thread Philip Guenther
On Mon, Feb 25, 2013 at 2:30 PM, Sebastian Pipping
sebast...@pipping.org wrote:
...
 It seems like normally GNU make walks the path of the most specific
 match in case of ambiguities.  I wonder if that's specified/documented
 anywhere.

Yes, it is.  I don't remember where, but it's in the docs.


Philip Guenther

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


Re: prerequisites alter choice of pattern match rules?

2013-02-25 Thread Philip Guenther
On Mon, Feb 25, 2013 at 5:57 AM, Brian J. Murrell br...@interlinx.bc.ca wrote:
 I would think that given the following set of rules:

 /tmp/%.foo: %.foo
 echo foo rule 1
 touch $@

 %.foo:
 echo foo rule 2
 touch $@

 /tmp/%.bar:
 make $*.bar
 echo bar rule 1
 touch $@

 %.bar:
 echo bar rule 2
 touch $@

 Trying to create a target of /tmp/a.foo and /tmp/a.bar should result in
 the same rules being run but they don't:
...
 It would seem that for the /tmp/a.foo, the /tmp/%.foo pattern rule is
 not being chosen but for /tmp/a.bar the /tmp/%.bar pattern rule is
 being chosen.  The only difference in those choices I can see is that
 the /tmp/%.foo pattern rule has a prerequisite and the /tmp/%.bar
 one doesn't.

 So the question is, why does a prerequisite change the behavior of
 pattern match rules?  I would think the selection of a pattern match
 rule would be independent of prerequisites but of course once the
 pattern match rule was chosen, the rule for the prerequisite would also
 need to be called to ensure it's freshness.

 Thoughts?

When there's no explicit rule for a target (i.e., a rule where the
exact target name is listed), the algorithm for chosing the implicit
rule to apply first checks for rule(s) for which all the prerequisites
either already exist or are explicitly listed as targets themselves,
or have no prerequisites**.  Only if all the pattern rules have at
least one non-existent prerequisite that isn't explicitly listed
elsewhere does make then recursively try chaining to other rules for
each of the (missing) prerequisites.  Yes, this behavior is documented
in the info pages in more than sufficient detail to be sure that it
was clearly intended.

You ask why that's done.  To really answer that question I think you
would have to find and review the discussions among the developers
when it was actually added to GNU make, presumably back when Roland
was the maintainer.  The answer might be because that's how Stu
Feldman's version of make did it.  Or maybe it was too slow if we
tried all the possible chains, and we also wanted some way other than
order-in-the-makefile to prefer a rule.  Or if there's a direct way
to build something, it must obviously be the right choice over
something which requires an intermediate file; if you don't want that,
then you should craft your patterns and filename choices so that you
don't get overlapping patterns!

...but I wasn't there and those are just guesses.


Philip Guenther


** if there are no prerequisites, then all of the prereqs are present;
the list of missing prereqs is empty.

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