Chain of pattern rule and non-terminal match-anything rule

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Chain of pattern rule and non-terminal match-anything rule

Renaud Pacalet
With the following Makefile:

# Makefile
%.dat: aa
        touch $@

%:
        mkdir -p $@

invoking `make -d aa/bb.dat` produces:

GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
 Considering target file 'Makefile'.
  Looking for an implicit rule for 'Makefile'.
  Trying pattern rule with stem 'Makefile'.
  Found an implicit rule for 'Makefile'.
  Finished prerequisites of target file 'Makefile'.
 No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'aa/bb.dat'.
 File 'aa/bb.dat' does not exist.
 Looking for an implicit rule for 'aa/bb.dat'.
 Trying pattern rule with stem 'bb'.
 Trying rule prerequisite 'aa'.
 Trying pattern rule with stem 'bb.dat'.
 Trying implicit prerequisite 'aa/bb.dat,v'.
 Trying pattern rule with stem 'bb.dat'.
 Trying implicit prerequisite 'aa/RCS/bb.dat,v'.
 Trying pattern rule with stem 'bb.dat'.
 Trying implicit prerequisite 'aa/RCS/bb.dat'.
 Trying pattern rule with stem 'bb.dat'.
 Trying implicit prerequisite 'aa/s.bb.dat'.
 Trying pattern rule with stem 'bb.dat'.
 Trying implicit prerequisite 'aa/SCCS/s.bb.dat'.
 Trying pattern rule with stem 'bb'.
 Trying rule prerequisite 'aa'.
 Looking for a rule with intermediate file 'aa'.
  Avoiding implicit rule recursion.
  Trying pattern rule with stem 'aa'.
  Trying implicit prerequisite 'aa,v'.
  Trying pattern rule with stem 'aa'.
  Trying implicit prerequisite 'RCS/aa,v'.
  Trying pattern rule with stem 'aa'.
  Trying implicit prerequisite 'RCS/aa'.
  Trying pattern rule with stem 'aa'.
  Trying implicit prerequisite 's.aa'.
  Trying pattern rule with stem 'aa'.
  Trying implicit prerequisite 'SCCS/s.aa'.
 No implicit rule found for 'aa/bb.dat'.
 Finished prerequisites of target file 'aa/bb.dat'.
Must remake target 'aa/bb.dat'.
make: *** No rule to make target 'aa/bb.dat'.  Stop.

If I change the non-terminal match-anything rule such that it is not
match-anything any more:

# Makefile
%.dat: aa
        touch $@

%a:
        mkdir -p $@

then I get:

$ make aa/bb.dat
mkdir -p aa
touch aa/bb.dat
rm aamake: unlink: aa: Is a directory

which I perfectly understand (I think). So, the problem with the first
Makefile has something to do with non-terminal match-anything rules.

I have read several times all sections of the GNU make manual that I
thought were relevant but I still don't understand why make does not use
the non-terminal match-anything rule to build `aa`. I suspect that this
has something to do with the "Avoiding implicit rule recursion" debug
message.

Does anybody know where this behaviour comes from or what part of the
GNU make manual explains this behaviour?
--
Renaud Pacalet
Télécom ParisTech - LabSoC, c/o EURECOM
Campus SophiaTech,
450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
Tel : +33 (0) 4 9300 8402
Web : http://www.telecom-paristech.fr/

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Chain of pattern rule and non-terminal match-anything rule

Renaud Pacalet


On 10/01/2019 11:55, Renaud Pacalet wrote:

> With the following Makefile:
>
> # Makefile
> %.dat: aa
> touch $@
>
> %:
> mkdir -p $@
>
> invoking `make -d aa/bb.dat` produces:
> ...
> Must remake target 'aa/bb.dat'.
> make: *** No rule to make target 'aa/bb.dat'.  Stop.
> ...
> Does anybody know where this behaviour comes from or what part of the
> GNU make manual explains this behaviour?

I think I found it in a comment in the source code:

$ git rev-parse --short HEAD
214865e
$ sed -n '321,323p;323q' src/implicit.c
          /* Rules that can match any filename and are not terminal
             are ignored if we're recursing, so that they cannot be
             intermediate files.  */

Shouldn't this be explicit in the documentation? Is it?
--
Renaud Pacalet

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make