Are dynamic Make Dependencies possible?

Viewed 32

Consider the following example Makefile:

.PHONY: all

all: Coffee_With_Milk Coffee_With_noMilk

%_With_%: Kitchen
    # Parse the parts from $@ and do stuff

As you can see, I produce Coffee_With_Milk and Coffee_With_noMilk with it.

When I not only have the choice [Coffee] and [Milk, noMilk] but [Coffee, Tea, Juice, Vodka, Coke] and [Milk, Sugar, Lemon, Marshmallow, nothing], I would have to write all 5x5=25 combinations into the all: <combination1> <combination2> <...> line.

Is there any way to create it dynamically?

1 Answers

You can use the foreach function:

BEVERAGE := Coffee Tea Juice Vodka Coke
ADDIN := Milk Sugar Lemon Marshmallow nothing

COMBOS := $(foreach B,$(BEVERAGE),$(foreach A,$(ADDIN),$(B)_With_$(A)))

As I mentioned in my comment, though, you won't be able to use a pattern rule like the one you've mentioned.

Related