Introduction to GNU make109
4.1.5Shell to Execute Commands
All commands in a makefile are executed in a subshell invoked by the
make
command. It
is important to know which shell will be used to execute commands in the makefile. By default
the shell name is
/bin/sh
. However this can be changed using the
SHELL
variable in the
makefile. Please note that this is not the environment variable
SHELL
, but is set within the
makefile. This is to avoid conflict with someone’s personal preference of using a particular shell.
Each line that starts with TAB character represents a command and is executed by a single
instance of shell. So, for example, the following line will cause a directory change to
tftp
and
the command
rm *.o
to be executed from that directory. After executing this command, the
next
command is executed in the original directory because a new subshell is invoked and the
effect of the
cd tftp
command is gone.
tftp: tftp/Makefile
cd tftp; rm *.o
@echo “Rebuilding . . .”
As mentioned earlier, one line can be split into multiple lines by placing a backslash at the
end of the line. The above three lines can be written as follows without any change in their
result:
tftp: tftp/Makefile
(cd tftp;\
rm *.o)
@echo “Makefile changed. Rebuilding …”
4.1.6Include Files
In case of large projects, makefile rules can be split into many files. These smaller files can
then be included into a makefile. When the
make
utility is scanning through the makefile
and it
finds an
include
file, it will go through the
include
file before going to the next line in the
makefile. Logically, you can think of contents of the
include
file being inserted into the
makefile at the place where the file is included.
Files can be included using the
include
directive inside a makefile. The following line
includes a file
myrules.in
in a makefile.
include myrules.in
Multiple files can be included into a makefile on the same line. The following line
includes two files
myrules.in
and
bootarules.in
into a makefile.
include myrules.in bootarules.in
When multiple files are included, these are read in the order they are present in the make-
file. In the above example, first
myrules.in
will be read by the
make
utility and then
boot-
arules.in
will be read.
Next Page >>
<< Previous Page
Back to the Table of Contents