I think it was back in 2014 that I got introduced to advanced Makefiles. Before that, I was aware of make being used to build and deploy software and also to run automated tests. I knew how to read and write Makefiles. Or so I thought.
The problem
This was a problem at work. Our build was taking more than an hour (!) and most of us thought that it was a necessary evil when you have many millions of lines of code to compile and link. A very senior technical guy thought otherwise.
Recursive and non-recursive make
Our software source tree had multiple levels, and each level had its own Makefile. The top-level Makefile declared targets and dependencies for that level, and its commands included make invocations for the next levels. And so on. The Makefiles were fairly small and readable, it looked nice and clean. But the whole build was taking a hell lot of time, apparently because of this. There is a famous paper by Peter Miller titled Recursive Make Considered Harmful that explains this problem in detail.
Non-recursive make and the power of Makefiles
The build problem at work was being solved by flattening the multi-level Makefiles to one effective Makefile. I was a temporary helping hand for the project, which is how I saw how fast the build became the moment the recursion went away - at least 3 times faster. The new Makefile employed many of the advanced features of make, which almost turn it into a functional programming language.
For example, you can write a list manipulation function like this in make:
list = 23 17 29 10 50 34
addnum = $(foreach num,$(2),$(shell expr $(num) + $(1)))
all:
@echo original: $(list)
@echo adding 20: '$(call addnum,20,$(list))'
If you run this Makefile, it will print out
original: 23 17 29 10 50 34
adding 20: 43 37 49 30 70 54
Going deeper into make
The real power of going non-recursive comes from the massive parallelism. If one make invocation is aware of all the files which need to be compiled and their dependencies on each other, it can do a much better job of utilizing multiple processor cores. John Graham Cumming explained a lot of these details in his book on GNU make. I got to know about this because we were using his company’s product Electric Accelerator at work.
We finally ended up using an open source Makefile framework called nonrec-make. Once this was done, the next challenge was debugging build problems. I learned about a fork of GNU make called remake which we used for debugging make.
My own fork of make
I decided to create my own fork of make, for statically analyzing Makefiles. The GNU make source code is surprisingly small and simple. It didn’t take me long to figure out how to modify it. I took me much longer for figuring out how to build a release version of make. The entire autotools system GNU uses is quite clunky, in my opinion. Anyways, that’s the story of how I created make-analyze - my fork of make with additional static analysis features. I also added an HTML export feature and a PyQT-based GUI viewer.
I did use it a bit at work. But I never got around to finding an open source use case - a large project which used Makefiles. I think I tried it on the CPython source code a few times, and then stopped working on the project.
The last thing I did on this front was submit a talk about all of this at an NYC tech conference. It was, of course, not accepted :-)

