gpt4 book ai didi

makefile - 为什么不触发 .PHONY 隐式模式规则?

转载 作者:行者123 更新时间:2023-12-01 23:11:28 29 4
gpt4 key购买 nike

我有以下递归 makefile:

.PHONY: all clean

%.subdir:
$(MAKE) -C src $*
$(MAKE) -C dict $*

all: all.subdir

clean: clean.subdir

它工作正常:

$ make all
make -C src all
make[1]: Entering directory `/or-1.3.6-fix/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/or-1.3.6-fix/src'
make -C dict all
make[1]: Entering directory `/or-1.3.6-fix/dict'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/or-1.3.6-fix/dict'

但是将 %.subdir 规则定义为虚假规则会更符合逻辑:

.PHONY: all clean all.subdir clean.subdir

现在让停止按我想要的方式工作:

$ make all
make: Nothing to be done for `all'.
$ make -d all
...
Updating goal targets....
Considering target file `all'.
File `all' does not exist.
Considering target file `all.subdir'.
File `all.subdir' does not exist.
Finished prerequisites of target file `all.subdir'.
Must remake target `all.subdir'.
Successfully remade target file `all.subdir'.
Finished prerequisites of target file `all'.
Must remake target `all'.
Successfully remade target file `all'.
make: Nothing to be done for `all'.

有人可以解释我为什么(或者更好地指出我制作文档)吗?

最佳答案

你是对的,将子目录规则定义为 PHONY 会更有意义。但是 Make 不考虑 PHONY 目标的隐式规则,因此您必须重写该规则。我建议如下:

SUBDIR_TARGETS = all.subdir clean.subdir
.PHONY: all clean $(SUBDIR_TARGETS)

$(SUBDIR_TARGETS): %.subdir:
$(MAKE) -C src $*
$(MAKE) -C dict $*

all: all.subdir
clean: clean.subdir

关于makefile - 为什么不触发 .PHONY 隐式模式规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3095569/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com