Back to lesson
Free conceptRules and targets

Rule anatomy

See how a rule connects a target, its prerequisites, and the recipe that can update it.

One file-producing rule
1app: main.c config.h2 cc -o app main.c
Target
The name before the colon. Here, app is the file this rule can create or update.
Prerequisites
The names after the colon. Make considers main.c and config.h before deciding whether app needs its recipe.
Recipe
The shell command that tells Make how to update app. Recipe lines normally begin with a tab.
Aggregate target
A target that groups other targets as prerequisites. It often needs no recipe because updating its prerequisites is the work it represents.

For an ordinary file target, Make runs the recipe when the target does not exist or is older than a prerequisite. The rule all: can deliberately have neither prerequisites nor a recipe; .PHONY: all makes clear that it names build behavior, and later prerequisites turn it into an aggregate target.

See it in context

Follow the lessons that apply this concept, then inspect the repository at the exact commit behind each explanation.

GNU Make manual: An Introduction to Makefile Rules