Phydeaux
Phydeaux

Reputation: 2855

Makefile - require all pattern matches

I'm trying to write a rule that will call my checking script on the output of each stage of my program, generating that output if it does not already exist using my %.output : %.input rule.

I tried check : $(wildcard stage[1234].output) but this causes the rule to require only those matching output files that already exist.

I could just define a variable like TARGETS = stage1.output stage2.output ..., but is there a way to generate all possible matches of a pattern and then require them?

Upvotes: 0

Views: 100

Answers (2)

Alexey Semenyuk
Alexey Semenyuk

Reputation: 704

If you want analogue of seq Unix utility in Make, here it is:

seq = $(if $(word $1,$2),$2,$(call seq,$1,$2 $(words $2 1)))
$(info seq(10)=$(call seq,10))

stage_sount:=7
stages:=$(patsubst %,stage%.output,$(call seq,$(stage_sount)))
$(info stages=$(stages))
all:

Output:

$ make
seq(10)= 1 2 3 4 5 6 7 8 9 10
stages=stage1.output stage2.output stage3.output stage4.output stage5.output stage6.output stage7.output
make: Nothing to be done for 'all'.

Upvotes: 0

Come Raczy
Come Raczy

Reputation: 1680

for the %.output : %.input rule to apply, you need both

  1. a goal that requires an intermediate that matches the pattern %.output
  2. a corresponding %.input file - either preexisting or a rule to build it

If your stage*.input files already exist, you can use:

INPUTS=$(wildcard stage[1234].input)
TARGETS=$(INPUTS:%.input=%.output)
check: $(TARGETS)

If your stage*.input files don't exist but are expected to be built from similar pattern rules, reapply the same principle.

If your stage*.input are produced from more complicated means, but assuming that their name can be generated by the application of a substitution pattern simply apply that pattern. In your example it would be something like:

L:= 1 2 3 4
TARGETS=$(L:%=stage%.output)

Upvotes: 1

Related Questions