遍历makefile参数列表

遍历makefile参数列表,makefile,system-verilog,uvm,test-bench,Makefile,System Verilog,Uvm,Test Bench,我想让我的makefile解析下面$(cfg)列表中的每个arg=value对。然后在makefile中使用这些$(arg)和$(value)。这些arg=值对可以用空格或逗号分隔 示例:我想通过命令行覆盖三个测试变量(A、B、C) make run test=my_test.sv cfg="A=3, B=4, C=5" Makefile应该执行以下操作: foreach $arg,$val in $cfg ----> +uvm_set_config_int=*,$arg,$val

我想让我的makefile解析下面$(cfg)列表中的每个arg=value对。然后在makefile中使用这些$(arg)和$(value)。这些arg=值对可以用空格或逗号分隔

示例:我想通过命令行覆盖三个测试变量(A、B、C)

make run test=my_test.sv cfg="A=3, B=4, C=5"
Makefile应该执行以下操作:

foreach $arg,$val in $cfg  ----> +uvm_set_config_int=*,$arg,$val
有效结果:

+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5
我上面的目的是允许通过命令行覆盖任何默认测试配置

我检查了一下,但是它没有回答我的具体问题

提前感谢您的帮助。

这不可能是对的:

+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5
因为这只是设置然后覆盖单个值
+uvm\u set\u config\u int
。最后,变量
+uvm\u set\u config\u int
将包含单个值
*,C,5
,因为这是最后一个赋值。也许您的意思是在上面的每一项中使用
uvm\u set\u config\u int+=…
,以附加到现有值

我真的不明白你想在这里完成什么

然而,这里有一个例子说明了如何按照你的要求去做,尽管这似乎没有多大意义:

c = ,
$(foreach X,$(subst $c, ,$(cfg)),$(eval +uvm_set_config_int=*,$(subst =,$c,$X)))

由于逗号是特殊的函数,我们必须将它们隐藏在上面的变量
$c
后面。第一个
subst
将逗号转换为空格,因为逗号用于分隔单词。第二个将
=
转换为逗号,这样您就可以将
A=3
更改为
A,3
等。
eval
将文本作为makefile行进行计算。

如果您正在通过make进行某种形式的构建配置,则可以使用make库,该库具有支持此任务的功能。在gmtt中,您可以这样制定您的任务:

include gmtt/gmtt.mk

cfg-table := 2 $(cfg) # make a gmtt-table from the variable

# now select column 1 and 2 from the table for the right test and format the output (without the need to format, just use "select")
smoketest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$$1,smoketest*),+uvm_set_config=*$(comma)$$1$(comma)$$2)

regressiontest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$$1,regressiontest*),+uvm_set_config=*$(comma)$$1$(comma)$$2)


$(info $(smoketest-cfg))
$(info $(regressiontest-cfg))
$(info -----------------------)
$(info $(subst $(space),$(newline),$(strip $(smoketest-cfg))))
你现在应该可以这样称呼它:

make cfg="smoketest-A 1 smoketest-B 2 regressiontest-A 3 regressiontest-B 4"
(gmtt使用的表只是GNUmake列表,所以必须使用空格作为项的分隔符,并且不能有空的“单元格”。)

输出:

 +uvm_set_config=*,smoketest-A,1 +uvm_set_config=*,smoketest-B,2
 +uvm_set_config=*,regressiontest-A,3 +uvm_set_config=*,regressiontest-B,4
-----------------------
+uvm_set_config=*,smoketest-A,1
+uvm_set_config=*,smoketest-B,2

请注意,您需要在输出格式中引用
,作为
$(逗号)
(gmtt提供的一个变量),因为make的大量字符处理几乎将所有内容都作为函数参数,甚至
\
,因此它不能作为转义字符使用。

为什么不使用
make。。。A=3 B=4 C=5
?或者变量名(
A
B
C
)可以是任何东西?变量名可以是任何东西。疯狂科学家的解决方案解决了我的问题