How does "make" app know default target to build if no target is specified?

Viewed 176756

Most Linux apps are compiled with:

make
make install clean

As I understand it, the make command takes names of build targets as arguments. So for example install is usually a target that copies some files to standard locations, and clean is a target that removes temporary files.

But what target will make build if no arguments are specified (e.g. the first command in my example)?

4 Answers

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.

bmake's equivalent of GNU Make's .DEFAULT_GOAL is .MAIN:

$ cat Makefile
.MAIN: foo

all:
    @echo all

foo:
    @echo foo
$ bmake
foo

See the bmake(1) manual page.

Related