📄 make-05.html
字号:
{margin-top:12.0pt;
margin-right:0pt;
margin-bottom:12.0pt;
margin-left:36.0pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:-36.0pt;
page-break-after:avoid;
tab-stops:list 36.0pt;
text-autospace:none;
font-size:12.0pt;
font-family:Arial;
font-weight:normal}
-->
</style>
</head>
<body>
<h1 align="center" style="text-align: center; text-indent: 0pt; margin-left: 9.9pt">
<a name="chapter_05"><span style="font-size: 18.0pt; font-family: 楷体_GB2312">
第五章:规则</span><span style="font-size: 18.0pt; font-family: 楷体_GB2312; font-weight: normal">的命令</span></a></h1>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: #222222">
<hr size="1" width="100%" align="center"></span>
<p class="MsoBodyTextFirstIndent"><span lang="EN-US"> </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">shell</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">[Tab]</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">shell</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><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">/bin/sh</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">shell</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">/bin/sh</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">#</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">#</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">#</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">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><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">shell</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">脚本也一样。</span></p>
<h2><a name="_gnu_make_5.1"><b><span lang="EN-US" style="font-size: 14.0pt">5.1<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7.0pt; font-family: Times New Roman">
</span></span></b><span style="font-size: 14.0pt; font-family: 楷体_GB2312">命令回显</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; 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">shell</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">@</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">echo</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”命令输出一些信息时。如:</span></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 29.95pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">@echo </span>
<span style="font-size: 12.0pt; font-family: 楷体_GB2312">开始编译</span><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">XXX</span><span style="font-size: 12.0pt; font-family: 楷体_GB2312">模块</span><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 lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">
</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -