

make is a useful tool for managing software projects. A Makefile can be the collective memory of commands necessary to build or manage a software project. There are several flavors and variants of make. In this tutorial we'll concentrate on the GNU make, but only those features that can be reasonably expected in one of the other flavors (SysV or BSD).
A Makefile contains targets, prerequisites, commands, and macros. All of these terms will become clear in the presentation. The first question to ask is why and when should a Makefile be used. (In this tutorial % is the command prompt and entered commands are in bold.)
When developing software the usual cycle is to edit, compile, execute, debug and repeat until all the bugs are found or when satisfied. This involves lots of repetitive steps. Assuming that the file sub2.c was edited, instead of typing:just type% cc -c sub2.c % cc -o mainexe main.o sub1.o sub2.o sub3.oif you have invested a minute or two to create a Makefile.% makeYou can save lots of time during the compilation step by breaking up your software project into separate compilation units. Only those units that are changed get recompiled. If the source is non-trivial (i.e. large), this can result in significant time savings.
- When there is more than one file to handle.
- If the code is expected to be built on different machines.
- There are special handling steps.
- If you consider your time to be valuable.
- If you expect to rebuild your executable at some later point - the Makefile retains the memory of the needed steps.

