Make and Makefiles
Running targets, passing variables, dry runs, and a Makefile template with phony targets and self-documenting help.
Running
Run a target
make <make_target>
Pass a variable
make deploy ENV=stagingShow commands without running them
make -n <make_target>
Parallel jobs
make -j"$(nproc)"Use a different Makefile or directory
make -C ./backend -f Makefile.ci testForce rebuild of everythingadvanced
make -B <make_target>
Makefile
Template: phony targets and helpadvanced
.PHONY: help build test lint
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'
build: ## Build the app
go build -o bin/app ./cmd/app
test: ## Run tests
go test ./...Recipe lines must start with a TAB, not spaces. Use $$ for a literal $ in recipes.
Default value that can be overriddenadvanced
IMAGE_TAG ?= latestPrint a variable for debuggingadvanced
make -p | grep '^IMAGE_TAG'