How to get the Cartesian product (combinatorial extension) of name lists in a make file

Using GNU-make, let's 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 target list.

As an example from another language that I know better, R has an expand.grid () function that can do this.

I really figured out a way to do this using the Makefile:

.PHONY: all prefix := 1 2 base := AB add_prefix = $(addsuffix $(base), $(prefix)) Obj = $(foreach base, $(base), $(add_prefix)) all: @echo $(Obj) 

But this is pretty hacky and doesn't use the adduffix function in an intuitive way. Is there a better way to do this?

+6
source share
1 answer

Why not just do it in two cycles?

 obj := $(foreach X,$(prefix),$(foreach Y,$(base),$X$Y)) 
+9
source

Source: https://habr.com/ru/post/983114/


All Articles