make命令简介

本文介绍了make命令的作用,它是C语言项目中常用的构建工具,能够自动判断需要重新编译的文件并执行相应命令。makefile是指导make进行编译和链接的文件,包含规则、前置条件和recipe。文章还讲解了makefile中的变量赋值和延迟扩展,以及如何添加前缀、后缀和进行文本替换等内置函数。
摘要由CSDN通过智能技术生成

1. 简介

Compiling is the act of turning source code into object code. Linking is the act of combining object code with libraries into a raw executable. Building is the sequence composed of compiling and linking, with possibly other tasks such as installer creation.

编译是将源代码转换为目标代码的行为。链接是将目标代码与库组合成原始可执行文件的行为。构建是由编译链接组成的序列,可能还有其他任务,如创建安装程序。

The GNU make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them.

GNU make 实用程序,它自动确定需要重新编译大型程序的哪些部分,并发出重新编译它们的命令。

make 是C语言的项目最常用的构建build)工具。实际上,任何只要某个文件有变化,就要重新构建的项目,都可以用 make 构建。

You need a file called a makefile to tell make what to do. Most often, the makefile tells make how to compile and link a program.

你需要一个名为 makefile 的文件来告诉make该做什么。通常,makefile 会告诉make 如何编译链接程序。

2. 基本书写规则

一个简单的makefile由以下的“规则”组成:

target … : prerequisites …
<\tab>recipe
        …
        …
  1. target 通常是由程序生成的文件的名称;目标的示例是可执行文件 .out 或对象文件 .o。目标也可以是要执行的操作的名称(phony target,伪目标),例如 clean
  2. prerequisites(前置条件)是一个用作创建目标的输入的文件。一个目标通常依赖于多个 .c.h 文件。
  3. recipe 是一种执行的动作。一个 recipe 可能有多个命令,可以在同一行上,也可以在各自的行上。每个recipe行的开头都是一个制表符 <tab>

通常,一个recipe在一个有前置条件的规则中,如果任何前置条件发生变化,它将用于创建一个target文件。相反,不需要有前置条件。例如:目标 clean 关联的删除命令的规则不具有前置条件。如下:

.PHONY: clean
clean:
	rm Program.out

The prerequisites of the special target .PHONY are considered to be phony targets. When it is time to consider such a target, make will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is.

特殊 target 的前置条件。.PHONY伪目标。当涉及这

  • 44
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值