Introduction

This lab will give you experience writing a couple of Makefiles. Clone your lab repository with git and have fun!

Your repository contains two subdirectories:

Problem 0: Clean up after yourself

Create and commit a .gitignore file that ignores all compiled files and other crud. These items include, but are not limited to:

  • Editor backup file (e.g., ~ files, .bak files, and .swp files)
  • Compiled executables (e.g., a.out)
  • Object files (e.g., .o files)

You will lose points if you leave junk in your submission on GitLab. Remember that you can remove files that you previously committed using git rm.

Problem 1: A simple Makefile

Write a Makefile for Project1 that includes:

  • Simple targets (no patterns) for each .cpp file in the repository
    • Each target converts one .cpp file into its corresponding .o file.
  • A target that builds the whole program
  • A clean target that…
    • Removes all object files
    • Removes the built executable

Problem 2: A complicated Makefile

Write a Makefile for Project2 that includes:

  • A variable that lets you set the compiler
  • A pattern target for all .o files
  • A target that builds a debug version of the program
  • A target that builds a release version (non-debug version) of the program.
    • This should be the default target.
  • A clean target that…
    • Removes all object files
    • Removes the built executable

Epilogue

As always, your git repo on http://git-classes.mst.edu is your submission. Don’t forget to commit and push all relevant files. Make sure you see everything you expect on GitLab!

We expect to see the following files on your master branch:

  • .gitignore
  • Project1/
    • Makefile
    • TrianglePrinter.cpp
    • TrianglePrinter.h
    • funcs.cpp
    • funcs.h
    • main.cpp
  • Project2/
    • Makefile
    • TrianglePrinter.cpp
    • TrianglePrinter.h
    • funcs.cpp
    • funcs.h
    • main.cpp
  • README.md

Notice that your repository will have subdirectories! You have the option to put .gitignore files in the subdirectories if you prefer. Just make sure you’re not committing junk files.

There is no need to modify the source code. You’re writing Makefiles today.