2.1 What a Rule Looks Like(规则是什么样子的)

A simple makefile consists of “rules” with the following shape(一个简单的makefile由一系列的规则构成,规则样式如下):

target(目标) … : prerequisites(依赖) …
        recipe(命令)
        …
        …

A target is usually the name of a file that is generated by a program(目标通常是一个由程序生成的文件的名字); examples of targets are executable or object files(目标可以是可执行文件或者目标文件). A target can also be the name of an action to carry out(目标也可以是一个要执行的动作的名字), such as ‘clean’ (see Phony(假的) Targets).

A prerequisite is a file that is used as input to create the target(依赖就是个文件,用来生成目标的). A target often depends on several files(一个目标通常依赖好几个文件).

A recipe is an action that make carries out(A recipe就是一个由make执行的动作). A recipe may have more than one command, either on the same line or each on its own line.

Please note: you need to put a tab character at the beginning of every recipe line(需要在每一个命令行前放置一个tab字符)! This is an obscurity that catches the unwary(这是一个让粗心者抓狂的东东). If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character (如果你喜欢在每个命令行设置一个其他字符而不是tab字符,你可以通过设置.RECIPEPREFIX变量来生效)(see Special Variables).

Usually a recipe is in a rule with prerequisites and serves to create a target file if any of the prerequisites change. However, the rule that specifies a recipe for the target need not have prerequisites. For example, the rule containing the delete command associated with the target ‘clean’ does not have prerequisites(这段话的意思就是说,规则里可以没有依赖,而只包含目标和命令).

A rule, then(因此), explains how and when to remake certain files which are the targets of the particular rule(规则就是用来说明如何以及何时构建目标文件). make carries out the recipe on the prerequisites to create or update the target(make通过执行规则中的命令来创建或更新目标文件). A rule can also explain how and when to carry out an action(规则也可以用来解释如何以及何时执行一个动作). See Writing Rules.

A makefile may contain other text besides rules, but a simple makefile need only contain rules. Rules may look somewhat(有点) more complicated(复杂的) than shown in this template(模板), but all fit the pattern more or less(或多或少).

<<<返回主目录

发布了200 篇原创文章 · 获赞 37 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/wo198711203217/article/details/104319303