遍历 makefile 参数列表
Iterating through makefile argument list
我希望我的 makefile 解析下面 $(cfg) 列表中的每个 arg=value 对。然后在 makefile 中使用这些 $(arg) 和 $(value)。这些 arg=value 对可以用 space 或逗号分隔。
示例:我想通过命令行覆盖三个测试变量(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
我上面的目的是允许通过命令行覆盖任何默认测试配置。
我检查了 Variable arguments list to a Makefile, Passing arguments to "make run",但它没有回答我的具体问题。
在此先感谢您的帮助。
这不可能是对的:
+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5
因为它只是设置,然后覆盖单个值 +uvm_set_config_int
。最后,变量 +uvm_set_config_int
将包含单个值 *,C,5
,因为这是最后一次赋值。也许你的意思是在上面的每一个中使用 uvm_set_config_int += ...
来附加到现有值?
我真的不明白你想在这里完成什么。
然而,这里有一个如何执行您所要求的示例,尽管它似乎没有多大意义:
c = ,
$(foreach X,$(subst $c, ,$(cfg)),$(eval +uvm_set_config_int=*,$(subst =,$c,$X)))
由于逗号对于函数是特殊的,我们必须将它们隐藏在上面的变量 $c
后面。第一个 subst
将逗号变成空格,因为 make 就是用来分隔单词的。第二个将 =
转换为逗号,因此您可以将 A=3
更改为 A,3
等。eval
评估作为 makefile 行给出的文本。
如果您正在通过 make 进行某种形式的构建配置,您可以使用 gmtt 这是一个具有支持此任务功能的库。在 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,$,smoketest*),+uvm_set_config=*$(comma)$$(comma)$)
regressiontest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$,regressiontest*),+uvm_set_config=*$(comma)$$(comma)$)
$(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 列表,因此您必须使用空格作为项目的分隔符,并且不能为空 "cells"。)
输出:
+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
请注意,您需要在输出格式中将 ,
引用为 $(comma)
(gmtt 提供的变量),因为 make 的大量字符处理几乎将所有内容都作为函数参数,甚至 \
,因此作为转义字符也无济于事。
我希望我的 makefile 解析下面 $(cfg) 列表中的每个 arg=value 对。然后在 makefile 中使用这些 $(arg) 和 $(value)。这些 arg=value 对可以用 space 或逗号分隔。
示例:我想通过命令行覆盖三个测试变量(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
我上面的目的是允许通过命令行覆盖任何默认测试配置。
我检查了 Variable arguments list to a Makefile, Passing arguments to "make run",但它没有回答我的具体问题。
在此先感谢您的帮助。
这不可能是对的:
+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5
因为它只是设置,然后覆盖单个值 +uvm_set_config_int
。最后,变量 +uvm_set_config_int
将包含单个值 *,C,5
,因为这是最后一次赋值。也许你的意思是在上面的每一个中使用 uvm_set_config_int += ...
来附加到现有值?
我真的不明白你想在这里完成什么。
然而,这里有一个如何执行您所要求的示例,尽管它似乎没有多大意义:
c = ,
$(foreach X,$(subst $c, ,$(cfg)),$(eval +uvm_set_config_int=*,$(subst =,$c,$X)))
由于逗号对于函数是特殊的,我们必须将它们隐藏在上面的变量 $c
后面。第一个 subst
将逗号变成空格,因为 make 就是用来分隔单词的。第二个将 =
转换为逗号,因此您可以将 A=3
更改为 A,3
等。eval
评估作为 makefile 行给出的文本。
如果您正在通过 make 进行某种形式的构建配置,您可以使用 gmtt 这是一个具有支持此任务功能的库。在 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,$,smoketest*),+uvm_set_config=*$(comma)$$(comma)$)
regressiontest-cfg := $(call map-select,1 2,$(cfg-table),$$(call glob-match,$,regressiontest*),+uvm_set_config=*$(comma)$$(comma)$)
$(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 列表,因此您必须使用空格作为项目的分隔符,并且不能为空 "cells"。)
输出:
+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
请注意,您需要在输出格式中将 ,
引用为 $(comma)
(gmtt 提供的变量),因为 make 的大量字符处理几乎将所有内容都作为函数参数,甚至 \
,因此作为转义字符也无济于事。