根据输入文本文件在makefile中生成目标
我对这里和使用makefiles是新手。 我有一个问题: 我有3个测试要执行: 我在make文件中手动添加了test1、test2和test3作为目标,如下所示:根据输入文本文件在makefile中生成目标,makefile,vhdl,Makefile,Vhdl,我对这里和使用makefiles是新手。 我有一个问题: 我有3个测试要执行: 我在make文件中手动添加了test1、test2和test3作为目标,如下所示: test1: compile_design compile test1_testname.vhd >> log_file.log simulate test1_testname 我为测试2和3做了同样的事情 我还补充说 all : test1 test2 test3 这真是太棒了 现在,我想让这个makefile更
test1: compile_design
compile test1_testname.vhd >> log_file.log
simulate test1_testname
我为测试2和3做了同样的事情
我还补充说
all : test1 test2 test3
这真是太棒了
现在,我想让这个makefile更具可移植性:
从包含以下信息的输入文件:
test1_testname
test2_testname
test3_testname
我想自动添加3个目标
如果输入文件包含n行,则通常为n个目标。您甚至不需要使用源文件。在Makefile的顶部列出目标可能更容易。然后,通过使用模式规则,您可以通过以下内容获得所需的内容
TESTS=test1_testname test2_testname test3_testname
all: $(TESTS)
%_testname: compile_design
compile $@.vhd >> log_file.log
simulate $@
您可以注意到,模式规则将目标定义为test1\u testname
,而不是较短的test1
。这是为了避免使用%
模式规则
如果确实要使用其他文件列出目标,可以使用更改第一行
TESTS=$(shell cat yoursourcefile)
您甚至不需要使用源文件。在Makefile的顶部列出目标可能更容易。然后,通过使用模式规则,您可以通过以下内容获得所需的内容
TESTS=test1_testname test2_testname test3_testname
all: $(TESTS)
%_testname: compile_design
compile $@.vhd >> log_file.log
simulate $@
您可以注意到,模式规则将目标定义为test1\u testname
,而不是较短的test1
。这是为了避免使用%
模式规则
如果确实要使用其他文件列出目标,可以使用更改第一行
TESTS=$(shell cat yoursourcefile)
谢谢但通常每个测试的测试名称都不同。这就是为什么我需要缩短目标名称:是否有任何方法可以生成它们,如:testX:compile_design compile$@.vhd>>log_file.log simulate$@和X从0到test_number(从文件行号中获取),我还需要一个输入文件,因为不同项目的测试编号不同。我希望有办法做到这一点。请注意,即使名称不同,也可以使用
%
目标,如%:compile\u design
中所述。此外,命令中的$@
将自动替换为目标名称,即当前测试名称。我使用了%:compile design compile$@.vhd>>log\u file.log simulate$@
但我得到了makefile\u tb.vhd>>log\u file.log,就好像makefile是targetThanks一样。但通常每个测试的测试名称都不同。这就是为什么我需要缩短目标名称:是否有任何方法可以生成它们,如:testX:compile_design compile$@.vhd>>log_file.log simulate$@和X从0到test_number(从文件行号中获取),我还需要一个输入文件,因为不同项目的测试编号不同。我希望有办法做到这一点。请注意,即使名称不同,也可以使用%
目标,如%:compile\u design
中所述。此外,命令中的$@
将自动替换为目标名称,即当前测试名称。我使用了%:compile design compile$@.vhd>>log\u file.log simulate$@
但我得到了makefile\u tb.vhd>>log\u file.log,就好像makefile是目标一样