Carl
Carl

Reputation: 7554

make: implicit rule, (tail-)recursively applied?

I have a calculation A.N where each step depends on the previous step A.N-1 (except the first step) as well as another sequential calculation result, B.N. I'd like to express this relation in a make file:

A.001: calc.script B.001
  $^ > $@

A.%: calc.script B.% A.(%-1) # (%-1) is pseudocode for idea
  $^ > $@

I can get the second rule to work for A.002, but it won't work for A.003. The approach I used for the pseudocode part above is:

# ... A.001 rule
define dec = $(shell echo $(1)-1|bc|xargs printf '%03d') # want 3 digit #s
.SECONDEXPANSION:
A.%: calc.script B.% A.$$(call dec,$$*)
  $$^ > $$@

Is there language support for this kind of approach? I'm looking at just have having a $(foreach ..., $(eval $(call ...))) construct to build the rules, but I'd prefer a recursive approach.

Upvotes: 1

Views: 55

Answers (1)

Beta
Beta

Reputation: 99124

From the manual:

"No single implicit rule can appear more than once in a chain."

This is a feature, not a bug. The kind of recursion you want is possible in Make, but Make isn't really suited to it.

Upvotes: 1

Related Questions