evoldoers / biomake

GNU-Make-like utility for managing builds and complex workflows
BSD 3-Clause "New" or "Revised" License
100 stars 9 forks source link

Pattern rules with multiple targets #57

Open sjackman opened 6 years ago

sjackman commented 6 years ago

Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and recipe. If a pattern rule has multiple targets, make knows that the rule’s recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets. When searching for a pattern rule to match a target, the target patterns of a rule other than the one that matches the target in need of a rule are incidental: make worries only about giving a recipe and prerequisites to the file presently in question. However, when this file’s recipe is run, the other targets are marked as having been updated themselves.

See https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html

In this example, the command touch ook.a ook.b should be run only once. biomake runs it twice.

all: foo bar ook.ab

foo bar ook:
    touch $@

%.a %.b: %
    touch $*.a $*.b

%.ab: %.a %.b
    cat $^ >$@
❯❯❯ make -n
touch foo
touch bar
touch ook
touch ook.a ook.b
cat ook.a ook.b >ook.ab
❯❯❯ biomake -n
 touch foo
 touch bar
   touch ook
  touch ook.a ook.b
  touch ook.a ook.b
 cat ook.a ook.b >ook.ab