📄 make-02.html
字号:
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
一个规则可以有多个命令行,每一条命令占一行。<b>注意:每一个命令行必须以</b></span><b><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">[Tab]</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">字符开始,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">[Tab]</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">字符告诉</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">此行是一个命令行。</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">按照命令完成相应的动作。这也是书写</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">中容易产生,而且比较隐蔽的错误。</span></b></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
命令就是在任何一个目标的依赖文件发生变化后重建目标的动作描述。一个目标可以没有依赖而只有动作(指定的命令)。比如</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">中的目标“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">clean</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”,此目标没有依赖,只有命令。它所定义的命令用来删除</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">过程产生的中间文件(进行清理工作)。</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
在</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">中“规则”就是描述在什么情况下、如何重建规则的目标文件,通常规则中包括了目标的依赖关系(目标的依赖文件)和重建目标的命令。</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">执行重建目标的命令,来创建或者重建规则的目标(此目标文件也可以是触发这个规则的上一个规则中的依赖文件)。</span><b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">规则包含了文件之间的依赖关系和更新此规则目标所需要的命令。</span></b></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
一个</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">文件中通常还包含了除规则以外的很多东西(后续我们会一步一步的展开)。一个最简单的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">可能只包含规则。规则在有些</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">中可能看起来非常复杂,但是无论规则的书写是多么的复杂,它都符合规则的基本格式。</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">
make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">程序根据规则的依赖关系,决定是否执行规则所定义的命令的过程我们称之为<b>执行规则</b>。</span></p>
<h3><a name="_gnu_make_2.3"><span lang="EN-US" style="font-size: 14.0pt">2.3 </span><span style="font-size: 14.0pt; font-family: 楷体_GB2312">简单的示例</span></a></h3>
<p class="MsoBodyTextFirstIndent" style="text-indent:24.0pt">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
本小节开始我们在第一小节中提到的例子。此例子由</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">3</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">个头文件和</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">8</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">个</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">C</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">文件组成。我们将书写一个简单的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">,来描述如何创建最终的可执行文件“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">edit</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”,此可执行文件依赖于</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">8</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">个</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">C</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">源文件和</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">3</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">个头文件。</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">文件的内容如下:</span></p>
<p class="MsoBodyTextFirstIndent" style="text-indent:24.0pt">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: black">
</span></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">#sample
Makefile</span></i></b></p>
<p class="MsoNormal" style="text-indent: 43.35pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">edit :
main.o kbd.o command.o display.o \</span></i></b></p>
<p class="MsoNormal" style="text-indent: 43.35pt; margin-left: 34.15pt"><b>
<i><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">insert.o
search.o files.o utils.o</span></i></b></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:36.0pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -o edit
main.o kbd.o command.o display.o \</span></i></b></p>
<p class="MsoNormal" style="margin-left:72.0pt;text-indent:36.0pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">insert.o
search.o files.o utils.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">main.o :
main.c defs.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
main.c </span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">kbd.o :
kbd.c defs.h command.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c kbd.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">command.o :
command.c defs.h command.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
command.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">display.o :
display.c defs.h buffer.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
display.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">insert.o :
insert.c defs.h buffer.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
insert.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">search.o :
search.c defs.h buffer.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
search.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">files.o :
files.c defs.h buffer.h command.h</span></i></b></p>
<p class="MsoNormal" style="text-indent: 41.2pt; margin-left: 30.9pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">cc -c
files.c</span></i></b></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -