Makin’ It

tl;dr make: still good.

One of the great things about having a blog is the capability for endless bikeshedding. The stakes are so low, I don’t feel bad for indulging those impulses.

Shortly after the events described previously, I came across a great article about using make in a Go project. It’s a terrific article, that does a great job building up the author’s Makefile piece by piece, with clear explanations at every step. I was immediately inspired to use make for the ol’ blog!

Now, this wasn’t a completely arbitrary decision. After dumping the deploy logic directly into the git hooks, I had a nagging sense that it would be better off as a standalone script, that the hooks invoked. Furthermore, it would feel better to decouple the invocation from any necessary configuration. make fits the bill perfectly.

Here’s the current state of the Makefile:

COMMIT_SHA=$(shell git rev-parse --short HEAD) ❶

.PHONY: deploy
	@scripts/deploy ${COMMIT_SHA} ❷

www/blog/index.html: $(shell find www/blog ! -path www/blog/index.html) ❸
	@scripts/gen-index > www/blog/index.html
  1. ❶ sets a variable that gets used by the deploy script in ❷. (I ripped this right off the linked article.)
  2. ❸ was fun. One of make’s super powers is rebuilding files only when their dependencies change. In this case, I’ve set up the entry index to be regenerated when anything in the www/blog directory changes. The ! -path bit just ignores changes to the index file itself.
  3. I’ve been pleased with the move. The separation of concerns feels much cleaner. One concrete benefit is that testing the individual scripts is much easier. (It’s kinda stupid to have to test a git hook’s functionality by making a bunch of throwaway commits.) But even with the nice decoupling, it’s nice to have a centralized Makefile that provides a good “table of contents” for the operations of the blog. Having been around forever, make, like a lot of old Unix tools, is both broad and deep. I’m intrigued to find out what other ways I’ll use it here and elsewhere.

    Questions? Comments? Contact me!

    Tools Used

    GNU make