make: "No Rule to Make Target" — Missing Files and Missing Prerequisites

make can't find (or infer) a rule to build a requested target. Read it literally: the named file is missing AND no rule can produce it. Fix the name, the prerequisite, or generate the missing source.

What you'll see

Root causes

A prerequisite file genuinely absent with no rule to create it

A missing source file, an un-generated artifact (configure, protobuf output), or a path wrong relative to the makefile's directory. make tells you exactly which prerequisite it wanted ('needed by').

Wrong target name or wrong directory

make target names are case-sensitive and live in the Makefile's directory: make build in a tree with no build target = literal no rule. The bare 'No rule to make target X' (without needed-by) means make never found target X at all.

Fix it

  1. Read the two message forms distinctly
    # with 'needed by': a PREREQUISITE is missing. Without: the TARGET name you typed doesn't exist in this Makefile.
  2. List what rules actually exist
    make -pn 2>/dev/null | grep -E '^[a-zA-Z0-9_.-]+:' | cut -d: -f1 | sort -u | head -30
  3. Missing prerequisite: find or generate the file
    ls <dir>; find . -name '<missing-file>' 2>/dev/null   # fresh clones: run ./configure, protoc, codegen targets first
  4. Clean-tree rebuilds: run the generate/configure step before make
    # the common order: ./autogen.sh || ./configure, make — a README/configure step usually produces the file make wants

Field note

The 'works on my machine' variant: your tree had the generated file from an earlier build; fresh clones don't. Deleting your build dir and cloning fresh is the honest CI-parity test. make -n <target> (dry run) prints the plan it WOULD execute — useful to verify the rule exists and its prerequisites resolve before running anything.

Common questions

Why does CI fail when my local build works?

CI clones fresh and makes your tree's generated files visible by their absence: run the codegen/configure step in CI before make, or add a rule that generates the missing file from its source.

How do I find the valid target names?

make -pn dumps every rule and variable; or just read the Makefile's top-level phony targets (usually .PHONY or the first block). Tab-completion doesn't exist for make — those two are the tooling.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.