3.2.1 Description and Format of the makefile File

The following example shows the contents of the makefile file.


A makefile must use tabs for indentation so that the make command can function properly. Also, be sure that tabs are retained if the file is copied and then used.

default: prime

# compile the library primelib first
primelib.o: primelib.c
	gcc -c primelib.c

# compile the main program
primain.o: primain.c
	gcc -c primain.c

# link and create executable file "prime"
prime: primelib.o primain.o
	gcc primain.o primelib.o -o prime -lm

	-rm -f *.o
	-rm -f prime