Make activities
When you type make (or whatever
the name of your “make” program happens to be), the make
program looks in the current directory for a file named makefile, which
you’ve created if it’s your project. This file lists
dependencies between source code
files. make looks at the dates on files. If a dependent file has an older
date than a file it depends on, make executes the
rule given after the dependency.
All comments in
makefiles start with a # and continue to the end of the
line.
As a simple example, the makefile
for a program called “hello” might contain:
# A comment
hello.exe: hello.cpp
mycompiler hello.cpp
This says that hello.exe (the
target) depends on hello.cpp. When hello.cpp has a newer date than
hello.exe, make executes the “rule” mycompiler
hello.cpp. There may be multiple dependencies and multiple rules. Many
make programs require that all the rules begin with a tab. Other than
that, whitespace is generally ignored so you can format for
readability.
The rules are not restricted to being
calls to the compiler; you can call any program you want from within
make. By creating groups of interdependent dependency-rule sets, you can
modify your source code files, type make and be certain that all the
affected files will be rebuilt correctly.