Introduction to GNU make107
Rule to Build the Default Goal
After defining the variables, the first rule defines the default goal. This is usually used to
build one or more final executable from all of the source, object and library files.
Rules to Build Other Goals
After defining the default goal, you can define as many other rules as you like. These other
rules are used to build individual parts of a big project. For example, if a project consists of three
main parts, the FTP server, the TFTP server and the DNS resolver, you can have three individual
rules for all of these individual parts. The default goal may be used to build all of these three tar-
gets in a single step.
Rules to Build Individual Objects
In addition to defining rules to build goals, you may have to define rules to build individ-
ual objects or intermediate files. One example of these rules is to build object files from the
source files. These object files may then be used to build executable or library files.
Rules to Install
Some rules may be required to install the files into appropriate directories created by other
rules. For example, after building library files, you may want to install them into
/lib
or
/
usr/lib
directory. Similarly, after building executable files, you may want to install them into
/bin
,
/usr/bin
or
/sbin
directory or any other directory of your choice. For this reason,
one or more rules may be defined in the makefiles so that ma
ke
copies the appropriate files into
their target location.
Rules to Clean Previous Builds
As mentioned earlier, the rule to clean previous builds is usually a phony rule to clean up
the source code tree from the previously built intermediate and target files. This rule is useful
when you want to hand over a clean directory to someone or to force everything to be rebuilt,
perhaps with new options.
Comments and Blank Lines
As a good convention, you can insert some comment lines in makefiles so that you and
others can make sense of what is there. All comments start with a hash (#) symbol. You can also
put a comment after a command. The rule of thumb is that anything after the hash character will
be considered a comment. If this character is the first character in a line, all of the line is a com-
ment line.
C A U T I O N Any empty line that begins with a TAB is not really
an empty line. It is considered an empty command. Empty com-
mands are sometimes useful when you don’t want to take any
action for a particular dependency.
Next Page >>
<< Previous Page
Back to the Table of Contents