This often catches people unaware, and can be a problem if your preferred editor
???helpfully??? translates tabs to eight spaces. If you try to use spaces instead of a tab, make displays the
message Missing separator and stops.
Listing 29-4 shows a sample makefile for building a text editor imaginatively named editor.
LISTING 29-4
A Sample Makefile
editor : editor.o screen.o keyboard.o
gcc -o editor editor.o screen.o keyboard.o
editor.o : editor.c
gcc -c editor.c
screen.o : screen.c
gcc -c screen.c
keyboard.o : keyboard.c
gcc -c keyboard.c
clean :
rm -f *.o core *~
realclean : clean
rm -f editor
To compile editor, you simply type make in the directory that contains the makefile. It??™s that
simple.
This example makefile has six rules. The first defines how to create the target named editor.
The first target in every makefile is the default target (unless you specifically define one using the
.DEFAULT directive, which is not covered in this chapter). The default target is the one that
make builds if no target is specified as an argument to make. editor has three dependencies:
editor.o, screen.o, and keyboard.o; these three files must exist to build editor. The
second line in the first rule is the command that make must execute to create editor: gcc -o
editor editor.
Pages:
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424