This can be done pretty well using recursion inside GNU make functions as follows:
_pos = $(if $(findstring $1,$2),$(call _pos,$1,\ $(wordlist 2,$(words $2),$2),x $3),$3) pos = $(words $(call _pos,$1,$2))
To use it, you must $(call) use the pos function with two arguments: the item to find, and a list to find it. For instance,
$(call pos,a,abcdefg) $(call pos,e,abcdefg) $(call pos,g,abcdefg) $(call pos,h,abcdefg) $(call pos,e,))
It works by recursing through the $2 argument until it can no longer find the value in $1 . Each time it repeats, it throws off the head of $2 with $(wordlist 2,$(words $2),$2) . Each time it is recurses, it adds x to the returned row, so for each position through $2 there is x up to $1 .
Then it just uses $(words) to count the return length from _pos (number x s).
If you are using a GMSL project, it may be written more accurately to write this as:
_pos = $(if $(findstring $1,$2),$(call $0,$1,$(call rest,$2),x $3),$3) pos = $(words $(call _$0,$1,$2))
Note that here I used $0 , which will contain the name of the current function (the standard GNU make function) and the GMSL rest function to cut the head off the list.