How to change the default target of `make`?
Posted on In QAThe default target of make
is the first target. But can I change the default target in Makefile
and how to change the default target of make
?
The default goal of make
is the first target whose name does not start with ‘.’ if .DEFAULT_GOAL
is not set. Ref: make manual.
To set the default target to ‘default’ as an example being not the first target in the Makefile, you have at least 2 ways.
Way 1. Set the .DEFAULT_GOAL
special variable to ‘default’.
.DEFAULT_GOAL := default
# other targets ...
default:
@ echo default target
Way 2. clear the .DEFAULT_GOAL
special variable before the ‘default’ target so that ‘default’ turns to the first target after .DEFAULT_GOAL
is not set.
# other targets ...
.DEFAULT_GOAL :=
# no target starting with '.' should be here
# between .DEFAULT_GOAL and 'default'
default:
@ echo default target