1

我是新来的,并且不擅长使用 makefile。我有一个问题:

我有3个测试要执行:

我在 make 文件中手动添加了 test1、test2 和 test3 作为目标,如下所示:

test1: compile_design
 compile test1_testname.vhd >> log_file.log
 simulate test1_testname

我对 test2 和 3 做了同样的事情。

我还添加了

all : test1 test2 test3

这非常有效。

现在,我想让这个 makefile 更便携:来自一个包含以下信息的输入文件:

test1_testname
test2_testname
test3_testname

如果输入文件包含 n 行,我希望自动添加 3 个目标,通常是 n 个目标。

4

1 回答 1

1

您甚至不需要使用源文件。在 Makefile 的顶部列出您的目标可能更容易。然后,通过使用模式规则,您可以通过以下方式获得所需的内容。

TESTS=test1_testname test2_testname test3_testname

all: $(TESTS)

%_testname: compile_design
    compile $@.vhd >> log_file.log
    simulate $@

您可以注意到模式规则将目标定义为test1_testname而不是更短的test1. 这是为了避免出现%模式规则。

如果你真的想使用另一个文件来列出你的目标,你可以改变第一行

TESTS=$(shell cat yoursourcefile)
于 2013-08-28T13:50:18.990 回答