Makefile DEFAULT_GOAL 变量

Abh*_*ngh 5 linux makefile

这是使用 DEFAULT_GOAL 变量的示例:

ifeq ($(.DEFAULT_GOAL),)
  $(warning no default goal is set)
endif

.PHONY: foo
foo: ; @echo $@

$(warning default goal is $(.DEFAULT_GOAL))

# Reset the default goal.
.DEFAULT_GOAL :=

.PHONY: bar
bar: ; @echo $@

$(warning default goal is $(.DEFAULT_GOAL))

# Set our own.
.DEFAULT_GOAL := foo


The output is:

no default goal is set
default goal is foo
default goal is bar
foo
Run Code Online (Sandbox Code Playgroud)

我坚持理解echo 和 $(warning )函数的流程是什么,即当调用$(warning )函数时, echo $@输出被抑制,并显示echo $@的最后一个输出。因为有2 个 echo 语句3 个 $(warning ) 函数调用,但 echo 最后一个 foo 只打印了一个目标 id。为什么其他值不打印,为什么最后一个值打印为 foo 为什么不打印 bar?

tri*_*eee 2

警告和分配发生如make读取Makefile。只有那时它才开始决定执行哪些规则。其他echo语句永远不会执行,因为它只在该点实现默认目标,即foo