evoldoers / biomake

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

Prefer more specific rules over more general ones #51

Open sjackman opened 6 years ago

sjackman commented 6 years ago

When multiple pattern rules exist, GNU Make prefers the more specific rule over more general ones, that is to say, the pattern rule with the shortest stem (the shortest string matched by %). See the last few sentences of https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html

In the following example, GNU make uses the combined sort | gzip rule, whereas biomake uses the separate sort and gzip rules.

all: words.sort.txt.gz

.SECONDARY:

words.txt: /usr/share/dict/words
    cp $< $@

%.sort.txt: %.txt
    sort -o $@ $<

%.txt.gz: %.txt
    gzip -c $< >$@

%.sort.txt.gz: %.txt
    sort $< | gzip >$@
❯❯❯ make -n
cp /usr/share/dict/words words.txt
sort words.txt | gzip >words.sort.txt.gz
❯❯❯ biomake -n
   cp /usr/share/dict/words words.txt
  sort -o words.sort.txt words.txt
 gzip -c words.sort.txt >words.sort.txt.gz
Target all not materialized - build required

The workaround in this case is to put the %.sort.txt.gz: %.txt rule above the other two rules.