How to change the default target of `make`?

The 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?

asked Dec 6, 2017 by anonymous

1 Answer

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
answered Dec 6, 2017 by Eric Z Ma (44,280 points)
edited Dec 6, 2017 by Eric Z Ma

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...