GNU Make-3.81 Manual
Total Page:16
File Type:pdf, Size:1020Kb
GNU Make GNU Make A Program for Directing Recompilation GNU make Version 3.81 April 2006 Richard M. Stallman, Roland McGrath, Paul D. Smith This file documents the GNU make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them. This is Edition 0.70, last updated 1 April 2006, of The GNU Make Manual, for GNU make version 3.81. Copyright c 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being \A GNU Manual," and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled \GNU Free Documentation License." (a) The FSF's Back-Cover Text is: \You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development." Published by the Free Software Foundation 51 Franklin St. { Fifth Floor Boston, MA 02110-1301 USA ISBN 1-882114-83-5 Cover art by Etienne Suvasa. i Short Contents 1 Overview of make :::::::::::::::::::::::::::::::::::::::::::::::::::: 1 2 An Introduction to Makefiles ::::::::::::::::::::::::::::::::::::::::::: 3 3 Writing Makefiles :::::::::::::::::::::::::::::::::::::::::::::::::::: 9 4 Writing Rules :::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 5 Writing the Commands in Rules ::::::::::::::::::::::::::::::::::::::: 37 6 How to Use Variables :::::::::::::::::::::::::::::::::::::::::::::::: 51 7 Conditional Parts of Makefiles ::::::::::::::::::::::::::::::::::::::::: 63 8 Functions for Transforming Text ::::::::::::::::::::::::::::::::::::::: 67 9 How to Run make ::::::::::::::::::::::::::::::::::::::::::::::::::: 81 10 Using Implicit Rules ::::::::::::::::::::::::::::::::::::::::::::::::: 91 11 Using make to Update Archive Files ::::::::::::::::::::::::::::::::::: 107 12 Features of GNU make :::::::::::::::::::::::::::::::::::::::::::::: 111 13 Incompatibilities and Missing Features ::::::::::::::::::::::::::::::::: 115 14 Makefile Conventions ::::::::::::::::::::::::::::::::::::::::::::::: 117 A Quick Reference ::::::::::::::::::::::::::::::::::::::::::::::::::: 129 B Errors Generated by Make ::::::::::::::::::::::::::::::::::::::::::: 135 C Complex Makefile Example :::::::::::::::::::::::::::::::::::::::::: 139 D GNU Free Documentation License :::::::::::::::::::::::::::::::::::: 145 Index of Concepts ::::::::::::::::::::::::::::::::::::::::::::::::::::: 153 Index of Functions, Variables, & Directives ::::::::::::::::::::::::::::::::: 161 iii Table of Contents 1 Overview of make::::::::::::::::::::::::::::::::::::::::::::::: 1 1.1 How to Read This Manual ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.2 Problems and Bugs :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 2 An Introduction to Makefiles ::::::::::::::::::::::::::::::::: 3 2.1 What a Rule Looks Like ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 2.2 A Simple Makefile ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 2.3 How make Processes a Makefile :::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.4 Variables Make Makefiles Simpler :::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.5 Letting make Deduce the Commands ::::::::::::::::::::::::::::::::::::::::::::::: 6 2.6 Another Style of Makefile :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.7 Rules for Cleaning the Directory ::::::::::::::::::::::::::::::::::::::::::::::::::: 7 3 Writing Makefiles:::::::::::::::::::::::::::::::::::::::::::::: 9 3.1 What Makefiles Contain ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 9 3.2 What Name to Give Your Makefile::::::::::::::::::::::::::::::::::::::::::::::::: 9 3.3 Including Other Makefiles :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.4 The Variable MAKEFILES:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 3.5 The Variable MAKEFILE_LIST ::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 3.6 Other Special Variables::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 12 3.7 How Makefiles Are Remade::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 3.8 Overriding Part of Another Makefile :::::::::::::::::::::::::::::::::::::::::::::: 14 3.9 How make Reads a Makefile::::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 3.10 Secondary Expansion:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 16 4 Writing Rules::::::::::::::::::::::::::::::::::::::::::::::::: 19 4.1 Rule Syntax :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 4.2 Types of Prerequisites :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 4.3 Using Wildcard Characters in File Names::::::::::::::::::::::::::::::::::::::::: 20 4.3.1 Wildcard Examples:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 4.3.2 Pitfalls of Using Wildcards :::::::::::::::::::::::::::::::::::::::::::::::::: 21 4.3.3 The Function wildcard:::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 4.4 Searching Directories for Prerequisites :::::::::::::::::::::::::::::::::::::::::::: 22 4.4.1 VPATH: Search Path for All Prerequisites ::::::::::::::::::::::::::::::::::::: 22 4.4.2 The vpath Directive ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 23 4.4.3 How Directory Searches are Performed ::::::::::::::::::::::::::::::::::::::: 24 4.4.4 Writing Shell Commands with Directory Search :::::::::::::::::::::::::::::: 24 4.4.5 Directory Search and Implicit Rules:::::::::::::::::::::::::::::::::::::::::: 25 4.4.6 Directory Search for Link Libraries :::::::::::::::::::::::::::::::::::::::::: 25 4.5 Phony Targets ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 25 4.6 Rules without Commands or Prerequisites :::::::::::::::::::::::::::::::::::::::: 27 4.7 Empty Target Files to Record Events ::::::::::::::::::::::::::::::::::::::::::::: 28 4.8 Special Built-in Target Names :::::::::::::::::::::::::::::::::::::::::::::::::::: 28 4.9 Multiple Targets in a Rule:::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 4.10 Multiple Rules for One Target ::::::::::::::::::::::::::::::::::::::::::::::::::: 31 4.11 Static Pattern Rules::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 4.11.1 Syntax of Static Pattern Rules:::::::::::::::::::::::::::::::::::::::::::::: 32 iv GNU make 4.11.2 Static Pattern Rules versus Implicit Rules :::::::::::::::::::::::::::::::::: 33 4.12 Double-Colon Rules ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 33 4.13 Generating Prerequisites Automatically:::::::::::::::::::::::::::::::::::::::::: 34 5 Writing the Commands in Rules :::::::::::::::::::::::::::: 37 5.1 Command Syntax :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 37 5.1.1 Splitting Command Lines :::::::::::::::::::::::::::::::::::::::::::::::::::: 37 5.1.2 Using Variables in Commands ::::::::::::::::::::::::::::::::::::::::::::::: 39 5.2 Command Echoing ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 39 5.3 Command Execution ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 39 5.3.1 Choosing the Shell::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 40 5.4 Parallel Execution :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 5.5 Errors in Commands ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 42 5.6 Interrupting or Killing make :::::::::::::::::::::::::::::::::::::::::::::::::::::: 43 5.7 Recursive Use of make :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 43 5.7.1 How the MAKE Variable Works ::::::::::::::::::::::::::::::::::::::::::::::: 44 5.7.2 Communicating Variables to a Sub-make ::::::::::::::::::::::::::::::::::::: 44 5.7.3 Communicating Options to a Sub-make :::::::::::::::::::::::::::::::::::::: 46 5.7.4 The `--print-directory' Option ::::::::::::::::::::::::::::::::::::::::::: 47 5.8 Defining Canned Command Sequences :::::::::::::::::::::::::::::::::::::::::::: 47 5.9 Using Empty Commands ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48 6 How to Use Variables :::::::::::::::::::::::::::::::::::::::: 51 6.1 Basics of Variable References ::::::::::::::::::::::::::::::::::::::::::::::::::::: 51 6.2 The Two Flavors of Variables::::::::::::::::::::::::::::::::::::::::::::::::::::: 52 6.3 Advanced Features for Reference to Variables ::::::::::::::::::::::::::::::::::::: 53 6.3.1 Substitution References :::::::::::::::::::::::::::::::::::::::::::::::::::::: 54 6.3.2 Computed Variable Names::::::::::::::::::::::::::::::::::::::::::::::::::: 54 6.4 How Variables Get Their Values :::::::::::::::::::::::::::::::::::::::::::::::::: 56 6.5 Setting Variables ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 56 6.6 Appending More Text to Variables ::::::::::::::::::::::::::::::::::::::::::::::: 57 6.7 The override Directive :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 58 6.8 Defining Variables Verbatim :::::::::::::::::::::::::::::::::::::::::::::::::::::: 59 6.9 Variables from the Environment :::::::::::::::::::::::::::::::::::::::::::::::::: 60 6.10 Target-specific Variable Values :::::::::::::::::::::::::::::::::::::::::::::::::: 60 6.11 Pattern-specific Variable Values :::::::::::::::::::::::::::::::::::::::::::::::::