📄 make-14.html
字号:
6.<span style="font:7.0pt "Times New Roman""> </span></span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
重建或者安装目标(一般是伪目标)的命令行可使用编译器或者相关工具程序,这些命令使用一个变量来表示。这样做的好处是:当修改一个命令时,只需要更改代表命令的变量的值就可以了。对于以下的这些命令程序:</span></p>
<p class="MsoNormal" style="text-indent: 48.0pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="margin-left:58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">ar bison cc
flex install ld ldconfig lex</span></i></b></p>
<p class="MsoNormal" style="margin-left:58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">make makeinfo
ranlib texi2dvi yacc</span></i></b></p>
<p class="MsoNormal" style="text-indent: 48.0pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 42.0pt">
<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; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 42.0pt">
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial">
</span></p>
<p class="MsoNormal" style="margin-left:58.2pt"><b><i>
<span lang="EN-US" style="font-size: 10.5pt; font-family: Arial">$(AR) $(BISON)
$(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG)$(LEX)</span></i></b></p>
<p class="MsoNormal" style="margin-left:58.2pt"><b><i>
<span lang="EN-US" style="font-size: 10.5pt; font-family: Arial">$(MAKE) $(MAKEINFO)
$(RANLIB) $(TEXI2DVI) $(YACC)</span></i></b></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 42.0pt">
<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; color: black">
如果规则的命令行需要使用“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">ranlib</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">ldconfig</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; line-height: 150%; text-autospace: ideograph-numeric ideograph-other; margin-left: 18.0pt">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
对以上没有列出的其它命令,在规则的命令行使用时也应该都是通过变量的形式。例如如下的这些命令:</span></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="margin-left:58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">chgrp chmod
chown mknod</span></i></b></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </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">
我们可以在</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">CHRP</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">CHMOD</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">$(CHMOD)</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">时需要遵循以上的约定。如果只考虑一种系统时,以上的这些约定中可以灵活处理,比如:在命令组件的使用上,我们就可以使用这个系统独具的那些命令组件;系统支持符号链接时,我们就可以在命令行重创建一个符号链接文件。<b>对于上边的第</b></span><b><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">6</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">个约定,强烈建议大家都遵循。</span></b></p>
<h2><a name="_gnu_make_14.3"><span style="font-size: 14pt" lang="en-us"><b>1</b></span><b><span lang="EN-US" style="font-size: 14.0pt">4.3<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">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 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">CC
= gcc</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">$(CC)</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">gcc</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">ln</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">rm</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">mv</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">FLAGS</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">CFLAGS</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">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%; font-family: Arial; color: black">CC</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">YFLAGS</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">yacc</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">YACC</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">LDFLAGS</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">ld</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">LD</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">CCFLAGS</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">gcc</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">LDFLAGS</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">
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%; font-family: Arial; color: black">CFLAGS</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">CFLAGS</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”中。编译特定文件(或者一类特定文件)时,如果需要使用特定的选项参数,可以将这些选项写在编译它所执行规则的命令行中(也可以使用</span><span lang="EN-US" style="font-family: 楷体_GB2312; font-size: 12.0pt; line-height: 150%; color: #0000FF">目标指定变量</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">或者</span><span style="font-family: 楷体_GB2312; font-size: 12.0pt; line-height: 150%; color: #0000FF">模式指定变量</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">)。例如:</span><span lang="SV" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">
</span></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="SV" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-indent: 41.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">CFLAGS = -g</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">ALL_CFLAGS = -I
$(CFLAGS)</span></i></b></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -