
Step 7 of 9:
Understanding Makefiles (cont.)
A makefile can contain four types of lines, each of which
are described below.
- Comment Lines -- All
lines in the makefile that begin with the # sign are
comments. These lines are provided simply to give the
user some useful information.
- Macro Definitions --
Macro definitions are the lines that define the name of
the macro, and then give its meaning. For example, CC =
cc means that CC is the macro name, and cc is its
definition. To dereference a macro you simply place it
inside parenthesis, and preceed it with the $ sign, for
example $(CC). This is the form the macro takes when
used in the target and action lines.
- Target Lines -- The
target lines list the goal, and the dependencies needed
to obtain the goal. The goal is the executable file that
you wish to create. The dependencies, either a file or
another goal, follow a colon and tell make what
this goal needs to be current. If any modifications are
made to a goal's dependencies then that goal is no
longer current, and the actions given on the action line
should be performed.
example: example.o
This line will make the executable file example dependent on
the object file example.o.
- Action Lines -- The
action lines tell make how to create the
dependencies, and therefore the goal. The macros given
on this line are expanded and used to compile the source
code into the executable name given on the target line. The
action lines must begin with a tab,not spaces, and must
come directly under a target line (ie. no newline
characters).
THE STEPS FOR COMPILATION AND EXECUTION ARE EXPLAINED IN STEP
8.

|