2

even_odd_list.csrc目录中有源文件。这是makefile我正在尝试的

VPATH = src include
CPPFLAGS = -I include

even_odd_list:

我已经打电话make -pn检查所有隐含的规则,但我没有看到一个似乎适用的规则。

我错过了什么?我希望能解释一下 make 正在执行的逻辑流程。

4

2 回答 2

1

Make 将匹配这个隐式规则(通过检查找到make -pf/def/null):

%: %.c
#  commands to execute (built-in):
        $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
于 2013-10-20T20:47:05.737 回答
1

这里忽略的事实是 make 如何将目标与隐式规则匹配。在这种情况下,没有指定先决条件,但是如果规则的先决条件存在或应该存在并且可以生成,则 make 将匹配隐式规则。当匹配隐式规则的先决条件存在且未指定时,它被视为隐式先决条件。

因此,要匹配的第一条规则是:

%: %.c
#  commands to execute (built-in):
        $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@

此页面有更多信息http://www.gnu.org/software/make/manual/html_node/Using-Implicit.html

Usingmake -d将显示 make 正在执行的步骤。这是此示例的相关输出:

Updating goal targets....
Considering target file `even_odd_list'.
 File `even_odd_list' does not exist.
 Looking for an implicit rule for `even_odd_list'.
 Trying pattern rule with stem `even_odd_list'.
 Trying implicit prerequisite `even_odd_list.o'.
 Trying pattern rule with stem `even_odd_list'.
 Trying implicit prerequisite `even_odd_list.c'.
 Found prerequisite `even_odd_list.c' as VPATH `src/even_odd_list.c'
 Found an implicit rule for `even_odd_list'.
  Considering target file `even_odd_list.c'.
   Looking for an implicit rule for `even_odd_list.c'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.y'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.l'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.w'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.w'.
   Trying pattern rule with stem `even_odd_list.c'.
   Trying implicit prerequisite `even_odd_list.c,v'.
   Trying pattern rule with stem `even_odd_list.c'.
   Trying implicit prerequisite `RCS/even_odd_list.c,v'.
   Trying pattern rule with stem `even_odd_list.c'.
   Trying implicit prerequisite `RCS/even_odd_list.c'.
   Trying pattern rule with stem `even_odd_list.c'.
   Trying implicit prerequisite `s.even_odd_list.c'.
   Trying pattern rule with stem `even_odd_list.c'.
   Trying implicit prerequisite `SCCS/s.even_odd_list.c'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.y'.
   Looking for a rule with intermediate file `even_odd_list.y'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `even_odd_list.y'.
    Trying implicit prerequisite `even_odd_list.y,v'.
    Trying pattern rule with stem `even_odd_list.y'.
    Trying implicit prerequisite `RCS/even_odd_list.y,v'.
    Trying pattern rule with stem `even_odd_list.y'.
    Trying implicit prerequisite `RCS/even_odd_list.y'.
    Trying pattern rule with stem `even_odd_list.y'.
    Trying implicit prerequisite `s.even_odd_list.y'.
    Trying pattern rule with stem `even_odd_list.y'.
    Trying implicit prerequisite `SCCS/s.even_odd_list.y'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.l'.
   Looking for a rule with intermediate file `even_odd_list.l'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `even_odd_list.l'.
    Trying implicit prerequisite `even_odd_list.l,v'.
    Trying pattern rule with stem `even_odd_list.l'.
    Trying implicit prerequisite `RCS/even_odd_list.l,v'.
    Trying pattern rule with stem `even_odd_list.l'.
    Trying implicit prerequisite `RCS/even_odd_list.l'.
    Trying pattern rule with stem `even_odd_list.l'.
    Trying implicit prerequisite `s.even_odd_list.l'.
    Trying pattern rule with stem `even_odd_list.l'.
    Trying implicit prerequisite `SCCS/s.even_odd_list.l'.
   Trying pattern rule with stem `even_odd_list'.
   Trying implicit prerequisite `even_odd_list.w'.
   Looking for a rule with intermediate file `even_odd_list.w'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `even_odd_list.w'.
    Trying implicit prerequisite `even_odd_list.w,v'.
    Trying pattern rule with stem `even_odd_list.w'.
    Trying implicit prerequisite `RCS/even_odd_list.w,v'.
    Trying pattern rule with stem `even_odd_list.w'.
    Trying implicit prerequisite `RCS/even_odd_list.w'.
    Trying pattern rule with stem `even_odd_list.w'.
    Trying implicit prerequisite `s.even_odd_list.w'.
    Trying pattern rule with stem `even_odd_list.w'.
    Trying implicit prerequisite `SCCS/s.even_odd_list.w'.
   Trying pattern rule with stem `even_odd_list'.
   Rejecting impossible implicit prerequisite `even_odd_list.w'.
   No implicit rule found for `even_odd_list.c'.
   Finished prerequisites of target file `even_odd_list.c'.
  No need to remake target `even_odd_list.c'; using VPATH name `src/even_odd_list.c'.
 Finished prerequisites of target file `even_odd_list'.
Must remake target `even_odd_list'.
cc  -I include   src/even_odd_list.c   -o even_odd_list
Putting child 0x085fbe90 (even_odd_list) PID 24853 on the chain.
Live child 0x085fbe90 (even_odd_list) PID 24853 
Reaping winning child 0x085fbe90 PID 24853 
Removing child 0x085fbe90 PID 24853 from chain.
Successfully remade target file `even_odd_list'.
于 2013-10-20T21:57:10.573 回答