Tutorial: Practical makefiles, by example

I know a lot of programmers, who are afraid of makefiles. Most of them come from a windows background, and when they migrate to GNU/Linux or MacOS X they naturally gravitate towards clunky IDEs to manage their build process. Others, fearing that makefiles are going to be too complex to manage manually, try to use even clunkier makefile (or project file) generators like cmake.

While none of the above solutions is without some merit in particular cases, I strongly believe that there’s no faster and simpler way to build your project, than writing a small makefile. And in order to dispel the fear, I decided to write a tutorial about how to write simple, practical makefiles, for your programs.

The article is too big and too … structured, for my idea of what a blog post should be, so I’m hosting it on my web site along with some of my previous articles instead.

So anyway here it is, let me know if you find it useful: Practical makefiles, by example.
Feel free to use the comments section in this post for any feedback, or send me an email if you prefer.

Btw, I used reStructuredText, and the docutils translators for this. So there’s also a PDF version, produced through the rst2latex translator. It’s not as good as it could have been if I wrote it directly in LaTeX, but I suppose it’s serviceable if you prefer a printable off-line version.

2 Responses to “Tutorial: Practical makefiles, by example”

  1. Randall Says:

    I agree with you 100%. If fact it takes more time to setup the IDE, for example visual studio 2017 than to create a makefile, assuming the compiler and linker paths are setup right. You makefile “A makefile for 99% of your programs” can just be dropped into the source folder, open a cmd window or linux shell and run make. Boom, you’re done. How hard was THAT?

    By the way, in my 20+ years as a developer, I’ve not come across a better written makefile intro than yours. Most are either so simple that its only useful to build an executable from a single file or are so complex due to trying to cover all cases, that the reader is left with their head spinning, not quite knowing which parts applies to THEIR build. Your’s combines the simple examples with one robust enough to be usable in product development. Good job!


Leave a comment