如何使文件执行动态目标?

问题描述 投票:0回答:1

我试图了解一个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文档,但那里也没有任何相关信息。关于这种动态目标及其执行的任何解释都将非常有帮助。

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)
makefile build gnu-make
1个回答
0
投票

我不认为此规则意味着您认为的含义:

$(PROGS) $(EXTRA_PROGS) $(CTF_INTEGRATION_TESTS): $(GO_BIN_BUILD_DEPS)
        $(GO_BIN_BUILD)

首先,make将扩展第一行中的所有变量(第二行是配方,因此直到make想要建立目标时才扩展它。)>

因此,您得到的是这样的东西:

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

其中a/a.suiteb/b.suiteforeach函数的结果(不知道CTF_DIRS变量的值,我不能说出实际值可能是什么)和dep1dep2dep3是运行SOME_COMMAND_TO_BUILD_GO_DEPENDENCIES的结果,我认为这是一些$(shell ...)命令。

这被解释为您为具有相同配方的每个文件声明了各自的规则,如下所示:

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)
© www.soinside.com 2019 - 2024. All rights reserved.