GNU make 手册

原文地址: https://www.gnu.org/software/make/manual/html_node/index.html

本文档介绍了GNU make工具,该工具能自动确定大型程序中哪些部分需要重新编译,并发出重新编译它们的命令。

这是2023年2月26日最后更新的0.77版《GNU Make手册》,适用于GNU make 4.4.1版本。

版权所有 © 1988、1989、1990、1991、1992、1993、1994、1995、1996、1997、1998、1999、2000、2002、2003、2004、2005、2006、2007、2008、2009、2010、2011、2012、2013、2014、2015、2016、2017、2018、2019、2020、2021、2022、2023 自由软件基金会公司。

允许在GNU自由文档许可证(版本1.3或自由软件基金会发布的任何更新版本)的条款下复制、分发和/或修改本文档;无不可变章节,封面文字为“A GNU Manual”,封底文字如下文(a)项所述。本许可证的副本包含在标题为“GNU Free Documentation License”的章节中。

(a) 自由软件基金会(FSF)的封底文字为:“您拥有复制和修改本GNU手册的自由。从自由软件基金会购买副本,将支持其开发GNU并促进软件自由。”

目录

  • 1 make 概述
  • 2 Makefile简介
  • 3 编写Makefile文件
  • 4 编写规则
    • 4.1 Rule Example
    • 4.2 Rule Syntax
    • 4.3 Types of Prerequisites
    • 4.4 Using Wildcard Characters in File Names
      • 4.4.1 Wildcard Examples
      • 4.4.2 Pitfalls of Using Wildcards
      • 4.4.3 The Function wildcard
    • 4.5 Searching Directories for Prerequisites
      • 4.5.1 VPATH: Search Path for All Prerequisites
      • 4.5.2 The vpath Directive
      • 4.5.3 How Directory Searches are Performed
      • 4.5.4 Writing Recipes with Directory Search
      • 4.5.5 Directory Search and Implicit Rules
      • 4.5.6 Directory Search for Link Libraries
    • 4.6 Phony Targets
    • 4.7 Rules without Recipes or Prerequisites
    • 4.8 Empty Target Files to Record Events
    • 4.9 Special Built-in Target Names
    • 4.10 Multiple Targets in a Rule
    • 4.11 Multiple Rules for One Target
    • 4.12 Static Pattern Rules
      • 4.12.1 Syntax of Static Pattern Rules
      • 4.12.2 Static Pattern Rules versus Implicit Rules
    • 4.13 Double-Colon Rules
    • 4.14 Generating Prerequisites Automatically
  • 5 Writing Recipes in Rules
    • 5.1 Recipe Syntax
      • 5.1.1 Splitting Recipe Lines
      • 5.1.2 Using Variables in Recipes
    • 5.2 Recipe Echoing
    • 5.3 Recipe Execution
    • 5.3.1 Using One Shell
    • 5.3.2 Choosing the Shell
    • 5.4 Parallel Execution
      • 5.4.1 Disabling Parallel Execution
      • 5.4.2 Output During Parallel Execution
      • 5.4.3 Input During Parallel Execution
    • 5.5 Errors in Recipes
    • 5.6 Interrupting or Killing make
    • 5.7 Recursive Use of make
      • 5.7.1 How the MAKE Variable Works
      • 5.7.2 Communicating Variables to a Sub-make
      • 5.7.3 Communicating Options to a Sub-make
      • 5.7.4 The ‘–print-directory’ Option
    • 5.8 Defining Canned Recipes
    • 5.9 Using Empty Recipes
  • 6 How to Use Variables
    • 6.1 Basics of Variable References
    • 6.2 The Two Flavors of Variables
      • 6.2.1 Recursively Expanded Variable Assignment
      • 6.2.2 Simply Expanded Variable Assignment
      • 6.2.3 Immediately Expanded Variable Assignment
      • 6.2.4 Conditional Variable Assignment
    • 6.3 Advanced Features for Reference to Variables
      • 6.3.1 Substitution References
      • 6.3.2 Computed Variable Names
    • 6.4 How Variables Get Their Values
    • 6.5 Setting Variables
    • 6.6 Appending More Text to Variables
    • 6.7 The override Directive
    • 6.8 Defining Multi-Line Variables
    • 6.9 Undefining Variables
    • 6.10 Variables from the Environment
    • 6.11 Target-specific Variable Values
    • 6.12 Pattern-specific Variable Values
    • 6.13 Suppressing Inheritance
    • 6.14 Other Special Variables
  • 7 Conditional Parts of Makefiles
    • 7.1 Example of a Conditional
    • 7.2 Syntax of Conditionals
    • 7.3 Conditionals that Test Flags
  • 8 Functions for Transforming Text
    • 8.1 Function Call Syntax
    • 8.2 Functions for String Substitution and Analysis
    • 8.3 Functions for File Names
    • 8.4 Functions for Conditionals
    • 8.5 The let Function
    • 8.6 The foreach Function
    • 8.7 The file Function
    • 8.8 The call Function
    • 8.9 The value Function
    • 8.10 The eval Function
    • 8.11 The origin Function
    • 8.12 The flavor Function
    • 8.13 Functions That Control Make
    • 8.14 The shell Function
    • 8.15 The guile Function
  • 9 How to Run make
    • 9.1 Arguments to Specify the Makefile
    • 9.2 Arguments to Specify the Goals
    • 9.3 Instead of Executing Recipes
    • 9.4 Avoiding Recompilation of Some Files
    • 9.5 Overriding Variables
    • 9.6 Testing the Compilation of a Program
    • 9.7 Temporary Files
    • 9.8 Summary of Options
  • 10 Using Implicit Rules
    • 10.1 Using Implicit Rules
    • 10.2 Catalogue of Built-In Rules
    • 10.3 Variables Used by Implicit Rules
    • 10.4 Chains of Implicit Rules
    • 10.5 Defining and Redefining Pattern Rules
      • 10.5.1 Introduction to Pattern Rules
      • 10.5.2 Pattern Rule Examples
      • 10.5.3 Automatic Variables
      • 10.5.4 How Patterns Match
      • 10.5.5 Match-Anything Pattern Rules
      • 10.5.6 Canceling Implicit Rules
    • 10.6 Defining Last-Resort Default Rules
    • 10.7 Old-Fashioned Suffix Rules
    • 10.8 Implicit Rule Search Algorithm
  • 11 Using make to Update Archive Files
    • 11.1 Archive Members as Targets
    • 11.2 Implicit Rule for Archive Member Targets
      • 11.2.1 Updating Archive Symbol Directories
    • 11.3 Dangers When Using Archives
    • 11.4 Suffix Rules for Archive Files
  • 12 Extending GNU make
    • 12.1 GNU Guile Integration
      • 12.1.1 Conversion of Guile Types
      • 12.1.2 Interfaces from Guile to make
      • 12.1.3 Example Using Guile in make
    • 12.2 Loading Dynamic Objects
      • 12.2.1 The load Directive
      • 12.2.2 How Loaded Objects Are Remade
      • 12.2.3 Loaded Object Interface
      • 12.2.4 Example Loaded Object
  • 13 Integrating GNU make
    • 13.1 Sharing Job Slots with GNU make
      • 13.1.1 POSIX Jobserver Interaction
      • 13.1.2 Windows Jobserver Interaction
    • 13.2 Synchronized Terminal Output
  • 14 GNU make的特性
  • 15 Incompatibilities and Missing Features
  • 16 Makefile Conventions
    • 16.1 General Conventions for Makefiles
    • 16.2 Utilities in Makefiles
    • 16.3 Variables for Specifying Commands
    • 16.4 DESTDIR: Support for Staged Installs
    • 16.5 Variables for Installation Directories
    • 16.6 Standard Targets for Users
    • 16.7 Install Command Categories
  • 附录A 快速参考
  • Appendix B Errors Generated by Make
  • 附录C 复杂的Makefile示例
  • Appendix D GNU Free Documentation License
  • Index of Concepts
  • Index of Functions, Variables, & Directives