Makefiles - Introduction

LeftRight

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.)

``Why should I use a Makefile?''

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:
% cc -c sub2.c
% cc -o mainexe main.o sub1.o sub2.o sub3.o
just type
% make
if you have invested a minute or two to create a Makefile.

You 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 should I use a Makefile?''

LeftRight
Slide 2