【发布时间】:2015-08-21 10:34:17
【问题描述】:
来自docs:
-n、-t和-q选项不会影响那些 以+字符开头或包含字符串$(MAKE)或${MAKE}。 请注意,只有包含+字符的行或字符串 无论这些选项如何,都会运行$(MAKE)或${MAKE}。其他线路 除非它们也以+开头或包含$(MAKE)或${MAKE}。
现在,给定一个 makefile:
# 'test -f foo' is "false".
$(shell rm -rf foo)
# 'test -f bar' is "true".
$(shell rm -rf bar; touch bar)
# 'test -f bar' will be executed, even for -[tnq] command-line options. NOT SO, for 'test -f foo'.
define cmd
test -f 'foo'
+test -f 'bar'
endef
1 2 ::
$(cmd)
运行,我们得到:
$ make --just-print 1
test -f 'foo'
test -f 'bar'
#####################
$ make --just-print 2
test -f 'foo'
test -f 'bar'
#####################
$ make --just-print 1 2
test -f 'foo'
test -f 'bar'
test -f 'foo'
makefile:14: recipe for target '2' failed
make: *** [2] Error 1
#####################
$ make --just-print 2 1
test -f 'foo'
test -f 'bar'
test -f 'foo'
makefile:14: recipe for target '1' failed
make: *** [1] Error 1
显然,我们这里有 4 个案例:
-
make --just-print 1-
test -f foo,显然是一个“错误”命令,成功。这是因为--just-print命令行选项,所以 Make 并没有真正“运行”它。这只是一个回声。 -
test -f bar,由于+前缀而实际运行的命令。但鉴于这个秘籍是一个“真正的”命令,它成功也就不足为奇了。
-
-
make --just-print 2-
正是作为案例1。好吧,为执行配方的目标在这里可能不同(
2与1),但执行的配方是 100%相同。这包括他们成功背后的“逻辑”,在case 1中进行了解释。
-
正是作为案例1。好吧,为执行配方的目标在这里可能不同(
-
make --just-print 1 2- 这更复杂。它以
case 1开头,出于同样的原因,test -f foo和test -f bar都成功了。 - 但是,当 Make 必须通过执行
2的配方来“重复”相同的“例程”时,会发生致命错误。为什么?
- 这更复杂。它以
-
make --just-print 2 1- 与
case 3相同,但2和1目标在这里扮演某种“相反”的角色。也就是说,2的执行成功(根据case 2)但随后在目标1上失败。
- 与
现在,毫无疑问,这里出了点问题。
因为在--just-print 模式下执行时,test -f foo 的 Make 永远不会失败。
很简单,因为Make不允许执行命令。它应该只是回应它!
那么,这里出了什么问题?
【问题讨论】: