GNU make manual 翻译( 一百一十四)
繼續(xù)翻譯
4.10 Multiple Targets in a Rule ===============================A rule with multiple targets is equivalent to writing many rules, each with one target, and all identical aside from that. The same recipe applies to all the targets, but its effect may vary because you can substitute the actual target name into the recipe using `$@'. The rule contributes the same prerequisites to all the targets also.This is useful in two cases.* You want just prerequisites, no recipe. For example:kbd.o command.o files.o: command.hgives an additional prerequisite to each of the three object filesmentioned.* Similar recipes work for all the targets. The recipes do not needto be absolutely identical, since the automatic variable `$@' can be used to substitute the particular target to be remade into thecommands (*note Automatic Variables::). For example:bigoutput littleoutput : text.ggenerate text.g -$(subst output,,$@) > $@is equivalent tobigoutput : text.ggenerate text.g -big > bigoutputlittleoutput : text.ggenerate text.g -little > littleoutputHere we assume the hypothetical program `generate' makes two typesof output, one if given `-big' and one if given `-little'. *NoteFunctions for String Substitution and Analysis: Text Functions,for an explanation of the `subst' function. Suppose you would like to vary the prerequisites according to the target, much as the variable `$@' allows you to vary the recipe. You cannot do this with multiple targets in an ordinary rule, but you can do it with a "static pattern rule". *Note Static Pattern Rules: Static Pattern.4.10 一個(gè)規(guī)則中的多個(gè)目的
===============================
和寫多個(gè)規(guī)則,每個(gè)規(guī)則一個(gè)目的的做法比較起來,帶有多個(gè)目的規(guī)則更加便利。同樣的片段作用于所有的目的,但是其作用范圍可能會(huì)變化,因?yàn)槟憧梢栽谄沃型ㄟ^ $@來替換世紀(jì)的目的名。規(guī)則也會(huì)把同樣的前提條件作用于所有的目的。
這在兩種情況下有用。
*你只需要 前提條件,不需要片段。例如:
kdo.o command.o files.o: command.h
對(duì)這三個(gè)目標(biāo)文件,給出了一個(gè)額外的前提條件。
*為所有目的工作的同樣的片段。片段不需要絕對(duì)唯一,因?yàn)樽詣?dòng)變量 $@能夠替換特定的目的,來重新建立指令(*note Automatic Variables::),例如:
bigoutput littleoutput : text.g
generate text.g -$(subst output,,$@) > $@
等價(jià)于:
bigoutput : text.g
generate text.g -big > bigoutput
littleoutput : text.g
generate text.g -little > littleoutput
在此書,我們假定假想的程序 generate 生成兩個(gè)類型的輸出,一個(gè)是給出 big 選項(xiàng)的時(shí)候,一個(gè)是給出little選項(xiàng)的時(shí)候。可以參照 *Note Functions for String Substitution and Analysis: Text Functions 中對(duì) subst 函數(shù)的解釋。
設(shè)想一下你將為目的而變換前提條件。正如你用 $@的變量來對(duì)片段進(jìn)行變化那樣;你在一個(gè)普通的帶有多個(gè)目的的規(guī)則里是不能達(dá)成的,但是你可以用 靜態(tài)模式規(guī)則來做到這一點(diǎn)。*Note Static Pattern Rules: Static Pattern。
后文待續(xù)
總結(jié)
以上是生活随笔為你收集整理的GNU make manual 翻译( 一百一十四)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java项目经验——程序员成长的关键
- 下一篇: 窗体的ControlBox属性