I need to treate a list in Makefile

I need to treate the follwing lists:

PACKAGE_DEPENDS_LIST="UCI,ULOOP"
PACKAGE_LIST_LIST="V_10.0.1,V_0.1"

how to use in Makefile a loop to use the list like:

DEPENDS:=+ UCI_V_10.0.1
DEPENDS:=+ ULOOP_V_0.1

It's hard to do fully dynamic but if you can live with a certain maximum amount of entries then you could do it like this:

PACKAGE_DEPENDS_LIST="UCI,ULOOP"
PACKAGE_VERSION_LIST="V_10.0.1,V_0.1"

comma:=,
empty:=
space:=$(empty) $(empty)
seq:=1 2 3 4 5 6 7 8 9 10

depend_words:=$(subst $(PACKAGE_DEPENDS_LIST),$(comma),$(space))
version_words:=$(subst $(PACKAGE_VERSION_LIST),$(comma),$(space))

DEPENDS += $(strip $(foreach idx,$(seq), \
  $(if $(word $(idx),$(depend_words)), \
    $(word $(idx),$(depend_words))_$(word $(idx),$(version_words)))))
3 Likes

I am aware you asked for a solution which uses a loop to build up the DEPENDS variable.
May I suggest using the $join() function instead?
You can still iterate over the result with a loop if needed.

PACKAGE_DEPENDS_LIST="UCI,ULOOP"
PACKAGE_VERSION_LIST="V_10.0.1,V_0.1"

comma:=,
empty:=
space:=$(empty) $(empty)

depend_unquoted=$(patsubst "%,%,$(patsubst %",%,$(PACKAGE_DEPENDS_LIST)))
version_unquoted=$(patsubst "%,%,$(patsubst %",%,$(PACKAGE_VERSION_LIST)))

depend_words=$(subst $(comma),$(space),$(depend_unquoted))
version_words=$(subst $(comma),$(space),$(version_unquoted))

DEPENDS=$(join $(patsubst %,%_,$(depend_words)),$(version_words))

$(foreach p,$(DEPENDS),$(info p=$(p)))
2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.