[prev] 31 [next]

Make/Makefiles (cont)

A Makefile for the example program:

game : main.o graphics.o world.o
	gcc -o game main.o graphics.o world.o

main.o : main.c graphics.h world.h
	gcc -Wall -Werror -c main.c

graphics.o : graphics.c world.h 
	gcc -Wall -Werror -c graphics.c

world.o : world.c
	gcc -Wall -Werror -c world.c

Things to note:

  • A target (game, main.o, …) is on a newline
    • followed by a :
    • then followed by the files that the target is dependent on
  • The action (gcc …) is always on a newline
    • and must be indented with a TAB