[prev] 110 [next]

Sidetrack: Make/Makefiles (cont)

An example Makefile:

exec : main.o module1.o module2.o
	gcc -o exec main.o module1.o module2.o

main.o : main.c module1.h
	gcc -Wall -Werror -std=c11 -c main.c

module1.o : module1.c module1.h module2.h
	gcc -Wall -Werror -std=c11 -c module1.c

module2.o : moudle2.c module2.h
	gcc -Wall -Werror -std=c11 -c module2.c

Things to note:

  • A target (exec, module1.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