make:为什么忽略显式模式规则并使用隐式规则?

时间:2015-04-15 19:36:31

标签: makefile gnu-make

考虑以下make文件:

all: *.o

%.o: %.cc %d
    echo `time` > $*.d
    echo `time` > $@

*.d:
    echo `time` > $@

没有.d个文件和一个test.cc文件。 make -r all的(部分)输出显示它忽略了显式规则。为什么呢?

No implicit rule found for `all'.
  Considering target file `test.o'.
   Looking for an implicit rule for `test.o'.
   Trying pattern rule with stem `test'.
   Trying implicit prerequisite `test.cc'.
   Trying implicit prerequisite `testd'.
   Trying pattern rule with stem `test'.
   Trying implicit prerequisite `test.c'.
   Trying pattern rule with stem `test'.
   Trying implicit prerequisite `test.cc'.
   Found an implicit rule for `test.o'.
    Considering target file `test.cc'.
     Looking for an implicit rule for `test.cc'.
     Trying pattern rule with stem `test.cc'.
     Trying implicit prerequisite `test.cc,v'.
     Trying pattern rule with stem `test.cc'.
     Trying implicit prerequisite `RCS/test.cc,v'.
     Trying pattern rule with stem `test.cc'.
     Trying implicit prerequisite `RCS/test.cc'.
     Trying pattern rule with stem `test.cc'.
     Trying implicit prerequisite `s.test.cc'.
     Trying pattern rule with stem `test.cc'.
     Trying implicit prerequisite `SCCS/s.test.cc'.
     No implicit rule found for `test.cc'.
     Finished prerequisites of target file `test.cc'.
    No need to remake target `test.cc'.
   Finished prerequisites of target file `test.o'.
   Prerequisite `test.cc' is newer than target `test.o'.
  Must remake target `test.o'.
g++    -c -o test.o test.cc
Putting child 0x01ab52e0 (test.o) PID 2713 on the chain.
Live child 0x01ab52e0 (test.o) PID 2713 
test.cc:1: error: expected constructor, destructor, or type conversion at end of input
Reaping losing child 0x01ab52e0 PID 2713 
make: *** [test.o] Error 1
Removing child 0x01ab52e0 PID 2713 from chain.

修改

这是新的Makefile,包含评论中的建议。关于为什么缺少先决条件不会触发规则,仍然有一个未解决的问题。

all: $(patsubst %.cc, %.o, $(wildcard *.cc))

%.o: %.cc

%.o: %.d %.cc
    echo `time` > $*.d
    echo `time` > $@

%.d:
    echo `time` separate > $@

输出:

  Considering target file `test.o'.
   Looking for an implicit rule for `test.o'.
   Looking for a rule with intermediate file `test.d'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `test'.
   Trying implicit prerequisite `test.cc'.
   Found an implicit rule for `test.o'.
    Considering target file `test.cc'.
     Looking for an implicit rule for `test.cc'.
     No implicit rule found for `test.cc'.
     Finished prerequisites of target file `test.cc'.
    No need to remake target `test.cc'.
   Finished prerequisites of target file `test.o'.
   Prerequisite `test.d' of target `test.o' does not exist.
   Prerequisite `test.cc' is older than target `test.o'.
  No need to remake target `test.o'.
 Finished prerequisites of target file `all'.

0 个答案:

没有答案