Makefile tutorial

Make commands

  • make {EXECUTABLE} to compile code into executable
  • make ungraded for showing it to the instructor
  • make/make debug/make valgrind for valgrind and perf
  • make fullsubmit to prepare it for the autograder
  • make sync2caen to transfer files over to CAEN

Project Setup Steps

For every project in EECS 281, you should start by editing the Makefile. A brand-new Makefile will have a few things that should always be resolved when beginning a new project. Open the Makefile in an editing window. The first thing that should be updated is your UNIQNAME.

The second thing to be changed is the EXECUTABLE. Pick something that relates to the project. For example, if the project was P3: Dancing All Around, and you needed to formulate a dance routine, dance would be a good executable name. We will use tutorial for this guide.

Finally, you might need to update IDENTIFIER. For projects, we usually set these for you, but for anything else, you should set them yourself. For the tutorial project, make the identifier TUTOR14L. If you see something like EEC50281EEC50281EEC50281[...], that’s usually a sign that you need to replace the identifier.

You may find later on in the course that you have test files that depend on certain other source files. We will not cover this scenario here, but the bottom of the Makefile has instructions.

Once you’ve made these changes to your Makefile, make sure to save.


Now that the Makefile is complete, you can build the code using make commands. Run the command

make debug

or just

make

to build an executable named tutorial_debug. Because make debug compiles our code with the -g3 flag, this executable is built with maximum debug information enabled (including breakpoints). If we don’t want the debug information, we can instead build with

make release

This executable will run faster, but won’t be usable for debugging. When debugging, it is imperative that you use the debug executable. The debug executable will always end in _debug. Only the debug executable includes breakpoints. If all goes well, the tutorial_debug executable and tutorial.o should appear in your file explorer interface as shown below. To delete any files created by make commands, you can run the command

make clean