help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enumerating list elements


From: Krzysztof Cieniuch
Subject: Re: Enumerating list elements
Date: Fri, 11 Mar 2011 12:12:12 +0000
User-agent: Thunderbird 2.0.0.24 (X11/20101213)

Christian Rishøj Jensen wrote:
Say I have a list with some elements:

FACTORS = form pos cluster

I would like to enumerate the elements in the list, i.e. for each element, 
create a variable with the element's name and the list index as the value.

I have tried this:

i=0 ; for f in $(FACTORS); do \
        ((i = i + 1)) ; \
        $(f) := $(i) ; \
done

...but without luck: This for-loop is evaluated by the shell and does not affect Make variables.
How can I achieve the desired effect?

/ Christian


_______________________________________________
Help-make mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-make
Do you mean this:

FACTORS = form pos cluster
#set to factor_i:=x if you want to start index from 1
factor_i:=
$(foreach factor,$(FACTORS),   \
$(eval $(factor):=$(words $(factor_i))) \
$(eval factor_i+=x))

$(info form=$(form))
$(info pos=$(pos))
$(info cluster=$(cluster))

Chris





reply via email to

[Prev in Thread] Current Thread [Next in Thread]