← All articles
· 2 min read

The Makefile I copy into every repository

A tiny, boring Makefile with a self-documenting help target has saved me more onboarding time than any wiki page. Here is the whole thing.

Every repository I touch grows the same small Makefile within a week, because a good make help is the cheapest onboarding document there is. New contributors type make, see the verbs, and stop asking how to run the thing.

The whole trick is a self-documenting help target that scrapes the comments off each rule:

Makefile
.DEFAULT_GOAL := help
.PHONY: help build test lint run fmt

help: ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
	 | awk 'BEGIN{FS=":.*?## "}{printf "  \033[36m%-10s\033[0m %s\n",$$1,$$2}'

build: ## Compile the binary
	go build -o bin/app ./cmd/app

test: ## Run the test suite
	go test ./... -race -count=1

lint: ## Run the linters
	golangci-lint run

fmt: ## Format the code
	gofmt -w .

run: build ## Build then run
	./bin/app

A few conventions make it robust. Declare targets .PHONY so they run even when a file of the same name exists. Put .DEFAULT_GOAL := help at the top so a bare make is friendly, not a surprise build. Remember recipe lines are tabs, not spaces — the one thing Make will never forgive. And double the dollar signs ($$1) in shell snippets so Make passes them through to the shell instead of expanding them itself.

That is the entire file. It is boring on purpose. Boring is what you want from the thing everyone runs fifty times a day.