Large programs usually consist of several components, structured in a modular way. A module has an interface part and an implementation part. Modern languages like C, C++ and Modula-2 provide mechanisms to specify the interface of a module in one file and its implementation in another file. If module B is built upon module A, i.e. uses functions exported by module A, module B merely needs to import module A's interface, but not its implementation.
Compiling a large program costs a lot of time. Fortunately, each module can be compiled separately. The advantage is that we merely have to recompile module A if we change something to the implementation of module A, other modules need not be recompiled. This can save a lot of time. If we change something to the interface of module A, we have to recompile all modules that use the interface of module A.
Each module's implementation is compiled to a so called object file. An object file contains a.o. binary machine instructions for the functions that are exported by the module. All object files that form a program must be linked together to create an executable. The executable can be loaded into the computer's memory and executed.
Make helps us to keep the object files and executables up to date.
We describe in a Makefile
how the modules are built upon each other,
and how we can generate the object files from the source files, and the
executable from the object files.
Each time we type ``make
'', make checks whether the executable
and object files exist, and if they do exist, it checks the timestamps
of the files to see if they are still up to date with respect to the sources.
If this is not the case, make concludes that the sources have been
changed since the last time the programmer typed ``make
'', and it takes
the appropriate actions to recompile the necessary modules, and link the
objects to a new executable.
Another very important advantage of using a Makefile
is that it
eases the distribution of your program.
Somebody who wants to recompile your program on his system merely needs to
type ``make
'', and an executable is generated that can be run
on his or her system.