1

I want my makefile to parse each arg=value pair in the $(cfg) list below. And then use these $(arg) and $(value) in the makefile. These arg=value pair can be separated by space or comma.

Example: I want to override three test variables (A, B, C) through command line

make run test=my_test.sv cfg="A=3, B=4, C=5"

Makefile should do something like this:

foreach $arg,$val in $cfg  ----> +uvm_set_config_int=*,$arg,$val

Effective result:

+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5

My purpose above is to allow overriding of any default test configuration through command line.

I checked Variable arguments list to a Makefile, Passing arguments to "make run" however it did not answer my specific question.

Thanks in advance for the help.

Verify
  • 15
  • 2

2 Answers2

1

This can't be right:

+uvm_set_config_int=*,A,3
+uvm_set_config_int=*,B,4
+uvm_set_config_int=*,C,5

because that just sets, then overrides, the single value +uvm_set_config_int. At the end the variable +uvm_set_config_int will contain the single value *,C,5 since that's the last assignment. Maybe you mean to use uvm_set_config_int += ... in each of the above, to append to the existing value?

I really don't understand what you're trying to accomplish here.

However, here's an example of how to do what you've asked, even though it doesn't seem to make much sense:

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

Since commas are special to make functions we have to hide them behind a variable $c above. The first subst turns commas into spaces, since that's what make uses to delimit words. The second converts = to comma so you can change A=3 to A,3 etc. The eval evaluates the text given as a makefile line.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
0

In case you are doing some form of build configuration through make, you can use gmtt which is a library with functionality supporting this task. In gmtt you can formulate your task like this:

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))))

and you should now be able to call it like:

make cfg="smoketest-A 1 smoketest-B 2 regressiontest-A 3 regressiontest-B 4"

(gmtt uses tables which are just GNUmake lists, therefore you must use spaces as separators of the items and you must not have empty "cells".)

Output:

 +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

Note that you need to quote , in your output format as $(comma) (a variable provided by gmtt) because of the generous character handling of make which takes nearly everything as a function parameter, even \, which therefore doesn't help as escaping character.

Vroomfondel
  • 2,704
  • 1
  • 15
  • 29