ugh.book

(singke) #1
Programming in Plato’s Cave 179

whether the files are out of date with respect to each other. A small depen-
dency graph, or Makefile, is shown below:


program: source1.o source2.o
cc -o program source1.o source2.o

source1.o: source1.c
cc -c source1.c

source2.o: source2.c
cc -c source2.c

In this graph, the nodes are program, source1.o, source2.o, source1.c, and
source2.c. The node program depends on the source1.o and source2.o
nodes. Here is a graphical representation of the same makefile:


When either source1.o or source2.o is newer than program, make will
regenerate program by executing the command cc -o program source1.o
source2.o. And, of course, if source1.c has been modified, then both
source1.o and program will be out of date, necessitating a recompile and a
relink.


While make’s model is quite general, the designers forgot to make it easy
to use for common cases. In fact, very few novice Unix programmers know
exactly how utterly easy it is to screw yourself to a wall with make, until
they do it.


To continue with our example, let’s say that our programmer, call him
Dennis, is trying to find a bug in source1.c and therefore wants to compile
this file with debugging information included. He modifies the Makefile to
look like this:


program

source1.o source2.o

source1.c source1.c
Free download pdf