makefile中的命令行选项' - what-if'不起作用

时间:2015-08-20 02:21:57

标签: makefile gnu-make

来自GNU制作docs

  

-W FILE   
  --what-if=FILE   
  --assume-new=FILE   
  --new-file=FILE   
  

 "What if".  Each '-W' flag is followed by a file name.  The given
 files' modification times are recorded by 'make' as being the
 present time, although the actual modification times remain the
 same.  You can use the '-W' flag in conjunction with the '-n' flag
 to see what would happen if you were to modify specific files.


还有elsewhere

  

' - W FILE'   
  ' - 什么-IF = FILE'   
  '--new-file =文件'   
  '--assume-新= FILE'   
  

 Pretend that the target FILE has just been modified.  When used
 with the '-n' flag, this shows you what would happen if you were to
 modify that file.  Without '-n', it is almost the same as running a
 'touch' command on the given file before running 'make', except
 that the modification time is changed only in the imagination of
 'make'.  *Note Instead of Executing Recipes: Instead of Execution.



所以,给定一个makefile:

# 'all' is "up-to-date", when it is "checked" against its prerequisites 'foo'.
$(shell touch foo)
$(shell sleep 1)
$(shell touch all)

all : foo
    echo '$@'

foo : phony
    : blah blah

.PHONY : phony



正在运行,我得到:

# 'all' would-be "up-to-date", when it is "checked" against its prerequisites 'foo'.
$ touch 'foo'
$ sleep 1
$ touch 'all'

# To quote the documentation, cited above, we:
# "Change the modification-time in the imagination of Make", for the file: 'foo'
$ make --new-file='foo'
: blah blah

没有为'all'文件执行任何命令,尽管有明确的命令行选项--new-file=foo,它应该改变Make的“想象”中的修改时间,如上面引用中所述

1 个答案:

答案 0 :(得分:1)

行。你对这面旗帜的理解是错误的。 gnu make跟踪生成的文件。你的测试程序是bazaar,因为依赖项没有生成任何内容。

在原始程序中:

foo : phony
    : blah blah

.PHONY : phony

phony是一个伪目标,make必须强制运行它,以及依赖它的目标。这就是你的foo目标代码运行的原因 - 它与文件系统中文件foo的状态无关。

因为all取决于foo,所以要生成foo运行命令之前的修改时间以及之后是相同的,所以在{从{1}}的角度来看,根本不需要生成make,这是普通all用法的预期行为。

以下是我的代码,用于演示此标志的用途:

make

然后在你的控制台中:

all : foo
        touch all

foo : phony
        touch foo
然后再次:

$ touch phony && make
touch foo
touch all

原因应该是显而易见的。那么如果我添加那个标志:

$ make
make: 'all' is up to date.

现在你会看到。

这里的区别在于$ make --new-file=phony touch foo touch all 的虚构,依赖make已被修改,因此整个依赖树也需要刷新。

如果我们合并文档:

  

使用时    使用'-n'标志,这会告诉您如果要这样做会发生什么    修改该文件。

这很有道理,因为它允许我探测依赖树,看看如果我修改这个文件需要重建多少东西。