Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

makefiles for things that aren't c

A small Makefile makes a tidy task runner for projects that have nothing to do with compiling C.

A mechanical keyboard next to a terminal

People hear "Makefile" and assume gcc and decades of arcane variable expansion. Most of the time I am not compiling anything. I just want one place that holds the four commands I always forget: how to run the linter, how to build the image, how to deploy, how to clean up after myself.

make is a perfectly good task runner for that, and it is already on every box. The whole point is make deploy instead of remembering the actual incantation, which by Friday afternoon I never do.

.PHONY: lint build deploy clean

lint:
	flake8 .

build:
	docker build -t myapp:latest .

deploy: build
	./scripts/deploy.sh staging

clean:
	rm -rf build/ dist/

Two things bite newcomers. Recipes must be indented with a real tab, not spaces, or you get the gloriously unhelpful "missing separator" error. And every target that is a verb rather than a file wants to be listed under .PHONY, otherwise make build does nothing on the day a directory called build happens to exist.

That is it. No autotools, no generated configure scripts, no inheritance from 1991. Just a tidy list of the things I do to a project, written down so I stop typing them out by hand.