Skip to content
Latchkey

Makefile .PHONY Command Reference

Mark task targets as phony so make always runs their recipes.

.PHONY tells make that a target is a task, not a file. Without it, a target named test silently does nothing if a file or directory called test exists.

What it does

Declaring a target as a prerequisite of .PHONY makes make skip the up-to-date file check and always run the recipe. This is essential for task targets like build, test, clean, and lint that do not produce a file of the same name.

Common flags and usage

  • .PHONY: name1 name2 ...: declare one or more phony targets
  • Apply to every non-file task: build, test, clean, lint, install
  • Without it, a same-named file or directory makes the target a no-op

Example

shell
.PHONY: build test clean

test:
	go test ./...

clean:
	rm -rf dist/

In CI

A missing .PHONY is a classic flaky pipeline: a test target appears to pass but make reported nothing to be done because a test/ directory exists. Mark every task target phony so CI steps always execute.

Key takeaways

  • .PHONY forces make to run a target even if a like-named file exists.
  • Mark every task target (build, test, clean, lint) phony.
  • A missing .PHONY causes silent nothing to be done no-ops in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →