在Make中的foreach调用中两次调用宏

时间:2018-11-14 00:44:24

标签: foreach makefile macros

我有一个宏,它为每个种子调用一个目标:

define MY_MACRO
    $(foreach seed, $(shell $(SHELL_EXPORT) seq $(3) $(4)), $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), FIRST_TARGET_NAME)))
endef

有没有一种方法可以调用两个不同的目标,一个又一个?这个用TEST_TARGET_MACRO的每个种子调用我的FIRST_TARGET_NAME。

像这样...

define MY_MACRO
    $(foreach seed, $(shell $(SHELL_EXPORT) seq $(3) $(4)), $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), FIRST_TARGET_NAME), $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), SECOND_TARGET_NAME)))
endef

,以便它将对每个种子评估第一个调用,然后第二个调用

我似乎无法找到一种方法来完成此操作......或在网上找到任何内容

1 个答案:

答案 0 :(得分:0)

我不太确定您要做什么,但是为什么不能只写两次eval / call?像这样:

define MY_MACRO
    $(foreach seed, $(shell $(SHELL_EXPORT) seq $(3) $(4)), \
        $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), FIRST_TARGET_NAME) \
        $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), SECOND_TARGET_NAME))))
endef

这是我简单完整的示例:

TEST_TARGET_MACRO = all:: ; $(info 1=$1 2=$2 3=$3 4=$4)

define MY_MACRO
    $(foreach seed, $(shell seq $(3) $(4)), \
        $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), FIRST_TARGET_NAME) \
        $(eval $(call TEST_TARGET_MACRO, $(1), $(2), $(seed), SECOND_TARGET_NAME))))
endef

$(call MY_MACRO,foo,bar,2,5)

这是我期望的输出:

1= foo 2= bar 3= 2 4= FIRST_TARGET_NAME
1= foo 2= bar 3= 2 4= SECOND_TARGET_NAME
1= foo 2= bar 3= 3 4= FIRST_TARGET_NAME
1= foo 2= bar 3= 3 4= SECOND_TARGET_NAME
1= foo 2= bar 3= 4 4= FIRST_TARGET_NAME
1= foo 2= bar 3= 4 4= SECOND_TARGET_NAME
1= foo 2= bar 3= 5 4= FIRST_TARGET_NAME
1= foo 2= bar 3= 5 4= SECOND_TARGET_NAME
make: 'all' is up to date.