是否有简单的方法来查找特定目标的源mk文件?

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

我正在使用由许多分散在整个系统中的makefile组成的环境。如果给我一个特定的目标,我想找到定义该目标的实际makefile,而无需手动扫描每个文件以递归查找include语句。gnu-make是否有任何功能可以告诉您目标的源文件?还是有人写过脚本来做到这一点?

gnu-make
2个回答
0
投票

我不知道您通过“查找包含语句”来标识特定目标所在的makefile的含义。除此之外,还取决于是否明确命名了目标或使用了模式规则。在后一种情况下,可能无法找到相关的makefile,因为在目标与其先决条件之间调用make之前并不一定存在任何连接-例如VPATH或更改了子makefile的委托工作目录中,手动搜​​索源(每wildcard)可能都会影响在哪里建立目标。就是说,大多数makefile层次结构并没有那么复杂以至于难以理解,否则它们将永远不会到达那里。您可以尝试在依赖文件中搜索目标的命名。另一种可能性是执行make --dry-run或什至make --always-make并查看日志输出。


0
投票

您可以使用-p选项运行GNU make,以转储已解析的Makefile。每个定义的目标和每个已解析的隐式规则都将在那里,包括其在文件中的位置,例如:

$ cat Makefile
include other.mk

all: foo.o

$ cat other.mk
%.o:
        @echo Building $@

输出(请注意,它包含隐式规则和从该规则扩展的目标):

$ make -r -p
...
%.o:
#  recipe to execute (from 'other.mk', line 2):
        @echo Building $@
...
foo.o:
#  Implicit rule search has been done.
#  Implicit/static pattern stem: 'foo'
#  File does not exist.
#  File has been updated.
#  Successfully updated.
# automatic
# @ := foo.o
# automatic
# % :=
# automatic
# * := foo
# automatic
# + :=
# automatic
# | :=
# automatic
# < :=
# automatic
# ^ :=
# automatic
# ? :=
# variable set hash-table stats:
# Load=8/32=25%, Rehash=0, Collisions=1/12=8%
#  recipe to execute (from 'other.mk', line 2):
        @echo Building $@
...
© www.soinside.com 2019 - 2024. All rights reserved.