Question 2: Makefiles [9]

Write a makefile that meets the following specifications:

  • The makefile uses separate variables to specify each of the following:
    • the compiler to be used, currently set to g++
    • the default compilation flags to be used, currently set to -Wall -Wextra -pedantic
    • the name of the directory that holds all the executables, currently set to ~/bin
    • the name of the directory that holds all the source files, currently set to ~/src
    • the name of the directory that holds all the header files, currently set to ~/hdr
    • the name of the directory that holds all the object files, currently set to ~/obj
  • The header files are coreDefs.h, client.h, transfer.h, server.h, and backup.h
    - coreDefs.h is included by each of the other four .h files
  • The implementation files are client.cpp, transfer.cpp, server.C, and backup.c
    - each of the implementation files includes the like-named .h file.
    - client.cpp and server.C each include transfer.h
  • The makefile supports separate compilation of each of the implementation files into a .o file.
  • The makefile supports three target executables:
    • client: built by linking transfer.o and client.o
    • server: built by linking transfer.o and server.o
    • backup: built by linking transfer.o, and backup.o
  • The makefile supplies a 'clean' target, that removes precisely the set of .o files produced by the various compilation steps above.
  • The makefile applies the minimal set of updates necessary to rebuild any specified target following modifications to relevant files. (I.e. it works as a makefile should.)

(Note that space for your answer is provided on the next page.)