Writing a simple Makefile
In this recipe, we will learn how to write a Makefile for a specific project. The Makefile we wrote in the previous recipe was generic, but this will be for a single project only. Knowing how to write Makefiles for your projects will save you a lot of time and energy as you start making more complex programs.
Also, including a Makefile in a project is considered good manners. The person downloading your project usually has no idea how to build it. That person only wants to use your program, not be forced to understand how things fit together and how to compile it. After downloading, for example, an open source project, they would expect to be able just to type make
and make install
(or possibly also some form of configuration script, but we won't cover that here). The program should then be ready to run.
Getting ready
For this recipe, we will use the cube
program we made in the Looking at the four stages of compilation recipe in this chapter...