f78 Writing Rules Contents|Index|Previous|Next

Writing Rules

A rule appears in the makefile and says when and how to remake cer-tain files, called the rule’s targets (most often only one per rule). It lists the other files that are the dependencies of the target, and commands to use to create or update the target.

The order of rules is not significant, except for determining the default goal: the target for make to consider, if you do not otherwise specify one. The default goal is the target of the first rule in the first makefile. If the first rule has multiple targets, only the first target is taken as the default. There are two exceptions: a target starting with a period is not a default unless it contains one or more slashes, ‘/’, as well; and, a target that defines a pattern rule has no effect on the default goal. (See Defining and Redefining Pattern Rules.)

Therefore, we usually write the makefile so that the first rule is the one for compiling the entire program or all the programs described by the makefile (often with a target called ‘all’). See Arguments to Specify the Goals.

See the following documentation for more discussion.

Rule Syntax

Using Wildcard Characters in File Names

Wildcard Examples

Pitfalls of Using Wildcards

The Function, wildcard

Searching Directories for Dependencies

VPATH: Search Path for All Dependencies

The vpath Directive

Writing Shell Commands with Directory Search

Directory Search and Implicit Rules

Directory Search for Link Libraries

Phony Targets

Rules without Commands or Dependencies

Empty Target Files to Record Events

Special Built-in Target Names

Multiple Targets in a Rule

Multiple Rules for One Target

Static Pattern Rules

Syntax of Static Pattern Rules

Static Pattern Rules versus Implicit Rules

Double-Colon Rules

Generating Dependencies Automatically

0