In my makefile, I need to make a variable assignment based on a command line variable value. for example, I do:
make var_1=xxx
where
This works in mingw gnu make 4.3 :
define get_index
$(shell \
$(eval _c = 1)\
$(eval _b = n n) \
$(foreach x,$(2), \
$(eval _b += n \
$(eval _c = $(words $(_b)) \
$(if $(filter $(1),$(x)), \
$(eval _r = $(_c)))))) \
echo $(_r) \
$(eval _c =) \
$(eval _b =) \
$(eval _r =) \
)
endef
Takes two arguments; the word to search for and the list where to search. The index is 'returned' by echoing in $(shell ...)
Example:
list = cow horse chicken
index = $(call get_index,horse,$(list))
@echo $(index)
# output: 2