How to get Cartesian product (combinatorial expansion) of name lists in makefile
cartesian-product, gnu-make, makefile
Solution
Why not just do it in two loops?
obj := $(foreach X,$(prefix),$(foreach Y,$(base),$X$Y))
Problem
Using GNU-make, say that I have two lists in my Makefile, and I want to combine them to get their Cartesian product as another list, so that I can use it as a list of targets. As an example from a different language that I know better, R has a function expand.grid() which could accomplish this. I actually figured out a way to do this using a Makefile: ``` .PHONY: all prefix := 1 2 base := A B add_prefix = $(addsuffix $(base), $(prefix)) Obj = $(foreach base, $(base), $(add_prefix)) all: @echo $(Obj) ``` But, this is pretty hacky and doesn't use the addsuffix function in an intuitive way. Is there a better way to do it?