Meet bmakelib: The Minimalist Make Standard Library

bmakelib logo: .mk in green lettering on a dark background

bmakelib

I’ve been using GNU Make for a very long time, as a hobbyist and for my personal projects. And, like almost everyone else who sticks with a tool long enough, I had accumulated my own collection of hacks and snippets – a little helper here, a useful trick there, and plenty of copy-paste.

That was OK until I managed, for the first time, to get buy-in from my employer to use GNU Make across the board. A company of more than 1,100 people.

That changed what I needed from my little collection.

A Proper Home for All Those Hacks

If I was going to ask colleagues to use this tooling, I needed to put the same care into it that I’d expect from any library we depended on.

The behaviours needed to be properly implemented and tested. The usage needed to be documented. Someone picking it up should be able to understand what a helper does, how to use it, and what happens when things go wrong.

I needed to turn the collection into a library.

Hence bmakelib.

A Standard Library for Make

Make provides us with a decent declarative language for describing targets, their dependencies and the work needed to produce them. As our Makefiles grow, we also find ourselves writing the supporting code around that work – things like checking if a required variable was provided, or rejecting an invalid option.

bmakelib collects them as reusable targets, recipes and functions. They fit into the Makefile you’re already writing, using Make’s own mechanisms. You can express a requirement as a prerequisite, call a helper function, or add timing and output capture around an existing target.

The aim is to make those recurring jobs easier to express and share.

The Next Person Who Runs Make

To my mind, a project’s Makefile is also an interface for the people working on it. Its targets give names to the things we do, and its variables expose the choices we need to make.

That interface deserves some attention. Which targets can I run? Which inputs do they need? Will a missing setting produce a useful error? Where can I find the output if something fails?

A shared library gives us a place to handle those concerns consistently. It also gives us somewhere to test the awkward cases and document what we’ve learnt, so the next project can benefit from that work.

That’s the idea behind bmakelib: taking the little conveniences we collect for ourselves and giving them the care needed to make them useful to other people, too.

Take a Look

If you use GNU Make, it’s worth looking at the documentation. It covers getting started, the available helpers and examples of how they fit together.

The source is on GitHub, under the Apache 2.0 licence. Contributions and suggestions are welcome.


Comments