Chapter 5. Commands
We’ve already covered many of the basic elements of make commands, but just to make sure we’re all on the same page, let’s review a little.
Commands are essentially one-line shell scripts. In effect, make grabs each line and passes it to a subshell for execution. In fact, make can optimize this (relatively) expensive fork/exec algorithm if it can guarantee that omitting the shell will not change the behavior of the program. It checks this by scanning each command line for shell special characters, such as wildcard characters and i/o redirection. If none are found, make directly executes the command without passing it to a subshell.
By default, /bin/sh is used for the shell. This
shell is controlled by the make variable SHELL but it is not inherited from the environment. When
make starts, it imports all the variables from the
user’s environment as make variables, except SHELL. This is because the user’s choice of shell should not
cause a makefile (possibly included in some downloaded
software package) to fail. If a user really wants to change the default shell used by
make, he can set the SHELL variable explicitly in the makefile.
We will discuss this issue in the Section 5.2
later in this chapter.
Parsing Commands
Following a make target, lines whose first character is a tab are assumed to be commands (unless the previous line was continued with a backslash). GNU make tries to be as smart as possible when handling tabs in other contexts. For instance, when there ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access