Why make a recipe in front of its premises?

I have a make file with some template rules¹ that ultimately are prerequisites for another rule. A minimal example that shows the symptoms that I am puzzled with is the following:

.PHONY: clean default one two

default: clean one two

clean:
    @rm -f {one,two}.{a,b}

one two: %: %.a %.b
    @echo TARGET $@ PREREQUISITES $^

%.a %.b:
    @echo Prereq $@
    @touch $@

The result that I expect at startup will be as follows:

Prereq one.a
Prereq one.b
RESERVE one BACKGROUND one.a one.b
Prereq two.a
Prereq two.b ASK
two BACKGROUNDS two.a two.b

Instead, only the first necessary condition is created, makegives me the following:

Prereq one.a
BOOK one BACKGROUND one.a one.b
Prereq two.a ASK
two BACKGROUND two.a two.b

, , , .

, , : .

, . , , , , :

$ make clean
$ make one
Prereq one.a
TARGET one PREREQUISITES one.a one.b
$ make one
Prereq one.b
TARGET one PREREQUISITES one.a one.b

, one. one.a , one.b. , , one .

( %a: %.b ), . , , .


¹ , , , .

+4
1

GNU Make , "" , , . , Make , . GNU :

. , . , make , . , . [...]

:

  • one: one.a one.b %: %.a %.b;
  • one.a one.b;
  • ($@), one.a (, );
  • one.a, one.b , one.a;
  • , one two.

, Make , , one.a two.a . , , , one.b two.b. one.a , one.a two.b.

, . , , , &mdash, , , , . %.a %.b , , . , , , - , :

%.a %.b:
        @echo Processing target $@ from stem $*
        touch $*.a $*.b

, , , MCVE clean . Make /bin/sh, , {a,b}. SHELL=/bin/bash, .

+5

Source: https://habr.com/ru/post/1666997/


All Articles