makefilegnu-make

map each item in list with a format in make


So I've got this variable:

ITEMS = item1 item2

and I want a function to do something like this:

ITEMS_AFTER := $(fmt prefix{}suffix, $(ITEMS))

so it will look like:

prefixitem1suffix prefixitem2suffix

how would I do it?

I hope i have a shorter way than using addprefix combined with addsuffix.


Solution

  • You can use foreach:

    ITEMS_AFTER := $(foreach I,$(ITEMS),prefix$Isuffix)
    

    or you can use patsubst:

    ITEMS_AFTER := $(patsubst %,prefix%suffix,$(ITEMS))