所以我这里有一个看起来像这样的 makefile
ALL_FILES=$(shell find . -name '*')
install : $(ALL_FILES)
$(INSTALL_LOCATION)/%.sh : %.sh ; /bin/usr/install -D $^ $@
$(INSTALL_LCOATION)/% : % ; /usr/bin/install -D $^ $@
$(INSTALL_LOCATION)/dir1/% : dir1/% ; /usr/bin/install -D $^ $@
我的问题是,第二个安装显然是第一个安装的超集, 但我猜第一个先运行,所以第二个被忽略。 但是,第二个不是也是第三个的完整超集吗?
那么make如何选择使用哪条规则呢?它会选择最具体的规则吗?
最佳答案
取决于 make 的版本。例如,在 3.82 之前的 GNU make 中,它将按照声明的顺序搜索模式,并简单地使用第一个匹配的模式,而不考虑特殊性。在 3.82 及更高版本中,GNU make 使用最具体的规则,无论声明顺序如何。这是一个简单的例子:
all: sub/foo.x
%.x:
@echo "Prefer first match (stem is $*)."
sub/%.x:
@echo "Prefer most specific match (stem is $*)."
将输出与 gmake 3.81 和 gmake 3.82 进行比较:
$ gmake-3.81
Prefer first match (stem is sub/foo).
$ gmake-3.82
Prefer most specific match (stem is foo).
关于makefile - make 如何选择使用哪个规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10656363/