Makefile: speedup go build & run by using mtimes

  • No need to rebuild your binary when nothing about it could have changed
  • go build -o foo && ./foo is faster than go run
# Makefile
BINARY = my-app
$(BINARY): $(shell find pkg cmd -type f -name "*.go" ! -name "*_test.go") go.mod go.sum
	go build -o $(BINARY) cmd/main.go

.PHONY: build
build: $(BINARY) ## Build binary

.PHONY: run
run: build ## run
	./$(BINARY) --help

Leave a comment