demo2.o: demo2.cxx throttle.h
g++ -Wall -c -gstabs demo2.cxx
The first line is called a target line, which begins with a file name and
a colon. After the colon is a list of more file names. Here's how to
interpret the line: The file before the colon (called the target file)
depends on the other files (after the colon). Whenever one of the files
after the colon changes, the make tool knows that the target file needs
to be regenerated. After the target line, there is a series of commands
that tell exactly how to regenerate the target file. For the case of
demo2.o, we only need the one g++ command to regenerate the file.
(Notice that we included the -c flag to indicate that we should only
compile and not create an executable file yet. We also included the
-gstabs flag in case we want to use the debugger.)
There is one
other peculiar requirement: The command lines (such as the g++ command)
must each begin with a tab (not with 8 spaces!).
As a second example of a dependency, the executable file demo2 is
created by compiling together the object files demo2.o and throttle.o.
If either of these two object files should change, then demo2 also
needs to be recreated. Here is the appropriate target line and command
from our makefile:
demo2$(SUFFIX): demo2.o throttle.o
g++ -Wall -gstabs demo2.o throttle.o -o demo2
This target line says that if demo2.o or throttle.o should happen to
change, then the demo2 must be regenerated with the g++ command that is
shown. The string $(SUFFIX) is added to the end of the name of
the file demo2. On a Unix system, this string is defined to be
an empty string, so that the whole file name is just demo2. On
an MS-Windows system, this string is defined to be ".exe" so that
the whole file name becomes demo2.exe. Can you find the part of
the makefile that defines the variable $(SUFFIX)? It is an
if-statement that depends on whether or not another variable
called COMSPEC is defined. (COMSPEC is something that is defined
for MS-Windows, but not for Unix.)