Makefile规则求解
本帖最后由 date01 于 2015-04-20 12:31 编辑小弟不才,看一个复杂的makefile,一个利用通配符%的表达式规则,因为有点小疑惑,所以自己测试了一下,但其输出令我百思不得其解,测试用makefile如下:
%: valid
@echo "the wildcard target"
valid: ;
@echo "the valid target"
程序输出如下:
$ make all
the valid target
the wildcard target
the wildcard target
问:为何通配规则会被执行两次? 试了下没有你说的问题# cat Makefile
%: valid
@echo "%"
valid:
@echo "valid"
# make
valid
%
make: “valid”是最新的。
# make --version
GNU Make 3.81
Copyright (C) 2006Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-redhat-linux-gnu
# 回复 1# date01
不好意思,我在事例代码里漏掉了执行命令,我提到的情形是在执行命令:make all,之后的输出,你可以试验一下,相信会得到跟我一样的输出.
回复 2# asdf2110
all 也走的 % 下的规则,加一个 all 规则就看出来了# cat Makefile
%: valid
@echo "the wildcard target"
all:
@echo "all"
valid: ;
@echo "the valid target"
# make all
the valid target
the wildcard target
all
#回复 3# date01
页:
[1]