📄 make-03.html
字号:
通常指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”用在以下场合:</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: -21.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 39.0pt">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
1.<span style="font:7.0pt "Times New Roman""> </span></span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">
有多个不同的程序,由不同目录下的几个独立的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">来描述其重建规则。它们需要使用一组通用的变量定义或者模式规则。通用的做法是将这些共同使用的变量或者模式规则定义在一个文件中(没有具体的文件命名限制),在需要使用的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">中使用指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”来包含此文件。</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: -21.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 39.0pt">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
2.<span style="font:7.0pt "Times New Roman""> </span></span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">
当根据源文件自动产生依赖文件时;我们可以将自动产生的依赖关系保存在另外一个文件中,主</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">使用指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”包含这些文件。这样的做法比直接在主</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">中追加依赖文件的方法要明智的多。其它版本的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">已经使用这种方式来处理。</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">
如果指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”指定的文件不是以斜线开始(绝对路径,如</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">/usr/src/Makefile...</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">),而且当前目录下也不存在此文件;</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">将根据文件名试图在以下几个目录下查找:首先,查找使用命令行选项“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">-I</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”或者“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">--include-dir</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”指定的目录,如果找到指定的文件,则使用这个文件;否则继续依此搜索以下几个目录(如果其存在):“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">/usr/gnu/include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”、“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">/usr/local/include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”和“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">/usr/include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”。</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">
当在这些目录下都没有找到“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”指定的文件时,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">将会提示一个包含文件未找到的告警提示,但是不会立刻退出。而是继续处理</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">的后续内容。当完成读取整个</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">后,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">将试图使用规则来创建通过指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”指定的但未找到的文件,当不能创建它时(没有创建这个文件的规则),</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">将提示致命错误并退出。会输出类似如下错误提示:</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.1pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<b>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
</span></b></p>
<p class="MsoNormal" style="text-indent: 48.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">Makefile:</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">错误的行数:未找到文件名:提示信息(</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">No
such file or directory</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">)</span></i></b></p>
<p class="MsoNormal" style="text-indent: 48.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">Make</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">:</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">
*** No rule to make target ‘<filename>’. Stop</span></i></b></p>
<p class="MsoNormal" style="text-indent: 20.6pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></i></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">通常我们在</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">中可使用“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">-include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”来代替“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”,来忽略由于包含文件不存在或者无法创建时的错误提示(“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">-</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”的意思是告诉</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">,忽略此操作的错误。</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">继续执行)。像下边那样:</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">
</span></p>
<p class="MsoNormal" style="text-indent: 48.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">-include
FILENAMES...</span></i></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 lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
</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">
使用这种方式时,当所要包含的文件不存在时不会有错误提示、</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">也不会退出;除此之外,和第一种方式效果相同。以下是<b>这两种方式的比较:</b></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">使用“</span><b><i><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include
FILENAMES...</span></i></b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">程序处理时,如果“</span><b><i><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">FILENAMES</span></i></b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”列表中的任何一个文件不能正常读取而且不存在一个创建此文件的规则时</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">程序将会提示错误并退出。</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">使用“</span><b><i><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">-include
FILENAMES...</span></i></b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”的情况是,当所包含的文件不存在或者不存在一个规则去创建它,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">程序会继续执行,只有真正由于不能正确完成终极目标的重建时(某些必需的目标无法在当前已读取的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">文件内容中找到正确的重建规则),才会提示致命错误并退出。</span></p>
<span style="font-size: 12.0pt; font-family: 楷体_GB2312">为了和其它的</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">make</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">程序进行兼容。也可以使用“</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">sinclude</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">”来代替“</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">-include</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">”(</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">GNU</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">所支持的方式)。</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial"> </span><h2>
<a name="_gnu_make_3.4"><span lang="EN-US" style="font-size: 14.0pt"><b>3.4 </b></span>
<span style="font-size: 14.0pt; font-family: 楷体_GB2312">变量</span><span style="font-size: 14.0pt">
<b><span lang="EN-US">MAKEFILES</span></b></span></a></h2>
<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">
如果在当前环境定义了一个“</span><b><i><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">MAKEFILES</span></i></b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”环境变量,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">执行时首先将此变量的值作为需要读入的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">文件,多个文件之间使用空格分开。类似使用指示符“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”包含其它</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">文件一样,如果文件名非绝对路径而且当前目录也不存在此文件,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">会在一些默认的目录去寻找。它和使用“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">include</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”的区别:</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: -21.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 39.0pt">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
1.<span style="font:7.0pt "Times New Roman""> </span></span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">
环境变量指定的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">文件中的“目标”不会被作为</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">执行的“终极目标”。就是说,这些文件中所定义规则的目标,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">不会将其作为“终极目标”来看待。如果在</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">的工作目录下没有一个名为“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”、“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”或者“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">GNUmakefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”的文件,</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">同样会提示“</span><b><i><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make:
*** No targets specified and no makefile found. Stop.</span></i></b><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">”;而在</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312">的工作目录下存在这样一个文件(“</span><span lang="EN-US" style="font-size: 12.0pt;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -