makefile Advanced Makefile Zipping lists


Example

GNU make

This pairmap function takes three arguments:

  1. A function name
  2. First space-separated list
  3. Second space-separated list

For each zipped tuple in the lists it will call the function with the following arguments:

  1. Tuple element from the first list
  2. Tuple element from the second list

It will expand to a space-separated list of the function expansions.

list-rem = $(wordlist 2,$(words $1),$1)
pairmap = $(and $(strip $2),$(strip $3),$(call \
    $1,$(firstword $2),$(firstword $3)) $(call \
    pairmap,$1,$(call list-rem,$2),$(call list-rem,$3)))

For example, this:

LIST1 := foo bar baz
LIST2 := 1 2 3

func = $1-$2

all:
    @echo $(call pairmap,func,$(LIST1),$(LIST2))

.PHONY: all

Will print foo-1 bar-2 baz-3.