SHELL := /bin/bash
NOV := 1,2
OSC := a,b
NOVW := 1 2
OSCW := a b
EXP := $(shell printf "%s " {$(NOV)}{$(OSC)})
EXPW := $(foreach X,$(NOVW),$(foreach Y,$(OSCW),$(X)$(Y)))
.PHONY: all a b $(EXP) $(EXPW)
all: a b
a: $(EXP)
@echo target a
@printf "my first prerequisite is %s\n" "$<"
@printf "all my prerequisites are %s\n" "$^"
b: $(EXPW)
@echo target b
@printf "my first prerequisite is %s\n" "$<"
@printf "all my prerequisites are %s\n" "$^"
Output:
$ make
target a
my first prerequisite is 1a
all my prerequisites are 1a 1b 2a 2b
target b
my first prerequisite is 1a
all my prerequisites are 1a 1b 2a 2b
Note: the SHELL
is needed because brace expansion isn't a POSIX feature. The shell used by GNU Make is /bin/sh
by default. When Bash is run as /bin/sh
, it doesn't support brace expansion.