Makefile DEFAULT_GOAL 变量
Makefile DEFAULT_GOAL variable
这是一个使用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
我坚持理解 echo 和 $(warning) 函数的流程是什么,即当 $(warning) 函数被称为 echo $@ 输出被抑制并显示 echo $@ 的最后输出。因为有 2 echo statement 和 3 $(warning ) function call 但 echo the last one foo 只打印了一个 target id。为什么不打印其他值,为什么最后一个值打印为 foo 为什么不打印 bar?
警告和分配发生在 make
读取 Makefile
时。只有这样它才开始决定要执行哪些规则。其他 echo
语句永远不会执行,因为它只会在该点设定默认目标,即 foo
.
这是一个使用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
我坚持理解 echo 和 $(warning) 函数的流程是什么,即当 $(warning) 函数被称为 echo $@ 输出被抑制并显示 echo $@ 的最后输出。因为有 2 echo statement 和 3 $(warning ) function call 但 echo the last one foo 只打印了一个 target id。为什么不打印其他值,为什么最后一个值打印为 foo 为什么不打印 bar?
警告和分配发生在 make
读取 Makefile
时。只有这样它才开始决定要执行哪些规则。其他 echo
语句永远不会执行,因为它只会在该点设定默认目标,即 foo
.