makefile - make 如何选择使用哪个规则

标签 makefile

所以我这里有一个看起来像这样的 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/

相关文章:

cygwin make - 对 INT_MAX 和 argp_usage 的 undefined reference

关闭文件上的 Python 套接字 Makefile 错误 I/O 操作

makefile - OpenWRT 的 Elixir 包构建指南

c - 递归生成文件未构建

c - 我需要制作一个目标文件,还是只是最终的可执行文件?

c - Makefile 循环依赖

c - 如何使用openMP为MPI程序制作makefile?

C++ 为 VS2012 构建 Winsparkle

linux - 当 gnu make phony 目标恰好与目录名称相同时的行为

c++ - 自动生成的依赖导致编译缓慢