Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Writing Rules

A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the prerequisites 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 section 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 section Arguments to Specify the Goals.

4.1 Rule Example  An example explained.
4.2 Rule Syntax  General syntax explained.
4.3 Types of Prerequisites  There are two types of prerequisites.
4.4 Using Wildcard Characters in File Names  Using wildcard characters such as `*'.
4.5 Searching Directories for Prerequisites  Searching other directories for source files.
4.6 Phony Targets  Using a target that is not a real file's name.
4.7 Rules without Commands or Prerequisites  You can use a target without commands or prerequisites to mark other targets as phony.
4.8 Empty Target Files to Record Events  When only the date matters and the files are empty.
4.9 Special Built-in Target Names  Targets with special built-in meanings.
4.10 Multiple Targets in a Rule  When to make use of several targets in a rule.
4.11 Multiple Rules for One Target  How to use several rules with the same target.
4.12 Static Pattern Rules  Static pattern rules apply to multiple targets and can vary the prerequisites according to the target name.
4.13 Double-Colon Rules  How to use a special kind of rule to allow several independent rules for one target.
4.14 Generating Prerequisites Automatically  How to automatically generate rules giving prerequisites from source files themselves.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  Published under the terms of the GNU General Public License Design by Interspire