【问题标题】:Iterating through makefile argument list遍历 makefile 参数列表
【发布时间】:2018-07-15 07:58:05
【问题描述】:

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

示例:我想通过命令行覆盖三个测试变量(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 MakefilePassing arguments to "make run",但它没有回答我的具体问题。

提前感谢您的帮助。

【问题讨论】:

  • 你为什么不用make ... A=3 B=4 C=5?或者变量名(ABC)可以是任何名称?
  • 变量名可以是任何东西。 Madscientist 的解决方案解决了我的问题

标签: makefile system-verilog uvm test-bench


【解决方案1】:

这不可能:

+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 行给出的文本。

【讨论】:

    【解决方案2】:

    如果您正在通过 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,$$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
    

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

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 2022-01-07
      相关资源
      最近更新 更多