I need to call a function with two parameters inside a foreach loop
define obj-goal
$1: $2
gcc $(CXXFLAGS) -c $$< -o $$@
endef
Two arguments for the function are coming from two lists
C_FILES:=$(patsubst %.py,%.c,$(SRC_FILES))
OBJ_FILES:=$(patsubst %.py,build/temp.linux-x86_64-2.7/%.o,$(SRC_FILES))
Currently what I did was concatenate the two variables and then split again using two functions first-var
and last-var
then passed into the required function
first-var = $(firstword $(subst ^, ,$1))
last-var = $(lastword $(subst ^, ,$1))
OC_FLIST:=$(join $(OBJ_FILES),$(patsubst %,^%,$(C_FILES)))
$(foreach filecat,$(OC_FLIST),$(info $(call obj-goal,$(call first-var,$(filecat)),$(call last-var,$(filecat)))))
Is there a better way to do this? like:
$(foreach (ofile, cfile), ($(OBJ_FILES), $(C_FILES)) ,$(eval $(call obj-goal,$(ofile),$(cfile))))