当只有一个目标指定没有(显式)先决条件时,会调用哪些隐式规则?

时间:2013-10-20 20:45:25

标签: makefile

我在even_odd_list.c目录中有源文件src。以下是makefile我正在尝试

VPATH = src include
CPPFLAGS = -I include

even_odd_list:

我已调用make -pn来检查所有隐式规则,但我没有看到似乎适用的规则。

我错过了什么?我将理解正在执行的逻辑流程的解释。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

所以,匹配的第一条规则是:

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

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

使用make -d将显示正在执行的步骤。以下是此示例的相关输出:

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'.