CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

A simple Makefile for our program

For the case of our multi-file program, calcmarks, we can develop a very verbose Makefile which fully describes the actions required to compile and link our project files.


# A Makefile to build our 'calcmarks' project

calcmarks : calcmarks.o globals.o readmarks.o correlation.o
—— tab —→cc -std=c11 -Wall -Werror -o calcmarks \
                  calcmarks.o globals.o readmarks.o correlation.o -lm


calcmarks.o : calcmarks.c calcmarks.h
—— tab —→cc -std=c11 -Wall -Werror -c calcmarks.c

globals.o : globals.c calcmarks.h
—— tab —→cc -std=c11 -Wall -Werror -c globals.c

readmarks.o : readmarks.c calcmarks.h
—— tab —→cc -std=c11 -Wall -Werror -c readmarks.c

correlation.o : correlation.c calcmarks.h
—— tab —→cc -std=c11 -Wall -Werror -c correlation.c  

download this Makefile.

Of note:
  • each target, at the beginning of lines, is followed by the dependencies (typically other files) on which it depends,

  • each target may also have one or more actions that are performed/executed if the target is out-of-date with respect to its dependencies,

  • actions must commence with the tab character, and

  • each action is passed verbatim to a shell for execution - just as if you would type it by hand.
    Very long lines may be split using the backslash character.

 


CITS2002 Systems Programming, Lecture 17, p12, 26th September 2023.