How does “make” app know default target to build if no target is specified?
$ make
which target to build?
By default, it begins by processing the first target that does not begin with a .
aka the default goal; to do that, it may have to process other targets - specifically, ones the first target depends on.
The GNU Make Manual covers all this stuff, and is a surprisingly easy and informative read.
If you like to override this behavior, there is the .DEFAULT_GOAL:
special target. An example from GNU make manual.
The following example illustrates these cases:
# Query the 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
This makefile prints:
no default goal is set
default goal is foo
default goal is bar
foo
About .DEFAULT, have not understand it. there is a blog for it.
all:gao
@echo "final"
.DEFAULT:
@echo "In default"
由於 gao 是一個前提條件,但是 makefile中沒有一個名字爲 gao的目的。
所以符合 .DEFAULT 目的的執行條件。
故執行結果爲:
In default
final
完畢