I built this guide because I could never quite wrap my head around Makefiles. They seemed awash with hidden rules and esoteric symbols, and asking simple questions didn’t yield simple answers. To solve this, I sat down for several weekends and read everything I could about Makefiles. I've condensed the most critical knowledge into this guide. Each topic has a brief description and a self contained example that you can run yourself.
-If you mostly understand Make, consider checking out the Makefile Cookbook, which has a template for medium sized projects with ample comments about what each part of the Makefile is doing.
+If you mostly understand Make, consider checking out the Makefile Cookbook, which has a template for medium sized projects with ample comments about what each part of the Makefile is doing.
Good luck, and I hope you are able to slay the confusing world of Makefiles!
Getting Started
Why do Makefiles exist?
@@ -455,6 +455,9 @@Running the Examples
To run these examples, you'll need a terminal and "make" installed. For each example, put the contents in a file called Makefile
, and in that directory run the command make
. Let's start with the simplest of Makefiles:
hello:
echo "hello world"
++Note: Makefiles must be indented using TABs and not spaces or
+make
will fail.
Here is the output of running the above example:
$ make
echo "hello world"