How does make file execute the dynamic targets?
我试图了解一个makefile,而动态目标的用法似乎很令人困惑。我无法理解如何在makefile中调用这些动态目标。
我尝试通过打印shell命令(使V = 1)来调试以下内容,但我无法消除怀疑。我看到正在构建file / 1,file / 2,file / 3和file / 4,但是看不到对此目标进行任何循环或多次调用。我还尝试查看https://www.gnu.org/software/make/manual/html_node/Implicit-Rules.html文档,但那里也没有任何相关信息。关于这种动态目标及其执行的任何解释都将非常有帮助。
1 2 3 4 5 6 7 8 9 10 11 12 | PROGS= \\ path/to/file/1 \\ path/to/file/2 EXTRA_PROGS= \\ path/to/file/3 \\ path/to/file/4 GO_BIN_BUILD=$(SOME_COMMAND_TO_BUILD_GO_BINARY) GO_BIN_BUILD_DEPS=$(SOME_COMMAND_TO_BUILD_GO_DEPENDENCIES) CTF_INTEGRATION_TESTS=$(foreach root,$(CTF_DIRS),$(root)/$(notdir $(root)).suite) $(PROGS) $(EXTRA_PROGS) $(CTF_INTEGRATION_TESTS): $(GO_BIN_BUILD_DEPS) #the dynamic target in question. $(GO_BIN_BUILD) |
我认为该规则并不意味着您认为的含义:
1 2 | $(PROGS) $(EXTRA_PROGS) $(CTF_INTEGRATION_TESTS): $(GO_BIN_BUILD_DEPS) $(GO_BIN_BUILD) |
首先,make将扩展第一行中的所有变量(第二行是一个配方,因此直到make想要建立目标时才扩展它)。
因此,您得到的是这样的内容:
1 | path/to/file/1 path/to/file/2 path/to/file/3 path/to/file/4 a/a.suite b/b.suite : dep1 dep2 dep3 |
其中
这被解释为您使用相同的配方为这些文件中的每个文件声明了各自的规则,如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 | path/to/file/1 : dep1 dep2 dep3 $(GO_BIN_BUILD) path/to/file/2 : dep1 dep2 dep3 $(GO_BIN_BUILD) path/to/file/3 : dep1 dep2 dep3 $(GO_BIN_BUILD) path/to/file/4 : dep1 dep2 dep3 $(GO_BIN_BUILD) a/a.suite : dep1 dep2 dep3 $(GO_BIN_BUILD) b/b.suite : dep1 dep2 dep3 $(GO_BIN_BUILD) |