0
votes

I want to make a GNU Makefile, in which for every targets like

<dirname>/stamp-<stampname>:

the following command is executed:

cd <dirname> && make stamp-<stampname>

As I've read here, the so-named pattern rules can do some quite similar, i.e. for example to call a C compiler to produce the .o-s from any sources (.c):

%.o: %.c
  $(CC) -o ...

They could solve my problem, but as you can see, in my case, multiple % directives would be needed. Ideally, if a syntax element like

%1/stamp-%2:
  cd %1 && make stamp-%2

would exist, it would solve everything. But it doesn't. Does some workaround exist for the task?

1

1 Answers

1
votes

Perhaps something like this:

STAMPS:=$(shell ls **/stamp-*)

all: $(STAMPS)

.PHONY: $(STAMPS)
$(STAMPS):
    cd $(dir $@) && $(MAKE) $(notdir $@)

This assumes the stamp- files are always present and can be collected with ls. If they are not, you will have to specify them manually, e.g. STAMPS:=foo/stamp-1 bar/stamp-2 ....