在GNU使手动说
有可能不止一个模式规则符合这些标准.在这种情况下,make将选择具有最短词干的规则(即,最具体匹配的模式).
所以它让我感到惊讶:
$ touch make_specific.cpp
$ cat Makefile.general_first
%.o: %.cpp
@echo using general rule
$(CXX) -c $< -o $@
%_specific.o: %_specific.cpp
@echo using specific rule
$(CXX) -c $< -o $@
$ make -B -f Makefile.general_first make_specific.o
using general rule
g++44 -c make_specific.cpp -o make_specific.o
Run Code Online (Sandbox Code Playgroud)
多模式规则匹配目标,并因为对干%_specific.o : %_specific.cpp规则(在这种情况下,"制作")比杆的短%.o : %.cpp规则,我预期的要选择的特定规则,但事实并非如此.
我错过了什么?
我有一个如下所示的目录结构:
$ tree
.
|-- dir
| `-- subdir
| `-- data
`-- makefile
Run Code Online (Sandbox Code Playgroud)
哪里data是文件.我makefile看起来像这样:
all: dir/analysis
.SECONDEXPANSION:
%/analysis: %/subdir
%/analysis: $(addsuffix /data, $$^)
@echo TARGET: $@ DEPS: $^
touch $@
Run Code Online (Sandbox Code Playgroud)
当我跑步时make,我希望结果看起来像这样:
TARGET: dir/analysis DEPS: dir/subdir/data dir/subdir
touch dir/analysis
Run Code Online (Sandbox Code Playgroud)
相反,它只是报道
make: *** No rule to make target `dir/analysis', needed by `all'. Stop.
Run Code Online (Sandbox Code Playgroud)
如果我将第一个规则更改为dir/analysis: dir/subdir然后它按预期工作.因此我怀疑make忽略了第一条规则,并在第一条规则出现时直接跳到第二条规则%/analysis: %/subdir.当两个规则都dir/analysis作为目标而不仅仅是第一个规则时,它也可以按预期工作.MadScientists对这里不同问题的回答似乎适用于我的问题.我尝试添加类似的规则
dummy_target: dir/subdir
mkdir -p dir/subdir
Run Code Online (Sandbox Code Playgroud)
和
dir/subdir:
mkdir -p …Run Code Online (Sandbox Code Playgroud)