make选项-r -R的用途是什么?

时间:2016-03-28 00:48:47

标签: makefile

来自make --help其状态:

-r, --no-builtin-rules      Disable the built-in implicit rules.
-R, --no-builtin-variables  Disable the built-in variable settings.

什么时候需要使用这些选项?有时我确实看到人们同时使用-rR

1 个答案:

答案 0 :(得分:0)

禁用内置规则和变量主要用于调试目的,但在某些情况下禁用规则可能会提高性能。

野外大多数“严肃”的makefile往往会为所有内容声明自己的规则和配方,因此内置规则通常是多余的。禁用它们可以加速makefile的执行,具体取决于它的编写方式。

假设您有以下makefile以及名为foo.cpp

的单个文件
foo: foo.o

Make的调试转储是

Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
 Considering target file 'Makefile'.
  Looking for an implicit rule for 'Makefile'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.o'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.c'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.cc'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.C'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.cpp'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.p'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.f'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.F'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.m'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.r'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.s'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.S'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.mod'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.sh'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile,v'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'RCS/Makefile,v'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'RCS/Makefile'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 's.Makefile'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'SCCS/s.Makefile'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.o'.
  Looking for a rule with intermediate file 'Makefile.o'.
   Avoiding implicit rule recursion.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.c'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.cc'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.C'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.cpp'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.p'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.f'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.F'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.m'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.r'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.s'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.S'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.mod'.
   Trying pattern rule with stem 'Makefile.o'.
   Trying implicit prerequisite 'Makefile.o,v'.
   Trying pattern rule with stem 'Makefile.o'.
   Trying implicit prerequisite 'RCS/Makefile.o,v'.
   Trying pattern rule with stem 'Makefile.o'.
   Trying implicit prerequisite 'RCS/Makefile.o'.
   Trying pattern rule with stem 'Makefile.o'.
   Trying implicit prerequisite 's.Makefile.o'.
   Trying pattern rule with stem 'Makefile.o'.
   Trying implicit prerequisite 'SCCS/s.Makefile.o'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.c'.
   Looking for a rule with intermediate file 'Makefile.c'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.y'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.l'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.w'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.w'.
    Trying pattern rule with stem 'Makefile.c'.
    Trying implicit prerequisite 'Makefile.c,v'.
    Trying pattern rule with stem 'Makefile.c'.
    Trying implicit prerequisite 'RCS/Makefile.c,v'.
    Trying pattern rule with stem 'Makefile.c'.
    Trying implicit prerequisite 'RCS/Makefile.c'.
    Trying pattern rule with stem 'Makefile.c'.
    Trying implicit prerequisite 's.Makefile.c'.
    Trying pattern rule with stem 'Makefile.c'.
    Trying implicit prerequisite 'SCCS/s.Makefile.c'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.y'.
    Looking for a rule with intermediate file 'Makefile.y'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.y'.
     Trying implicit prerequisite 'Makefile.y,v'.
     Trying pattern rule with stem 'Makefile.y'.
     Trying implicit prerequisite 'RCS/Makefile.y,v'.
     Trying pattern rule with stem 'Makefile.y'.
     Trying implicit prerequisite 'RCS/Makefile.y'.
     Trying pattern rule with stem 'Makefile.y'.
     Trying implicit prerequisite 's.Makefile.y'.
     Trying pattern rule with stem 'Makefile.y'.
     Trying implicit prerequisite 'SCCS/s.Makefile.y'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.l'.
    Looking for a rule with intermediate file 'Makefile.l'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.l'.
     Trying implicit prerequisite 'Makefile.l,v'.
     Trying pattern rule with stem 'Makefile.l'.
     Trying implicit prerequisite 'RCS/Makefile.l,v'.
     Trying pattern rule with stem 'Makefile.l'.
     Trying implicit prerequisite 'RCS/Makefile.l'.
     Trying pattern rule with stem 'Makefile.l'.
     Trying implicit prerequisite 's.Makefile.l'.
     Trying pattern rule with stem 'Makefile.l'.
     Trying implicit prerequisite 'SCCS/s.Makefile.l'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.w'.
    Looking for a rule with intermediate file 'Makefile.w'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.w'.
     Trying implicit prerequisite 'Makefile.w,v'.
     Trying pattern rule with stem 'Makefile.w'.
     Trying implicit prerequisite 'RCS/Makefile.w,v'.
     Trying pattern rule with stem 'Makefile.w'.
     Trying implicit prerequisite 'RCS/Makefile.w'.
     Trying pattern rule with stem 'Makefile.w'.
     Trying implicit prerequisite 's.Makefile.w'.
     Trying pattern rule with stem 'Makefile.w'.
     Trying implicit prerequisite 'SCCS/s.Makefile.w'.
    Trying pattern rule with stem 'Makefile'.
    Rejecting impossible implicit prerequisite 'Makefile.w'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.cc'.
   Looking for a rule with intermediate file 'Makefile.cc'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile.cc'.
    Trying implicit prerequisite 'Makefile.cc,v'.
    Trying pattern rule with stem 'Makefile.cc'.
    Trying implicit prerequisite 'RCS/Makefile.cc,v'.
    Trying pattern rule with stem 'Makefile.cc'.
    Trying implicit prerequisite 'RCS/Makefile.cc'.
    Trying pattern rule with stem 'Makefile.cc'.
    Trying implicit prerequisite 's.Makefile.cc'.
    Trying pattern rule with stem 'Makefile.cc'.
    Trying implicit prerequisite 'SCCS/s.Makefile.cc'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.C'.
   Looking for a rule with intermediate file 'Makefile.C'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile.C'.
    Trying implicit prerequisite 'Makefile.C,v'.
    Trying pattern rule with stem 'Makefile.C'.
    Trying implicit prerequisite 'RCS/Makefile.C,v'.
    Trying pattern rule with stem 'Makefile.C'.
    Trying implicit prerequisite 'RCS/Makefile.C'.
    Trying pattern rule with stem 'Makefile.C'.
    Trying implicit prerequisite 's.Makefile.C'.
    Trying pattern rule with stem 'Makefile.C'.
    Trying implicit prerequisite 'SCCS/s.Makefile.C'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.cpp'.
   Looking for a rule with intermediate file 'Makefile.cpp'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile.cpp'.
    Trying implicit prerequisite 'Makefile.cpp,v'.
    Trying pattern rule with stem 'Makefile.cpp'.
    Trying implicit prerequisite 'RCS/Makefile.cpp,v'.
    Trying pattern rule with stem 'Makefile.cpp'.
    Trying implicit prerequisite 'RCS/Makefile.cpp'.
    Trying pattern rule with stem 'Makefile.cpp'.
    Trying implicit prerequisite 's.Makefile.cpp'.
    Trying pattern rule with stem 'Makefile.cpp'.
    Trying implicit prerequisite 'SCCS/s.Makefile.cpp'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.p'.
   Looking for a rule with intermediate file 'Makefile.p'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.web'.
    Trying pattern rule with stem 'Makefile.p'.
    Trying implicit prerequisite 'Makefile.p,v'.
    Trying pattern rule with stem 'Makefile.p'.
    Trying implicit prerequisite 'RCS/Makefile.p,v'.
    Trying pattern rule with stem 'Makefile.p'.
    Trying implicit prerequisite 'RCS/Makefile.p'.
    Trying pattern rule with stem 'Makefile.p'.
    Trying implicit prerequisite 's.Makefile.p'.
    Trying pattern rule with stem 'Makefile.p'.
    Trying implicit prerequisite 'SCCS/s.Makefile.p'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.web'.
    Looking for a rule with intermediate file 'Makefile.web'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.web'.
     Trying implicit prerequisite 'Makefile.web,v'.
     Trying pattern rule with stem 'Makefile.web'.
     Trying implicit prerequisite 'RCS/Makefile.web,v'.
     Trying pattern rule with stem 'Makefile.web'.
     Trying implicit prerequisite 'RCS/Makefile.web'.
     Trying pattern rule with stem 'Makefile.web'.
     Trying implicit prerequisite 's.Makefile.web'.
     Trying pattern rule with stem 'Makefile.web'.
     Trying implicit prerequisite 'SCCS/s.Makefile.web'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.f'.
   Looking for a rule with intermediate file 'Makefile.f'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.F'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.r'.
    Trying pattern rule with stem 'Makefile.f'.
    Trying implicit prerequisite 'Makefile.f,v'.
    Trying pattern rule with stem 'Makefile.f'.
    Trying implicit prerequisite 'RCS/Makefile.f,v'.
    Trying pattern rule with stem 'Makefile.f'.
    Trying implicit prerequisite 'RCS/Makefile.f'.
    Trying pattern rule with stem 'Makefile.f'.
    Trying implicit prerequisite 's.Makefile.f'.
    Trying pattern rule with stem 'Makefile.f'.
    Trying implicit prerequisite 'SCCS/s.Makefile.f'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.F'.
    Looking for a rule with intermediate file 'Makefile.F'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.F'.
     Trying implicit prerequisite 'Makefile.F,v'.
     Trying pattern rule with stem 'Makefile.F'.
     Trying implicit prerequisite 'RCS/Makefile.F,v'.
     Trying pattern rule with stem 'Makefile.F'.
     Trying implicit prerequisite 'RCS/Makefile.F'.
     Trying pattern rule with stem 'Makefile.F'.
     Trying implicit prerequisite 's.Makefile.F'.
     Trying pattern rule with stem 'Makefile.F'.
     Trying implicit prerequisite 'SCCS/s.Makefile.F'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.r'.
    Looking for a rule with intermediate file 'Makefile.r'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile'.
     Rejecting impossible implicit prerequisite 'Makefile.l'.
     Trying pattern rule with stem 'Makefile.r'.
     Trying implicit prerequisite 'Makefile.r,v'.
     Trying pattern rule with stem 'Makefile.r'.
     Trying implicit prerequisite 'RCS/Makefile.r,v'.
     Trying pattern rule with stem 'Makefile.r'.
     Trying implicit prerequisite 'RCS/Makefile.r'.
     Trying pattern rule with stem 'Makefile.r'.
     Trying implicit prerequisite 's.Makefile.r'.
     Trying pattern rule with stem 'Makefile.r'.
     Trying implicit prerequisite 'SCCS/s.Makefile.r'.
   Trying pattern rule with stem 'Makefile'.
   Rejecting impossible implicit prerequisite 'Makefile.F'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.m'.
   Looking for a rule with intermediate file 'Makefile.m'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.ym'.
    Trying pattern rule with stem 'Makefile.m'.
    Trying implicit prerequisite 'Makefile.m,v'.
    Trying pattern rule with stem 'Makefile.m'.
    Trying implicit prerequisite 'RCS/Makefile.m,v'.
    Trying pattern rule with stem 'Makefile.m'.
    Trying implicit prerequisite 'RCS/Makefile.m'.
    Trying pattern rule with stem 'Makefile.m'.
    Trying implicit prerequisite 's.Makefile.m'.
    Trying pattern rule with stem 'Makefile.m'.
    Trying implicit prerequisite 'SCCS/s.Makefile.m'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.ym'.
    Looking for a rule with intermediate file 'Makefile.ym'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.ym'.
     Trying implicit prerequisite 'Makefile.ym,v'.
     Trying pattern rule with stem 'Makefile.ym'.
     Trying implicit prerequisite 'RCS/Makefile.ym,v'.
     Trying pattern rule with stem 'Makefile.ym'.
     Trying implicit prerequisite 'RCS/Makefile.ym'.
     Trying pattern rule with stem 'Makefile.ym'.
     Trying implicit prerequisite 's.Makefile.ym'.
     Trying pattern rule with stem 'Makefile.ym'.
     Trying implicit prerequisite 'SCCS/s.Makefile.ym'.
   Trying pattern rule with stem 'Makefile'.
   Rejecting impossible implicit prerequisite 'Makefile.r'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.s'.
   Looking for a rule with intermediate file 'Makefile.s'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.S'.
    Trying pattern rule with stem 'Makefile.s'.
    Trying implicit prerequisite 'Makefile.s,v'.
    Trying pattern rule with stem 'Makefile.s'.
    Trying implicit prerequisite 'RCS/Makefile.s,v'.
    Trying pattern rule with stem 'Makefile.s'.
    Trying implicit prerequisite 'RCS/Makefile.s'.
    Trying pattern rule with stem 'Makefile.s'.
    Trying implicit prerequisite 's.Makefile.s'.
    Trying pattern rule with stem 'Makefile.s'.
    Trying implicit prerequisite 'SCCS/s.Makefile.s'.
    Trying pattern rule with stem 'Makefile'.
    Trying implicit prerequisite 'Makefile.S'.
    Looking for a rule with intermediate file 'Makefile.S'.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Avoiding implicit rule recursion.
     Trying pattern rule with stem 'Makefile.S'.
     Trying implicit prerequisite 'Makefile.S,v'.
     Trying pattern rule with stem 'Makefile.S'.
     Trying implicit prerequisite 'RCS/Makefile.S,v'.
     Trying pattern rule with stem 'Makefile.S'.
     Trying implicit prerequisite 'RCS/Makefile.S'.
     Trying pattern rule with stem 'Makefile.S'.
     Trying implicit prerequisite 's.Makefile.S'.
     Trying pattern rule with stem 'Makefile.S'.
     Trying implicit prerequisite 'SCCS/s.Makefile.S'.
   Trying pattern rule with stem 'Makefile'.
   Rejecting impossible implicit prerequisite 'Makefile.S'.
   Trying pattern rule with stem 'Makefile'.
   Trying implicit prerequisite 'Makefile.mod'.
   Looking for a rule with intermediate file 'Makefile.mod'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'Makefile.mod'.
    Trying implicit prerequisite 'Makefile.mod,v'.
    Trying pattern rule with stem 'Makefile.mod'.
    Trying implicit prerequisite 'RCS/Makefile.mod,v'.
    Trying pattern rule with stem 'Makefile.mod'.
    Trying implicit prerequisite 'RCS/Makefile.mod'.
    Trying pattern rule with stem 'Makefile.mod'.
    Trying implicit prerequisite 's.Makefile.mod'.
    Trying pattern rule with stem 'Makefile.mod'.
    Trying implicit prerequisite 'SCCS/s.Makefile.mod'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.c'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.cc'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.C'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.cpp'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.p'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.f'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.F'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.m'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.r'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.s'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.S'.
  Trying pattern rule with stem 'Makefile'.
  Rejecting impossible implicit prerequisite 'Makefile.mod'.
  Trying pattern rule with stem 'Makefile'.
  Trying implicit prerequisite 'Makefile.sh'.
  Looking for a rule with intermediate file 'Makefile.sh'.
   Avoiding implicit rule recursion.
   Trying pattern rule with stem 'Makefile.sh'.
   Trying implicit prerequisite 'Makefile.sh,v'.
   Trying pattern rule with stem 'Makefile.sh'.
   Trying implicit prerequisite 'RCS/Makefile.sh,v'.
   Trying pattern rule with stem 'Makefile.sh'.
   Trying implicit prerequisite 'RCS/Makefile.sh'.
   Trying pattern rule with stem 'Makefile.sh'.
   Trying implicit prerequisite 's.Makefile.sh'.
   Trying pattern rule with stem 'Makefile.sh'.
   Trying implicit prerequisite 'SCCS/s.Makefile.sh'.
  No implicit rule found for 'Makefile'.
  Finished prerequisites of target file 'Makefile'.
 No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'foo'.
 File 'foo' does not exist.
 Looking for an implicit rule for 'foo'.
 Trying pattern rule with stem 'foo'.
 Trying implicit prerequisite 'foo.o'.
 Found an implicit rule for 'foo'.
  Considering target file 'foo.o'.
   Looking for an implicit rule for 'foo.o'.
   Trying pattern rule with stem 'foo'.
   Trying implicit prerequisite 'foo.c'.
   Trying pattern rule with stem 'foo'.
   Trying implicit prerequisite 'foo.cc'.
   Trying pattern rule with stem 'foo'.
   Trying implicit prerequisite 'foo.C'.
   Trying pattern rule with stem 'foo'.
   Trying implicit prerequisite 'foo.cpp'.
   Found an implicit rule for 'foo.o'.
    Considering target file 'foo.cpp'.
     Looking for an implicit rule for 'foo.cpp'.
     Trying pattern rule with stem 'foo.cpp'.
     Trying implicit prerequisite 'foo.cpp,v'.
     Trying pattern rule with stem 'foo.cpp'.
     Trying implicit prerequisite 'RCS/foo.cpp,v'.
     Trying pattern rule with stem 'foo.cpp'.
     Trying implicit prerequisite 'RCS/foo.cpp'.
     Trying pattern rule with stem 'foo.cpp'.
     Trying implicit prerequisite 's.foo.cpp'.
     Trying pattern rule with stem 'foo.cpp'.
     Trying implicit prerequisite 'SCCS/s.foo.cpp'.
     No implicit rule found for 'foo.cpp'.
     Finished prerequisites of target file 'foo.cpp'.
    No need to remake target 'foo.cpp'.
   Finished prerequisites of target file 'foo.o'.
   Prerequisite 'foo.cpp' is older than target 'foo.o'.
  No need to remake target 'foo.o'.
  Pruning file 'foo.o'.
 Finished prerequisites of target file 'foo'.
Must remake target 'foo'.
cc   foo.o   -o foo
Putting child 0x7fc4d94124c0 (foo) PID 1581 on the chain.
Live child 0x7fc4d94124c0 (foo) PID 1581 
Reaping winning child 0x7fc4d94124c0 PID 1581 
Removing child 0x7fc4d94124c0 PID 1581 from chain.
Successfully remade target file 'foo'.

似乎很多工作都是如此微不足道,尽管其中大部分都与重新制作makefile而不是目标本身有关。不过,这可以在一个包含大量源文件和makefile的大项目中加起来。

现在看一下这个文件的调试输出

foo: foo.o
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(OUTPUT_OPTION) $<

使用make -r

调用
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
 Considering target file 'Makefile'.
  Looking for an implicit rule for 'Makefile'.
  No implicit rule found for 'Makefile'.
  Finished prerequisites of target file 'Makefile'.
 No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'foo'.
 File 'foo' does not exist.
  Considering target file 'foo.o'.
   File 'foo.o' does not exist.
   Looking for an implicit rule for 'foo.o'.
   Trying pattern rule with stem 'foo'.
   Trying implicit prerequisite 'foo.cpp'.
   Found an implicit rule for 'foo.o'.
    Considering target file 'foo.cpp'.
     Looking for an implicit rule for 'foo.cpp'.
     No implicit rule found for 'foo.cpp'.
     Finished prerequisites of target file 'foo.cpp'.
    No need to remake target 'foo.cpp'.
   Finished prerequisites of target file 'foo.o'.
  Must remake target 'foo.o'.
g++   -c -o foo.o foo.cpp
Putting child 0x7fe1c0503520 (foo.o) PID 1614 on the chain.
Live child 0x7fe1c0503520 (foo.o) PID 1614 
Reaping winning child 0x7fe1c0503520 PID 1614 
Removing child 0x7fe1c0503520 PID 1614 from chain.
  Successfully remade target file 'foo.o'.
 Finished prerequisites of target file 'foo'.
Must remake target 'foo'.
g++    foo.o  -o foo
Putting child 0x7fe1c05038b0 (foo) PID 1618 on the chain.
Live child 0x7fe1c05038b0 (foo) PID 1618 
Reaping winning child 0x7fe1c05038b0 PID 1618 
Removing child 0x7fe1c05038b0 PID 1618 from chain.
Successfully remade target file 'foo'.

您现在不仅可以完全控制食谱,而且还可以通过准确指定您需要的食物来提高效率。

也就是说,如果您发现自己完全克隆了内置规则,您可以考虑简单地禁用 所需的规则

$(MAKEFILE_LIST): ;
%.o: %.c
%.o: %.cc
%.o: %.C
%.cpp: ;
%: ;

至于内置变量,我不能说除了调试之外我已经找到-R的用途,请记住-R已经隐含-r作为内置-in规则没有变量就没用了。