MCS273 Introduction to C++ Programming (January 2013)

A decent Makefile


Overview

This document introduces you to the features of a decent Makefile which, in addition to a few extra helpful features, automatically does most of the work of updating itself! After you've installed the Makefile, the only time you'll need to update it is to add and remove from the list of .cc files. (No need to mention dependencies or .h files!)

Tasks

  1. Switch to the directory of your integer point lab. Replace the Makefile with this Makefile.

  2. Refer to the top of the file to find the suggested changes. Do them. In particular, be sure to type, touch .depend.mk. This just makes an empty file which can then legally be included at the end of your Makefile. The Makefile will automagically update this each time it runs.

  3. Notice the following new features of this Makefile:

    • There is more extensive use of variables for control.

    • The Makefile automatically creates all the dependencies for you. After typing make -k, check out the file called .depend.mk, which has a list of file.o dependencies. (It reads your code and decides what file.h files you #include.)

    • If you type make clean, lots of files will get deleted. In particular, compiled code and backup files created by emacs will be removed.

    • The line OBJS = $(CXX_SRCS:.cc=.o) says, "Make a variable, OBJS, which is identical to CXX_SRCS, but with each .cc replaced by a .o." So, if you have done the command:

          CXX_SRCS = IntPoint.cc main.cc
      
      then the command OBJS = $(CXX_SRCS:.cc=.o) is equivalent to:
          OBJS = IntPoint.o main.o
      

    • The compilation command also demangles function names. You may have noticed some very strange and hard to understand function names being reported by the linker and debugger. The demangler makes these function names less cryptic. (Do man c++filt for more details.)

  4. Check-off (2 points): Ask to be checked off on this lab. You should show me your Makefile and .depend.mk.