Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad to have no default target in a Makefile

Tags:

linux

makefile

Is it bad practice to have something like:

all:

in a Makefile, to enforce the user to specify the target, and ignore the default one?

like image 462
kaspersky Avatar asked Feb 26 '13 17:02

kaspersky


People also ask

What is makefile default target?

By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe.

What does default mean in makefile?

The default behavior of make is to run the first target in the Makefile if you don't specify a target as a command-line argument. If you like to override this behavior, there is the . DEFAULT: special target.

What happens if you run make with no arguments?

With no argument, make runs as many jobs simultaneously as possible. If there is more than one `-j' option, the last one is effective. See section Parallel Execution, for more information on how commands are run. Note that this option is ignored on MS-DOS.

What will not happen if u run the make command without parameters?

Without arguments, make builds the first target that appears in its makefile, which is traditionally a target named all. make decides whether a target needs to be regenerated by comparing file modification times.


1 Answers

all is not necessarily the default target. The default target is the first one defined in your makefile. Also, if you leave an empty target as the default one (and are sure that there's no other all target with rules somewhere else in the makefile), make's behavior might be a little bit puzzling. I'd suggest to let the default behavior print an appropriate error message, such as:

error:
        @echo "Please choose one of the following target: compile, install, uninstall"
        @# Alternatively: "Please RTFI(nstall)F(ile)"
        @exit 2
like image 63
Virgile Avatar answered Oct 10 '22 12:10

Virgile