Clay Dowling's Occasional Musings
I write code, build things, and occasionally lead teams. I also share my thoughts or things I've learned about them, so that others can learn from my mistakes.
Clay's Pie Crust Recipe
Makefiles for Test Driven Development
I'm a big believer in Test Driven Development. That's the model where you write a failing test, then you write just enough code to make the test pass, but no more. It sounds counter-intuitive,but experience has shown that I get a finished, deliverable product a lot faster, and I'm less likely to find bugs. Even more importantly, my customers are less likely to find bugs.
Setting up a Makefile to support test driven development adds some additional challenges to what I've shown in my earlier articles. It's probably necessary to keep source and test is separate folders just to maintain sanity. We'll probably also have an outside dependency on our test framework, and there's a good chance that we'll need to create test doubles for some of the dependencies. A hypothetical folder structure might look like this:
project - mock // Test doubles - src - system // functions which interact with hardware - test - unity // our test framework
Each of those folders contains its own Makefile. For all but the test
folder, that Makefile looks very similar to what we've seen in previous
articles.
Easy Makefiles
If you read my earlier article OMG WTF Makefiles, there was a lot of information to take in. And Makefiles built that way can get pretty overwhelming to keep up pretty quickly. In fact, unless I'm forced to use BSD Make, I use GNU Make and take advantage of some nice shortcuts. I'll show you how to keep your Makefile building simple.
OMG WTF Makefiles!
If, like many developers, you haven't written a line of C or C++ since you left school, but suddenly find yourself needing to write in those languages, this article is for you. Or maybe you're in school, but you need to write a moderately complex program (more than one file). This article is also for you.